aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-09-11 17:20:08 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-09-11 17:50:14 +0200
commita990a308835f11461595fa15d66ab4348254bbf6 (patch)
tree1d013d15e3981ef2fd52669ac1c9c2fcb0d7d93c /libavcodec
parent2fe8fd394829d44fd2ac5c7ac30ff01d8f228dd0 (diff)
downloadffmpeg-a990a308835f11461595fa15d66ab4348254bbf6.tar.gz
ratecontrol: correct predictor in case of stuffing
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/mpegvideo.h1
-rw-r--r--libavcodec/mpegvideo_enc.c1
-rw-r--r--libavcodec/ratecontrol.c3
3 files changed, 4 insertions, 1 deletions
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 0fb7d67dbc..39f23222d3 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -469,6 +469,7 @@ typedef struct MpegEncContext {
/* bit rate control */
int64_t total_bits;
int frame_bits; ///< bits used for the current frame
+ int stuffing_bits; ///< bits used for stuffing
int next_lambda; ///< next lambda used for retrying to encode a frame
RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d8290a7dfc..ab6115b6f0 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1579,6 +1579,7 @@ vbv_retry:
s->frame_bits = put_bits_count(&s->pb);
stuffing_count = ff_vbv_update(s, s->frame_bits);
+ s->stuffing_bits = 8*stuffing_count;
if (stuffing_count) {
if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) <
stuffing_count + 50) {
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index a693ec4ca0..7b8e6493f0 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -679,7 +679,8 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
/* update predictors */
if(picture_number>2 && !dry_run){
const int last_var= s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum;
- update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits);
+ av_assert1(s->frame_bits >= s->stuffing_bits);
+ update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits - s->stuffing_bits);
}
if(s->flags&CODEC_FLAG_PASS2){