]> git.videolan.org Git - x264.git/commitdiff
Fix a case in which VBV underflows can occur
authorGabriel Bouvigne <bouvigne@mp3-tech.org>
Tue, 16 Sep 2008 08:53:02 +0000 (01:53 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 16 Sep 2008 08:57:38 +0000 (01:57 -0700)
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

index 3251f4f5fe33ee5668f57728c63376fc79a59d19..1559c72333a53536b5bd8c937980d3f26e0c939e 100644 (file)
@@ -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);