summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo_parser.c
diff options
context:
space:
mode:
authorHeesuk Jung <heesuk.jung@lge.com>2012-11-02 08:25:03 -0700
committerMichael Niedermayer <michaelni@gmx.at>2012-11-02 22:27:17 +0100
commit25b7aa980bb8ecc6de085adf7d6b8e68a44bcbd4 (patch)
tree8cd39f99bede5bc8866c7a12944c124add281569 /libavcodec/mpegvideo_parser.c
parent77d89a5b160127b5b60ba0310cb999077a22525d (diff)
Fix bit_rate in MPEG1/2 Video
In ISO/IEC 13818-2, bit rate is differently determined according to video type 1) MPEG1 Video Bit_rate and vbv_delay are set to 3FFFF and FFFF respectively to indicate variable bitrate. Other values are for constant bitrate. VBV is only defined for constant bit rate operation. Ths STD supersedes the VBV model for vbr. 2) MPEG2 Video Even if the bitrate is constant, the value of bit_rate may not be the actual bitrate since bit_rate need only be an upper bound to that actual bitrate. VBV is only defined for variable bit rate operation. Constant bit rate is viewed as a special case of vbr. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mpegvideo_parser.c')
-rw-r--r--libavcodec/mpegvideo_parser.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 5fb2799814..c112a94841 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -44,6 +44,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
int horiz_size_ext, vert_size_ext, bit_rate_ext;
int did_set_size=0;
int bit_rate = 0;
+ int vbv_delay = 0;
//FIXME replace the crap with get_bits()
s->repeat_pict = 0;
@@ -55,6 +56,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
case PICTURE_START_CODE:
if (bytes_left >= 2) {
s->pict_type = (buf[1] >> 3) & 7;
+ vbv_delay = ((buf[1] & 0x07) << 13) | (buf[2] << 5) | (buf[3] >> 3);
}
break;
case SEQ_START_CODE:
@@ -131,8 +133,11 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
}
}
the_end: ;
- if (bit_rate && bit_rate != 0x3FFFF) {
- avctx->bit_rate = 400 * bit_rate;
+ if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && bit_rate) {
+ avctx->rc_max_rate = 400*bit_rate;
+ } else if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && bit_rate &&
+ (bit_rate != 0x3FFFF || vbv_delay != 0xFFFF)) {
+ avctx->bit_rate = 400*bit_rate;
}
}