Original code was quite unorganized and not as easy to read through.
There were basically 3 code paths:
1. Division of `AVStream` duration by its timebase
2. Division of `AVFormatContext` duration by its timebase, with possible
AV offset compensation
3. Simply using frame count from `AVStream`
Finally there was possibility of ending up with duration of 0 in
specific case where `pFormatCtx->duration == AV_NOPTS_VALUE`, but I did
not find any test case for this (Added in aebb32748e).
During investigation for PR #126866, I have concluded, that before
commit 8903205dd9, the code which compared duration of stream and
container was incorrectly always true. But it resulted in correct
behavior for about 4 years. Code was reorganized with that assumption,
so above listed code paths are in order of possible execution. Exception
is code path 3, which is run first, but it's result is pretty much always
discarded.
Since all these workarounds are added around code path 3, it is safe
to assume, that it is least precise, so it should be considered last.
Pull Request: https://projects.blender.org/blender/blender/pulls/127010