From 2ccfb162669cc7e03c5e446260653a885b3db193 Mon Sep 17 00:00:00 2001 From: bcoudurier Date: Fri, 15 May 2009 05:39:44 +0000 Subject: [PATCH] decode mpeg-2 closed gop first b frames, fix issue #824 git-svn-id: file:///var/local/repositories/ffmpeg/trunk@18837 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b --- libavcodec/mpeg12.c | 20 +++++++++++++++----- libavcodec/mpegvideo.c | 1 + libavcodec/mpegvideo.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index d9157806c..44a1d987c 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -30,6 +30,7 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "mpegvideo_common.h" #include "mpeg12.h" #include "mpeg12data.h" @@ -2139,7 +2140,7 @@ static void mpeg_decode_gop(AVCodecContext *avctx, int drop_frame_flag; int time_code_hours, time_code_minutes; int time_code_seconds, time_code_pictures; - int closed_gop, broken_link; + int broken_link; init_get_bits(&s->gb, buf, buf_size*8); @@ -2151,7 +2152,7 @@ static void mpeg_decode_gop(AVCodecContext *avctx, time_code_seconds = get_bits(&s->gb,6); time_code_pictures = get_bits(&s->gb,6); - closed_gop = get_bits1(&s->gb); + s->closed_gop = get_bits1(&s->gb); /*broken_link indicate that after editing the reference frames of the first B-Frames after GOP I-Frame are missing (open gop)*/ @@ -2160,7 +2161,7 @@ static void mpeg_decode_gop(AVCodecContext *avctx, if(s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n", time_code_hours, time_code_minutes, time_code_seconds, - time_code_pictures, closed_gop, broken_link); + time_code_pictures, s->closed_gop, broken_link); } /** * Finds the end of the current frame in the bitstream. @@ -2354,8 +2355,17 @@ static int decode_chunks(AVCodecContext *avctx, int mb_y= start_code - SLICE_MIN_START_CODE; if(s2->last_picture_ptr==NULL){ - /* Skip B-frames if we do not have reference frames. */ - if(s2->pict_type==FF_B_TYPE) break; + /* Skip B-frames if we do not have reference frames and gop is not closed */ + if(s2->pict_type==FF_B_TYPE){ + int i; + if(!s2->closed_gop) + break; + /* Allocate a dummy frame */ + i= ff_find_unused_picture(s2, 0); + s2->last_picture_ptr= &s2->picture[i]; + if(alloc_picture(s2, s2->last_picture_ptr, 0) < 0) + return -1; + } } if(s2->next_picture_ptr==NULL){ /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 6ee10b540..da157c733 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -2107,6 +2107,7 @@ void ff_mpeg_flush(AVCodecContext *avctx){ s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; s->mb_x= s->mb_y= 0; + s->closed_gop= 0; s->parse_context.state= -1; s->parse_context.frame_start_found= 0; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 6240aac63..c2947b48c 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -312,6 +312,7 @@ typedef struct MpegEncContext { int *lambda_table; int adaptive_quant; ///< use adaptive quantization int dquant; ///< qscale difference to prev qscale + int closed_gop; ///< MPEG1/2 GOP is closed int pict_type; ///< FF_I_TYPE, FF_P_TYPE, FF_B_TYPE, ... int last_pict_type; //FIXME removes int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol -- 2.11.4.GIT