PR #24128 opened by ngaullier
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24128
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24128.patch

Use case: interlaced AVC Intra is typically missing the required information
for proper tff detection.
Currently, the decoder defaults to tff, but the parser defaults to progressive.

./ffmpeg -f lavfi -i testsrc=1920x1080 -codec libx264 -pix_fmt yuv422p10le \
    -x264-params avcintra-class=100:tff=1 -frames 1 tff.h264
./ffprobe tff.h264 -of flat -show_entries 
stream=field_order:frame=interlaced_frame,top_field_first

Before:
frames.frame.0.interlaced_frame=1
frames.frame.0.top_field_first=1
streams.stream.0.field_order="progressive"

After:
frames.frame.0.interlaced_frame=1
frames.frame.0.top_field_first=1
streams.stream.0.field_order="tt"

Issue since field_order setting in 3f1a7ceb2c604deff.


>From 9e94cff9dcd4d5f4abfd483a6d39d263a73007b6 Mon Sep 17 00:00:00 2001
From: Nicolas Gaullier <[email protected]>
Date: Thu, 13 Aug 2026 17:00:42 +0200
Subject: [PATCH] avcodec/h264_parser: align field_order default with the
 decoder

Use case: interlaced AVC Intra is typically missing the required information
for proper tff detection.
Currently, the decoder defaults to tff, but the parser defaults to progressive.

./ffmpeg -f lavfi -i testsrc=1920x1080 -codec libx264 -pix_fmt yuv422p10le \
    -x264-params avcintra-class=100:tff=1 -frames 1 tff.h264
./ffprobe tff.h264 -of flat -show_entries 
stream=field_order:frame=interlaced_frame,top_field_first

Before:
frames.frame.0.interlaced_frame=1
frames.frame.0.top_field_first=1
streams.stream.0.field_order="progressive"

After:
frames.frame.0.interlaced_frame=1
frames.frame.0.top_field_first=1
streams.stream.0.field_order="tt"

Issue since field_order setting in 3f1a7ceb2c604deff.

Signed-off-by: Nicolas Gaullier <[email protected]>
---
 libavcodec/h264_parser.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 9d64fc603f..af43cad609 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -423,6 +423,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
 
             if (sps->frame_mbs_only_flag) {
                 p->picture_structure = PICT_FRAME;
+                s->field_order = AV_FIELD_PROGRESSIVE;
             } else {
                 if (get_bits1(&nal.gb)) { // field_pic_flag
                     p->picture_structure = PICT_TOP_FIELD + 
get_bits1(&nal.gb); // bottom_field_flag
@@ -541,8 +542,11 @@ static inline int parse_nal_units(AVCodecParserContext *s,
                         s->field_order = AV_FIELD_TT;
                     else if (field_poc[0] > field_poc[1])
                         s->field_order = AV_FIELD_BB;
-                    else
-                        s->field_order = AV_FIELD_PROGRESSIVE;
+                    else if (sps->mb_aff) {
+                        /* Default to top field first
+                         * This is the same as what the decoder does */
+                        s->field_order = AV_FIELD_TT;
+                    }
                 }
             } else {
                 if (p->picture_structure == PICT_TOP_FIELD)
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to