diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2003-12-17 19:53:05 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2003-12-17 19:53:05 +0000 |
commit | d60a8f85d7016af8a412acfc8e220445a3c3436d (patch) | |
tree | 2cb76e762ac95f7655916125cd73a0b8564c3d20 /libavcodec/ratecontrol.c | |
parent | 044007c220ddda46e33432fc0501c1c244caa6fb (diff) | |
download | ffmpeg-d60a8f85d7016af8a412acfc8e220445a3c3436d.tar.gz |
vbv_delay
Originally committed as revision 2623 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ratecontrol.c')
-rw-r--r-- | libavcodec/ratecontrol.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 791acd8f0f..6247315b1d 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -198,11 +198,11 @@ static inline double bits2qp(RateControlEntry *rce, double bits){ int ff_vbv_update(MpegEncContext *s, int frame_size){ RateControlContext *rcc= &s->rc_context; const double fps= (double)s->avctx->frame_rate / (double)s->avctx->frame_rate_base; - const double buffer_size= s->avctx->rc_buffer_size; + const int buffer_size= s->avctx->rc_buffer_size; const double min_rate= s->avctx->rc_min_rate/fps; const double max_rate= s->avctx->rc_max_rate/fps; - -//printf("%f %f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate); + +//printf("%d %f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate); if(buffer_size){ int left; @@ -215,8 +215,8 @@ int ff_vbv_update(MpegEncContext *s, int frame_size){ left= buffer_size - rcc->buffer_index - 1; rcc->buffer_index += clip(left, min_rate, max_rate); - if(rcc->buffer_index > s->avctx->rc_buffer_size){ - int stuffing= ceil((rcc->buffer_index - s->avctx->rc_buffer_size)/8); + if(rcc->buffer_index > buffer_size){ + int stuffing= ceil((rcc->buffer_index - buffer_size)/8); if(stuffing < 4 && s->codec_id == CODEC_ID_MPEG4) stuffing=4; @@ -413,6 +413,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q, /* buffer overflow/underflow protection */ if(buffer_size){ double expected_size= rcc->buffer_index; + double q_limit; if(min_rate){ double d= 2*(buffer_size - expected_size)/buffer_size; @@ -420,7 +421,13 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q, else if(d<0.0001) d=0.0001; q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity); - q= FFMIN(q, bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*3, 1))); + q_limit= bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*3, 1)); + if(q > q_limit){ + if(s->avctx->debug&FF_DEBUG_RC){ + av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit); + } + q= q_limit; + } } if(max_rate){ @@ -429,7 +436,13 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q, else if(d<0.0001) d=0.0001; q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity); - q= FFMAX(q, bits2qp(rce, FFMAX(rcc->buffer_index/3, 1))); + q_limit= bits2qp(rce, FFMAX(rcc->buffer_index/3, 1)); + if(q < q_limit){ + if(s->avctx->debug&FF_DEBUG_RC){ + av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit); + } + q= q_limit; + } } } //printf("q:%f max:%f min:%f size:%f index:%d bits:%f agr:%f\n", q,max_rate, min_rate, buffer_size, rcc->buffer_index, bits, s->avctx->rc_buffer_aggressivity); |