Commit 08e737d1 authored by Gabriel Bouvigne's avatar Gabriel Bouvigne Committed by Fiona Glaser

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.
parent bdb435f7
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment