[FFmpeg-devel] mpegvideo : interlaced_frame with picture_structure == PICT_FRAME

Vanista Herion vanista at gmail.com
Mon Jan 5 21:17:32 CET 2015


Some MPEG 2 video will give bad interlacing information in AVFrame. If the
parameters are used by a deinterlace filter such as yadif, frames will be
processed needlessly and impair the quality.

By reviewing the code in mpegvideo.c which sets the interlaced_frame
and top_field_first, I noticed that picture_structure is not considered
whereas it probably supersedes everything else. The H.262 specification is
not very clear on that but in the case of this sample, the stream is
definitely progressive, picture_structure is equal to 3 (Frame picture) and
top_field_first alternates true and false.

The result is that frames come out reported as tff, bff and progressive,
cycling at every frame.
I propose a simple patch to set interlaced_frame to false when
picture_structure is equal to PICT_FRAME.

​
 interlaced_flag_switch.mpeg
<https://docs.google.com/file/d/0B72Rmfr6KECZVVE1T3R6dWhMb2s/edit?usp=drive_web>
​
-------------- next part --------------
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ce4fa59..2e25e15 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1832,14 +1832,16 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
     s->current_picture_ptr = pic;
     // FIXME use only the vars from current_pic
     s->current_picture_ptr->f->top_field_first = s->top_field_first;
+    s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame &&
+                                                 !s->progressive_sequence;
     if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
         s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
         if (s->picture_structure != PICT_FRAME)
             s->current_picture_ptr->f->top_field_first =
                 (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
+        else
+            s->current_picture_ptr->f->interlaced_frame = 0;
     }
-    s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame &&
-                                                 !s->progressive_sequence;
     s->current_picture_ptr->field_picture      =  s->picture_structure != PICT_FRAME;
 
     s->current_picture_ptr->f->pict_type = s->pict_type;


More information about the ffmpeg-devel mailing list