From e9a4834a7da195365b194b2f084f0d1654878628 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 14 Feb 2004 13:37:58 +0000 Subject: [PATCH] normalize adaptive quantizatiuon fix (based upon a patch by (Jindrich Makovicka )) Originally committed as revision 2780 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/ratecontrol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 6c90b1b6cd..473645def4 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -545,9 +545,10 @@ static void adaptive_quantization(MpegEncContext *s, double q){ /* handle qmin/qmax cliping */ if(s->flags&CODEC_FLAG_NORMALIZE_AQP){ + float factor= bits_sum/cplx_sum; for(i=0; imb_num; i++){ float newq= q*cplx_tab[i]/bits_tab[i]; - newq*= bits_sum/cplx_sum; + newq*= factor; if (newq > qmax){ bits_sum -= bits_tab[i]; @@ -558,6 +559,8 @@ static void adaptive_quantization(MpegEncContext *s, double q){ cplx_sum -= cplx_tab[i]*q/qmin; } } + if(bits_sum < 0.001) bits_sum= 0.001; + if(cplx_sum < 0.001) cplx_sum= 0.001; } for(i=0; imb_num; i++){