diff mbox series

[FFmpeg-devel,v3] mpegvideo_parser: check picture_structure for field order

Message ID 20220206100408.40824-1-tom.ty89@gmail.com
State New
Headers show
Series [FFmpeg-devel,v3] mpegvideo_parser: check picture_structure for field order | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Tom Yan Feb. 6, 2022, 10:04 a.m. UTC
the top_field_first bit is only used to indicate the field order
when the picture is a frame picture (which consists of two fields)
but not when it is a field picture (which consists of one single
top or bottom field).

Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
 libavcodec/mpegvideo_parser.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index c5dc867d24..26f3aac9da 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -181,6 +181,7 @@  static void mpegvideo_extract_headers(AVCodecParserContext *s,
                     break;
                 case 0x8: /* picture coding extension */
                     if (bytes_left >= 5) {
+                        s->picture_structure = buf[2] & 0x3;
                         top_field_first = buf[3] & (1 << 7);
                         repeat_first_field = buf[3] & (1 << 1);
                         progressive_frame = buf[4] & (1 << 7);
@@ -198,13 +199,15 @@  static void mpegvideo_extract_headers(AVCodecParserContext *s,
                             }
                         }
 
-                        if (!pc->progressive_sequence && !progressive_frame) {
-                            if (top_field_first)
-                                s->field_order = AV_FIELD_TT;
-                            else
-                                s->field_order = AV_FIELD_BB;
-                        } else
+                        /* picture_structure > progressive bits > top_field_first */
+                        if (s->picture_structure == AV_PICTURE_STRUCTURE_TOP_FIELD)
+                            s->field_order = AV_FIELD_TT;
+                        else if (s->picture_structure == AV_PICTURE_STRUCTURE_BOTTOM_FIELD)
+                            s->field_order = AV_FIELD_BB;
+                        else if (pc->progressive_sequence || progressive_frame)
                             s->field_order = AV_FIELD_PROGRESSIVE;
+                        else
+                            s->field_order = top_field_first ? AV_FIELD_TT : AV_FIELD_BB;
                     }
                     break;
                 }