From f8353d5fdab24ecfb0989c9751007592f83543da Mon Sep 17 00:00:00 2001 From: Wolfram Gloger Date: Fri, 16 Mar 2012 21:17:00 +0100 Subject: [PATCH] mpegvideo: don't pretend the first frame is always a key frame Signed-off-by: Wolfram Gloger Modify the parser initialization so that parsers can set pict_type themselves. Use this in the mpegvideo parser so that initial frames are not unconditionally I frames. I have had this in my tree for several years. Signed-off-by: Michael Niedermayer --- libavcodec/mpegvideo_parser.c | 7 +++++++ libavcodec/parser.c | 4 ++-- tests/ref/seek/lavf_mpg | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 776052d252..5658cdeb36 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -182,9 +182,16 @@ static int mpegvideo_split(AVCodecContext *avctx, return 0; } +static int mpegvideo_parse_init(AVCodecParserContext *s) +{ + s->pict_type = AV_PICTURE_TYPE_NONE; // first frame might be partial + return 0; +} + AVCodecParser ff_mpegvideo_parser = { .codec_ids = { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, .priv_data_size = sizeof(struct MpvParseContext), + .parser_init = mpegvideo_parse_init, .parser_parse = mpegvideo_parse, .parser_close = ff_parse_close, .split = mpegvideo_split, diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 0be793506d..58be89f349 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -63,6 +63,8 @@ AVCodecParserContext *av_parser_init(int codec_id) av_free(s); return NULL; } + s->fetch_timestamp=1; + s->pict_type = AV_PICTURE_TYPE_I; if (parser->parser_init) { ret = parser->parser_init(s); if (ret != 0) { @@ -71,8 +73,6 @@ AVCodecParserContext *av_parser_init(int codec_id) return NULL; } } - s->fetch_timestamp=1; - s->pict_type = AV_PICTURE_TYPE_I; s->key_frame = -1; s->convergence_duration = 0; s->dts_sync_point = INT_MIN; diff --git a/tests/ref/seek/lavf_mpg b/tests/ref/seek/lavf_mpg index dc51195293..ccecf2ba5b 100644 --- a/tests/ref/seek/lavf_mpg +++ b/tests/ref/seek/lavf_mpg @@ -16,7 +16,7 @@ ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st:-1 flags:1 ts:-0.740831 ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st: 0 flags:0 ts: 2.153333 -ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.960000 pos: 339968 size: 681 +ret: 0 st: 0 flags:0 dts: 1.920000 pts: 1.960000 pos: 339968 size: 681 ret: 0 st: 0 flags:1 ts: 1.047500 ret: 0 st: 0 flags:0 dts: 1.040000 pts: 1.080000 pos: 40960 size: 16073 ret: 0 st: 1 flags:0 ts:-0.058333 @@ -30,7 +30,7 @@ ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st: 0 flags:0 ts:-0.481667 ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st: 0 flags:1 ts: 2.412500 -ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.960000 pos: 339968 size: 681 +ret: 0 st: 0 flags:0 dts: 1.920000 pts: 1.960000 pos: 339968 size: 681 ret: 0 st: 1 flags:0 ts: 1.306667 ret: 0 st: 1 flags:1 dts: 1.522444 pts: 1.522444 pos: 342028 size: 314 ret: 0 st: 1 flags:1 ts: 0.200844 @@ -38,7 +38,7 @@ ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st:-1 flags:0 ts:-0.904994 ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st:-1 flags:1 ts: 1.989173 -ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.960000 pos: 339968 size: 681 +ret: 0 st: 0 flags:0 dts: 1.920000 pts: 1.960000 pos: 339968 size: 681 ret: 0 st: 0 flags:0 ts: 0.883344 ret: 0 st: 1 flags:1 dts: 1.000000 pts: 1.000000 pos: 2048 size: 208 ret: 0 st: 0 flags:1 ts:-0.222489