diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-01-29 15:50:54 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-01-29 15:50:54 +0000 |
commit | 2c8b796fa9000bf7c5946771701a41ea2f0ae3d9 (patch) | |
tree | 08ae6186b7a0a83af6ced2d513650cf53c5ef0f0 /libavcodec | |
parent | 8fd19ab286ea352eff0e2162d0fc5e49fb21110e (diff) | |
download | ffmpeg-2c8b796fa9000bf7c5946771701a41ea2f0ae3d9.tar.gz |
b frames + cbr fix
Originally committed as revision 2730 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mpegvideo.c | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 7004a9680b..7d1c5ba1ef 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1939,53 +1939,56 @@ int MPV_encode_picture(AVCodecContext *avctx, for(i=0; i<4; i++){ avctx->error[i] += s->current_picture_ptr->error[i]; } - } - - flush_put_bits(&s->pb); - s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; - stuffing_count= ff_vbv_update(s, s->frame_bits); - if(stuffing_count){ - switch(s->codec_id){ - case CODEC_ID_MPEG1VIDEO: - case CODEC_ID_MPEG2VIDEO: - while(stuffing_count--){ - put_bits(&s->pb, 8, 0); - } - break; - case CODEC_ID_MPEG4: - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, 0x1C3); - stuffing_count -= 4; - while(stuffing_count--){ - put_bits(&s->pb, 8, 0xFF); - } - break; - default: - av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); - } flush_put_bits(&s->pb); s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; - } - /* update mpeg1/2 vbv_delay for CBR */ - if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate){ - int vbv_delay; + stuffing_count= ff_vbv_update(s, s->frame_bits); + if(stuffing_count){ + switch(s->codec_id){ + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + while(stuffing_count--){ + put_bits(&s->pb, 8, 0); + } + break; + case CODEC_ID_MPEG4: + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, 0x1C3); + stuffing_count -= 4; + while(stuffing_count--){ + put_bits(&s->pb, 8, 0xFF); + } + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); + } + flush_put_bits(&s->pb); + s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; + } - assert(s->repeat_first_field==0); - - vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate); - assert(vbv_delay < 0xFFFF); + /* update mpeg1/2 vbv_delay for CBR */ + if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate){ + int vbv_delay; - s->vbv_delay_ptr[0] &= 0xF8; - s->vbv_delay_ptr[0] |= vbv_delay>>13; - s->vbv_delay_ptr[1] = vbv_delay>>5; - s->vbv_delay_ptr[2] &= 0x07; - s->vbv_delay_ptr[2] |= vbv_delay<<3; + assert(s->repeat_first_field==0); + + vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate); + assert(vbv_delay < 0xFFFF); + + s->vbv_delay_ptr[0] &= 0xF8; + s->vbv_delay_ptr[0] |= vbv_delay>>13; + s->vbv_delay_ptr[1] = vbv_delay>>5; + s->vbv_delay_ptr[2] &= 0x07; + s->vbv_delay_ptr[2] |= vbv_delay<<3; + } + s->total_bits += s->frame_bits; + avctx->frame_bits = s->frame_bits; + }else{ + assert((pbBufPtr(&s->pb) == s->pb.buf)); + s->frame_bits=0; } - - s->total_bits += s->frame_bits; - avctx->frame_bits = s->frame_bits; + assert((s->frame_bits&7)==0); return s->frame_bits/8; } |