PR #22630 opened by dalecurtis URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22630 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22630.patch
This is a fix for https://crbug.com/495269752 which details a case where the hardware decoder output more frames than the software decoder. Investigation revealed that ffmpeg would drop pictures outside the reorder window incorrectly with unsignaled b-frames. This doesn't reproduce fully in ffmpeg itself. Chromium doesn't use ffmpeg's h264 parser during demuxing, so when using ffmpeg for decoding it doesn't always get the same level of pre-parsed information passed on. Running ffmpeg -v trace -i <264 version of first gop> shows the log "no picture ooo" without this fix. The updated fate tests also show a case where frames were incorrectly reordered before this fix. Signed-off-by: Dale Curtis <[email protected]> >From 0f8977ff6786a8023ef999b90311f500544a881b Mon Sep 17 00:00:00 2001 From: Dale Curtis <[email protected]> Date: Thu, 26 Mar 2026 19:18:17 +0000 Subject: [PATCH] Fix frame ordering issues with unsignaled b-frames This is a fix for https://crbug.com/495269752 which details a case where the hardware decoder output more frames than the software decoder. Investigation revealed that ffmpeg would drop pictures outside the reorder window incorrectly with unsignaled b-frames. This doesn't reproduce fully in ffmpeg itself. Chromium doesn't use ffmpeg's h264 parser during demuxing, so when using ffmpeg for decoding it doesn't always get the same level of pre-parsed information passed on. Running ffmpeg -v trace -i <264 version of first gop> shows the log "no picture ooo" without this fix. The updated fate tests also show a case where frames were incorrectly reordered before this fix. Signed-off-by: Dale Curtis <[email protected]> --- libavcodec/h264_slice.c | 4 +-- tests/ref/fate/h264_mp4toannexb_ticket5927 | 26 ++++++++++---------- tests/ref/fate/h264_mp4toannexb_ticket5927_2 | 26 ++++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 0ce8e46c72..c416f54576 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1327,8 +1327,8 @@ static int h264_select_output_frame(H264Context *h) cur->mmco_reset = 1; } else if(h->avctx->has_b_frames < out_of_order && !sps->bitstream_restriction_flag){ int loglevel = h->avctx->frame_num > 1 ? AV_LOG_WARNING : AV_LOG_VERBOSE; - av_log(h->avctx, loglevel, "Increasing reorder buffer to %d\n", out_of_order); - h->avctx->has_b_frames = out_of_order; + h->avctx->has_b_frames = FFMAX(out_of_order, sps->num_reorder_frames); + av_log(h->avctx, loglevel, "Increasing reorder buffer to %d\n", h->avctx->has_b_frames); } pics = 0; diff --git a/tests/ref/fate/h264_mp4toannexb_ticket5927 b/tests/ref/fate/h264_mp4toannexb_ticket5927 index e65ba8dc1f..1928874cf3 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket5927 +++ b/tests/ref/fate/h264_mp4toannexb_ticket5927 @@ -6,16 +6,16 @@ edddeef7901b2bd8d55625b8105b579f *tests/data/fate/h264_mp4toannexb_ticket5927.h2 #codec_id 0: h264 #dimensions 0: 1920x1080 #sar 0: 0/1 -0, -48000, -9223372036854775808, 48000, 247993, 0x541321e9 -0, 0, -9223372036854775808, 48000, 43354, 0xa05dca6f, F=0x0 -0, 48000, -9223372036854775808, 48000, 11423, 0x5e8086dd, F=0x0 -0, 96000, -9223372036854775808, 48000, 50798, 0x145fbe4f, F=0x0 -0, 144000, -9223372036854775808, 48000, 12567, 0x1e3d5304, F=0x0 -0, 192000, -9223372036854775808, 48000, 52444, 0x1a6c1a64, F=0x0 -0, 240000, -9223372036854775808, 48000, 12575, 0x2fff484b, F=0x0 -0, 288000, -9223372036854775808, 48000, 54025, 0xb3bf0ce6, F=0x0 -0, 336000, -9223372036854775808, 48000, 13539, 0xfdb16c57, F=0x0 -0, 384000, -9223372036854775808, 48000, 54483, 0xefead99f, F=0x0 -0, 432000, -9223372036854775808, 48000, 13705, 0x23cd27e8, F=0x0 -0, 480000, -9223372036854775808, 48000, 22308, 0x4093b5af, F=0x0 -0, 528000, -9223372036854775808, 48000, 6369, 0x6cca2aa0 +0, -192000, -9223372036854775808, 48000, 247993, 0x541321e9 +0, -144000, -9223372036854775808, 48000, 43354, 0xa05dca6f, F=0x0 +0, -96000, -9223372036854775808, 48000, 11423, 0x5e8086dd, F=0x0 +0, -48000, -9223372036854775808, 48000, 50798, 0x145fbe4f, F=0x0 +0, 0, -9223372036854775808, 48000, 12567, 0x1e3d5304, F=0x0 +0, 48000, -9223372036854775808, 48000, 52444, 0x1a6c1a64, F=0x0 +0, 96000, -9223372036854775808, 48000, 12575, 0x2fff484b, F=0x0 +0, 144000, -9223372036854775808, 48000, 54025, 0xb3bf0ce6, F=0x0 +0, 192000, -9223372036854775808, 48000, 13539, 0xfdb16c57, F=0x0 +0, 240000, -9223372036854775808, 48000, 54483, 0xefead99f, F=0x0 +0, 288000, -9223372036854775808, 48000, 13705, 0x23cd27e8, F=0x0 +0, 336000, -9223372036854775808, 48000, 22308, 0x4093b5af, F=0x0 +0, 384000, -9223372036854775808, 48000, 6369, 0x6cca2aa0 diff --git a/tests/ref/fate/h264_mp4toannexb_ticket5927_2 b/tests/ref/fate/h264_mp4toannexb_ticket5927_2 index 7a99faa535..a6275d014e 100644 --- a/tests/ref/fate/h264_mp4toannexb_ticket5927_2 +++ b/tests/ref/fate/h264_mp4toannexb_ticket5927_2 @@ -6,16 +6,16 @@ edddeef7901b2bd8d55625b8105b579f *tests/data/fate/h264_mp4toannexb_ticket5927_2. #codec_id 0: h264 #dimensions 0: 1920x1080 #sar 0: 0/1 -0, -48000, -9223372036854775808, 48000, 247993, 0x541321e9 -0, 0, -9223372036854775808, 48000, 43354, 0xa05dca6f, F=0x0 -0, 48000, -9223372036854775808, 48000, 11423, 0x5e8086dd, F=0x0 -0, 96000, -9223372036854775808, 48000, 50798, 0x145fbe4f, F=0x0 -0, 144000, -9223372036854775808, 48000, 12567, 0x1e3d5304, F=0x0 -0, 192000, -9223372036854775808, 48000, 52444, 0x1a6c1a64, F=0x0 -0, 240000, -9223372036854775808, 48000, 12575, 0x2fff484b, F=0x0 -0, 288000, -9223372036854775808, 48000, 54025, 0xb3bf0ce6, F=0x0 -0, 336000, -9223372036854775808, 48000, 13539, 0xfdb16c57, F=0x0 -0, 384000, -9223372036854775808, 48000, 54483, 0xefead99f, F=0x0 -0, 432000, -9223372036854775808, 48000, 13705, 0x23cd27e8, F=0x0 -0, 480000, -9223372036854775808, 48000, 22308, 0x4093b5af, F=0x0 -0, 528000, -9223372036854775808, 48000, 6369, 0x6cca2aa0 +0, -192000, -9223372036854775808, 48000, 247993, 0x541321e9 +0, -144000, -9223372036854775808, 48000, 43354, 0xa05dca6f, F=0x0 +0, -96000, -9223372036854775808, 48000, 11423, 0x5e8086dd, F=0x0 +0, -48000, -9223372036854775808, 48000, 50798, 0x145fbe4f, F=0x0 +0, 0, -9223372036854775808, 48000, 12567, 0x1e3d5304, F=0x0 +0, 48000, -9223372036854775808, 48000, 52444, 0x1a6c1a64, F=0x0 +0, 96000, -9223372036854775808, 48000, 12575, 0x2fff484b, F=0x0 +0, 144000, -9223372036854775808, 48000, 54025, 0xb3bf0ce6, F=0x0 +0, 192000, -9223372036854775808, 48000, 13539, 0xfdb16c57, F=0x0 +0, 240000, -9223372036854775808, 48000, 54483, 0xefead99f, F=0x0 +0, 288000, -9223372036854775808, 48000, 13705, 0x23cd27e8, F=0x0 +0, 336000, -9223372036854775808, 48000, 22308, 0x4093b5af, F=0x0 +0, 384000, -9223372036854775808, 48000, 6369, 0x6cca2aa0 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
