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>
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;
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel