diff mbox

[FFmpeg-devel,2/4] lavc/h264_parser: export field order in more cases

Message ID 20161004044939.22351-2-rodger.combs@gmail.com
State Accepted
Commit f271a9bd991be4ce8d230b7dc6a0e56ca64b195c
Headers show

Commit Message

Rodger Combs Oct. 4, 2016, 4:49 a.m. UTC
---
 libavcodec/h264_parser.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Oct. 5, 2016, 7:47 p.m. UTC | #1
On Mon, Oct 03, 2016 at 11:49:37PM -0500, Rodger Combs wrote:
> ---
>  libavcodec/h264_parser.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)

should be ok

a bit off topic but
ct_type should be more completely parsed and used if available if its
more reliable
it should more reliable in theory

[...]
diff mbox

Patch

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 3ed7d77..bca0071 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -61,6 +61,7 @@  typedef struct H264ParseContext {
     int parse_history_count;
     int parse_last_mb;
     int64_t reference_dts;
+    int last_frame_num, last_picture_structure;
 } H264ParseContext;
 
 
@@ -528,7 +529,19 @@  static inline int parse_nal_units(AVCodecParserContext *s,
                     s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;
                 else
                     s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
-                s->field_order = AV_FIELD_UNKNOWN;
+                if (p->poc.frame_num == p->last_frame_num &&
+                    p->last_picture_structure != AV_PICTURE_STRUCTURE_UNKNOWN &&
+                    p->last_picture_structure != AV_PICTURE_STRUCTURE_FRAME &&
+                    p->last_picture_structure != s->picture_structure) {
+                    if (p->last_picture_structure == AV_PICTURE_STRUCTURE_TOP_FIELD)
+                        s->field_order = AV_FIELD_TT;
+                    else
+                        s->field_order = AV_FIELD_BB;
+                } else {
+                    s->field_order = AV_FIELD_UNKNOWN;
+                }
+                p->last_picture_structure = s->picture_structure;
+                p->last_frame_num = p->poc.frame_num;
             }
 
             av_freep(&nal.rbsp_buffer);
@@ -677,6 +690,7 @@  static av_cold int init(AVCodecParserContext *s)
     H264ParseContext *p = s->priv_data;
 
     p->reference_dts = AV_NOPTS_VALUE;
+    p->last_frame_num = INT_MAX;
     ff_h264dsp_init(&p->h264dsp, 8, 1);
     return 0;
 }