From: Gabriel Bouvigne Date: Tue, 16 Sep 2008 08:53:02 +0000 (-0700) Subject: Fix a case in which VBV underflows can occur X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=7eaff1792dd1064ff607fec47d0d7d91fdc62641;p=x264.git Fix a case in which VBV underflows can occur Fix a potential case where a frame might be initially allocated too low a QP, which would then have to be raised a low during row-based ratecontrol. In some cases, this could even produce VBV underflows in 2pass mode. --- diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 3251f4f5..1559c723 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -1418,10 +1418,12 @@ static float rate_estimate_qscale( x264_t *h ) double expected_fullness = rce.expected_vbv / rcc->buffer_size; double qmax = q*(2 - expected_fullness); double size_constraint = 1 + expected_fullness; + qmax = X264_MAX(qmax, rce.new_qscale); if (expected_fullness < .05) qmax = lmax; qmax = X264_MIN(qmax, lmax); - while( (expected_vbv < rce.expected_vbv/size_constraint) && (q < qmax) ) + while( ((expected_vbv < rce.expected_vbv/size_constraint) && (q < qmax)) || + ((expected_vbv < 0) && (q < lmax))) { q *= 1.05; expected_size = qscale2bits(&rce, q);