Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vidstabdetect appears to be nondeterministic? #111

Open
egnor opened this issue Jun 21, 2021 · 5 comments
Open

vidstabdetect appears to be nondeterministic? #111

egnor opened this issue Jun 21, 2021 · 5 comments

Comments

@egnor
Copy link

egnor commented Jun 21, 2021

Hi, if I run vidstabdetect repeatedly this video clip (which is not special as far as I know)...

clip.mp4

ffmpeg -i clip.mp4 -filter:v vidstabdetect -f null -

...the output transform.trf differs from run to run, as compared with "diff" (though the "show=1" output is identical). Is this expected?

It's possible the nondeterminism is in video decoding but that seems unlikely -- asking ffmpeg to transcode the same clip (with no vidstabdetect) produces identical output. The transforms seem to be effectively very similar, but vidstabtransform result also produces slightly different results, which is inconvenient in a variety of ways for managing a pipeline.

@georgmartius
Copy link
Owner

Mh, I cannot remember putting any source of non-determinism in it. How is the trf file different? (Are you still using the ascii format?)

@egnor
Copy link
Author

egnor commented Jun 21, 2021

transforms.1.trf.txt
transforms.2.trf.txt

(Didn't even realize there was a non-ASCII format!)

@egnor
Copy link
Author

egnor commented Jun 21, 2021

Aha, if I set OMP_NUM_THREADS=1 then output becomes deterministic!

Probably it's the thread-parallelized loop in calcTransFields, causing the localmotions to be output in nondeterministic order. Might be worth sorting those on output? (And similarly elsewhere?)

@georgmartius
Copy link
Owner

georgmartius commented Jun 21, 2021

Okay, makes sense. Why is it important for you that the outputs are the same. In the next step, the order of the fields in the transform file does not matter.

@egnor
Copy link
Author

egnor commented Jun 21, 2021

Sadly, the final video I get is not the same. But it seems that the transforms.trf difference is a red herring! Even with transforms.trf identical, two different runs of vidstabtransform on the same source give different results. 😞

% ffmpeg -i clip.mp4 -vf vidstabtransform clip_stab.1.mp4
...
% ffmpeg -i clip.mp4 -vf vidstabtransform clip_stab.2.mp4
...
% diff clip_stab.1.mp4 clip_stab.2.mp4
Binary files clip_stab.1.mp4 and clip_stab.2.mp4 differ

Unfortunately, setting OMP_NUM_THREADS=1 doesn't fix this one.

As for "why do I care": Broadly speaking, it's valuable to have reproducible build steps at each point of a pipeline. Build pipeline systems often work better and more efficiently when equivalent results are bitwise identical, so they can skip subsequent steps. It also allows other people to verify or reproduce builds, which is important for security (ensure nothing was tampered with), debugging (reproduce build results to understand them), etc.. See reproducible-builds.org, martinfowler.com/bliki/ReproducibleBuild.html, en.wikipedia.org/wiki/Reproducible_builds and the like -- most of which are talking about software builds, but the same concepts apply to other artifacts.

In my very specific case, I have scripts that turn "art sources" into production videos, which then get checked in if they've changed. If the production video changes every time the pipeline is run, then there's a lot of churn and unnecessary pushing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants