On Mon, 23 Nov 2026, 23:42 Baptiste Coudurier via ffmpeg-devel, < [email protected]> wrote:
> PR #26311 opened by Baptiste Coudurier (bcoudurier) > URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26311 > Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26311.patch > > The parser trusted pic_struct over the field POCs, so a bottom first > libx264 stream whose SEI says top-bottom probed as `field_order=tt` while > the decoder reports `top_field_first=0`. Field POCs now take precedence, as > in the decoder. > > The test encodes such a stream with libx264 at run time. > > Needed by https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26148. > > 🤖 Generated with [Claude Code](https://claude.com/claude-code) > > > > From 2518fe9fd795ac50fffd052dec185c8d1388fa6f Mon Sep 17 00:00:00 2001 > From: Baptiste Coudurier <[email protected]> > Date: Sun, 22 Nov 2026 22:06:32 -0800 > Subject: [PATCH] avcodec/h264_parser: let field POCs decide the field order > > As the decoder does, so a bottom first stream with a top-bottom > pic_struct is no longer reported as tt. > > Co-Authored-By: Claude Opus 5.5 <[email protected]> > Signed-off-by: Baptiste Coudurier <[email protected]> > --- > libavcodec/h264_parser.c | 5 +++++ > tests/fate/enc_external.mak | 13 +++++++++++++ > tests/ref/fate/libx264-bff-field-order | 3 +++ > 3 files changed, 21 insertions(+) > create mode 100644 tests/ref/fate/libx264-bff-field-order > > diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c > index 87228fb63ab..ab7bf007f93 100644 > --- a/libavcodec/h264_parser.c > +++ b/libavcodec/h264_parser.c > @@ -626,6 +626,11 @@ static inline int > parse_nal_units(AVCodecParserContext *s, > s->field_order = AV_FIELD_PROGRESSIVE; > break; > } > + /* Field POCs take precedence, as in the decoder. */ > + if (s->field_order != AV_FIELD_PROGRESSIVE && > + field_poc[0] != field_poc[1]) > + s->field_order = field_poc[0] < field_poc[1] ? > + AV_FIELD_TT : AV_FIELD_BB; > } else { > if (field_poc[0] < field_poc[1]) > s->field_order = AV_FIELD_TT; > diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak > index ec6ae833730..10457bd2fab 100644 > --- a/tests/fate/enc_external.mak > +++ b/tests/fate/enc_external.mak > @@ -12,6 +12,19 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MP4 MOV, > LIBX264_HDR10 HEVC_DEMUX > fate-libx264-hdr10: CMD = enc_external > $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ > mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list > -of flat" > > +# libx264 writes top first pic_struct SEIs with bottom first field POCs: > POCs win. > +FATE_LIBX264_FFPROBE-$(call ALLYES, LIBX264_ENCODER H264_MUXER > H264_DEMUXER H264_PARSER H264_DECODER \ > + LAVFI_INDEV TESTSRC_FILTER > SETFIELD_FILTER FORMAT_FILTER FILE_PROTOCOL) += fate-libx264-bff-field-order > +fate-libx264-bff-field-order: CMD = run_with_temp \ > + "$(FFMPEG) -nostdin -hide_banner -loglevel error -f lavfi \ > + -i testsrc=size=352x288:rate=30000/1001,setfield=bff,format=yuv420p \ > + -frames:v 2 -c:v libx264 -flags +ildct+ilme -f h264 -y" \ > + "ffprobe$(PROGSSUF)$(EXESUF) -v error -bitexact \ > + -show_entries > stream=field_order:frame=interlaced_frame,top_field_first -of compact" h264 > + > +FATE_FFMPEG_FFPROBE += $(FATE_LIBX264_FFPROBE-yes) > +fate-enc-external: $(FATE_LIBX264_FFPROBE-yes) > + > FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) > fate-enc-external: $(FATE_ENC_EXTERNAL-yes) > > diff --git a/tests/ref/fate/libx264-bff-field-order > b/tests/ref/fate/libx264-bff-field-order > new file mode 100644 > index 00000000000..03e3764e824 > --- /dev/null > +++ b/tests/ref/fate/libx264-bff-field-order > @@ -0,0 +1,3 @@ > +frame|interlaced_frame=1|top_field_first=0 > +frame|interlaced_frame=1|top_field_first=0 > +stream|field_order=bb > -- > 2.54.1 > Do non-x264 encoders do this correctly? Kieran > _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
