Create Fixture
This page covers an example of the process of creating a nix flake video fixture, which is not to be confused with a pytest fixture (although the concept is related). These fixtures are primarily used for testing video processing and feature extraction.
Example Fixture: Over/Under-cut Testing Video
We implemented Over/Under-Cut in shot MissFeatures. In order to consistently test the feature, we find a video clip demonstrating an unambiguous instance of Over/Under-cut and add the video as a fixture, specifically a 'tarResources' fixture.
Acquire Feature Video
Make a shots folder:
(~/railbird)$ mkdir my_shots
Open video with debug player:
# Looking for a shot demonstrating either an over- or under-cut
bcorner@Moby:~/railbird$ just track 267
Enable via the dropdown menu:
- shot selector (helps identify candidate shots for the desired Feature)
- shot history
- video export
Look for a Feature-relevant video clip
Export video segment
Note the beginning and ending frames for the segment to be exported.
Export the clip to the shots folder, i.e., my_shots/some_shot.mp4
.
bcorner@Moby:~/railbird$ ls -lh my_shots/
total 2.1M
-rw-r--r-- 1 bcorner bcorner 2.1M May 7 20:42 some_shot.mp4
Make Fixture
bcorner@Moby:~/railbird$ just make-fixture my_shots
Making archive at /tmp/mytar.RzvhkE.tar
./
./some_shot.mp4
Made archive at /tmp/mytar.RzvhkE.tar
permanent name 8b61cd563522832d7c4f4f26e0e8f7e4559cfc3c452499941ed5b4dc17ab6339.tar
8b61cd563522832d7c4f4f26e0e8f7e4559cfc3c452499941ed5b4dc17ab6339.tar
Update 'tarResources'
in railbird/flake.nix
Append an entry to tarResources
for our freshly made fixture. The file needs to be accessible for download over the internet, i.e., uploaded to Syncthing, etc.
nix will complain and tell us what our sha256 value should be.
"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; // placeholder
...
tarResources = [
{
url = "https://syncthing.railbird.ai/sample_videos/12b27c3a-489f-49b8-93db-b6f13b4f43c0.tar";
sha256 = "sha256-otMqKeurrRRS9h4/dMRWWIi2UhnhOMpOxC1/QIsbXwo=";
}
{
url = "https://syncthing.railbird.ai/sample_videos/342ec9d32f2ad58595e31a0de64b35120b368f45c143bbb134f0e5c074acf135.tar";
sha256 = "sha256-NC7J0y8q1YWV4xoN5ks1Egs2j0XBQ7uxNPDlwHSs8TU=";
}
{
url = "https://syncthing.railbird.ai/sample_videos/fc2cd972986754a0c4516930b651519bf6b128f0fe0805c8ed01d8a7cdd3607f.tar";
sha256 = "sha256-/CzZcphnVKDEUWkwtlFRm/axKPD+CAXI7QHYp83TYH8=";
}
{
url = "https://syncthing.railbird.ai/sample_videos/3dde8a2b3dffdd06ec344e13eda893a4074dedee9bba0311731fc5f606098c3f.tar";
sha256 = "sha256-Pd6KKz3/3QbsNE4T7aiTpAdN7e6bugMRcx/F9gYJjD8=";
}
{
url = "https://syncthing.railbird.ai/sample_videos/8e5f65682e68b4b22d7d1536d77434c3915ce8f9f6176736f4543d25ecc9b5ea.tar";
sha256 = "sha256-jl9laC5otLItfRU213Q0w5Fc6Pn2F2c29FQ9JezJteo=";
}
{
url = "https://github.com/bcorner/rb-test-videos/raw/main/8b61cd563522832d7c4f4f26e0e8f7e4559cfc3c452499941ed5b4dc17ab6339.tar";
sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
];
...
Update flake.nix tarResources with correct sha256
value
This is kinda janky. We make our sample video accessible online (in this example, my .tar was added to a public GitHub repo, and I included its download URL).
When we run nix develop --impure
or direnv reload
, nix will fetch the file from the indicated URL and calculate the corresponding hash for the fetched file, and will complain about our newly-added tarResource entry having a mismatched hash:
bcorner@Moby:~$ cd railbird/
direnv: loading ~/railbird/.envrc
direnv: using flake . --impure
warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
evaluating derivation 'git+file:///home/bcorner/railbird#devShells.x86_64-linux.default'direnv: ([/nix/store/3bmgmpaqm8p34hi6xb1y4fisf5n0pbbh-direnv-2.34.0/bin/direnv export bash]) is taking a while to execute. Use CTRL-C to give up.
error: hash mismatch in fixed-output derivation '/nix/store/vy0vhm9y71g7y6j5qks5jax61f4jz0k3-8b61cd563522832d7c4f4f26e0e8f7e4559cfc3c452499941ed5b4dc17ab6339.tar.drv':
specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
got: sha256-i2HNVjUigy18T08m4Oj35FWc/DxFJJmUHtW03BerYzk=
Or, if you don't have direnv setup:
[nixos@nixos:~/railbird]$ nix develop --impure
warning: Git tree '/home/nixos/railbird' is dirty
warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
error: hash mismatch in fixed-output derivation '/nix/store/vy0vhm9y71g7y6j5qks5jax61f4jz0k3-8b61cd563522832d7c4f4f26e0e8f7e4559cfc3c452499941ed5b4dc17ab6339.tar.drv':
specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
got: sha256-i2HNVjUigy18T08m4Oj35FWc/DxFJJmUHtW03BerYzk=
We then edit our tarResources entry in flake.nix
to include the correct sha256 hash value, which nix was so kind as to calculate for us:
...
{
url = "https://github.com/bcorner/rb-test-videos/raw/main/8b61cd563522832d7c4f4f26e0e8f7e4559cfc3c452499941ed5b4dc17ab6339.tar";
sha256 = "sha256-i2HNVjUigy18T08m4Oj35FWc/DxFJJmUHtW03BerYzk=";
}
];
...