From 7eaff1792dd1064ff607fec47d0d7d91fdc62641 Mon Sep 17 00:00:00 2001 From: Gabriel Bouvigne Date: Tue, 16 Sep 2008 01:53:02 -0700 Subject: [PATCH] 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. --- encoder/ratecontrol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); -- 2.47.3