You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
as you know, coding order and presentation order do not coincide if one uses b-frames in which case the frames need to be reordered by the decoder which therefore has to know (or guess) how high the reorder count is (the reorder count (of frame X) is the number of frames preceding X in coding order, but following it in display order) in order to know how many frames to buffer. ffmpeg seems to use the following strategy for the reorder count of H.264 streams (or actually for H.264 in Matroska -- I haven't checked other containers which often convey dts explicitly whereby Matroska only conveys decoding order and PTS): If the stream indicates its reorder count (in the VUI (video usability information) data, an optional part of the Sequence Parameter Set (SPS)), that number is used; if not, the first GOP is analyzed and its reorder count is used. If this initial estimate is too low, then ffmpeg drops some frames and increases its estimate of the reorder count (and emits a warning "Increasing reorder buffer to 2" [in my case 2, others may of course differ] if you are using ffmpeg directly). (Thanks to nevcairiel who explained this to me here.) Here is a file where this guessing logic fails. Here is the beginning of mkvinfo's output for it:
As one can see, the reorder count is always one or zero in the first GOP. But this changes in the second GOP: The frames 25-28 in (0-based) display order with timestamps 500, 520 and 540 have a reorder count of two so ffmpeg has underestimated the reorder count and drops the frames 25-27; so does ffms2. (I somewhere read that by adding -strict 1 changes ffmpeg's guessing logic and uses a very high value for the reorder count so that one doesn't have dropped frames. It seems to be true.) Contrary to ffmpeg (which emits one frame at 480 and another at 560) ffms2 repeats the frame with timestamp 560 four times to make up for the dropped frames. Here is a sample.
In order to show that this is really about frame reordering, I extracted the H.264 stream from the Matroska file and changed the SPS so that it now includes the entry for reorder frames. (I used three reorder frames, although two would have been enough.) Afterwards I remuxed to Matroska. Here is the result. Now ffmpeg and ffmpeg based players played the file flawlessly and also ffms2 did not drop frames. Here is the proof.
I see two potential solutions for this problem: First, you could use a very high number of potential frame reorderings like the --strict 1 switch. But there is also a second solution: One could get the necessary value for reorder count as a byproduct of the indexing which means that there is no need to guess anything.
Thanks for all your efforts so far and also for the time you invest into this bug report.
Greetings
mkver
The text was updated successfully, but these errors were encountered:
Hello,
as you know, coding order and presentation order do not coincide if one uses b-frames in which case the frames need to be reordered by the decoder which therefore has to know (or guess) how high the reorder count is (the reorder count (of frame X) is the number of frames preceding X in coding order, but following it in display order) in order to know how many frames to buffer. ffmpeg seems to use the following strategy for the reorder count of H.264 streams (or actually for H.264 in Matroska -- I haven't checked other containers which often convey dts explicitly whereby Matroska only conveys decoding order and PTS): If the stream indicates its reorder count (in the VUI (video usability information) data, an optional part of the Sequence Parameter Set (SPS)), that number is used; if not, the first GOP is analyzed and its reorder count is used. If this initial estimate is too low, then ffmpeg drops some frames and increases its estimate of the reorder count (and emits a warning "Increasing reorder buffer to 2" [in my case 2, others may of course differ] if you are using ffmpeg directly). (Thanks to nevcairiel who explained this to me here.)
Here is a file where this guessing logic fails. Here is the beginning of mkvinfo's output for it:
As one can see, the reorder count is always one or zero in the first GOP. But this changes in the second GOP: The frames 25-28 in (0-based) display order with timestamps 500, 520 and 540 have a reorder count of two so ffmpeg has underestimated the reorder count and drops the frames 25-27; so does ffms2. (I somewhere read that by adding
-strict 1
changes ffmpeg's guessing logic and uses a very high value for the reorder count so that one doesn't have dropped frames. It seems to be true.) Contrary to ffmpeg (which emits one frame at 480 and another at 560) ffms2 repeats the frame with timestamp 560 four times to make up for the dropped frames. Here is a sample.In order to show that this is really about frame reordering, I extracted the H.264 stream from the Matroska file and changed the SPS so that it now includes the entry for reorder frames. (I used three reorder frames, although two would have been enough.) Afterwards I remuxed to Matroska. Here is the result. Now ffmpeg and ffmpeg based players played the file flawlessly and also ffms2 did not drop frames. Here is the proof.
I see two potential solutions for this problem: First, you could use a very high number of potential frame reorderings like the
--strict 1
switch. But there is also a second solution: One could get the necessary value for reorder count as a byproduct of the indexing which means that there is no need to guess anything.Thanks for all your efforts so far and also for the time you invest into this bug report.
Greetings
mkver
The text was updated successfully, but these errors were encountered: