From: Jason Garrett-Glaser Date: Sat, 12 Dec 2009 01:22:18 +0000 (-0800) Subject: Fix two bugs in 2-pass ratecontrol X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=c9cafc75352f036bdcb90f2a26e7233920567b13;p=x264.git Fix two bugs in 2-pass ratecontrol last_qscale_for wasn't set during the 2pass init code. abr_buffer was way too small in the case of multiple threads, so accordingly increase its buffer size based on the number of threads. May significantly increase quality with many threads in 2-pass mode, especially in cases with extremely large I-frames, such as anime. --- diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 03b603ba..43bad454 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -1813,7 +1813,7 @@ static float rate_estimate_qscale( x264_t *h ) } else { - double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate; + double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate * (h->param.b_sliced_threads?1:h->param.i_threads); if( rcc->b_2pass ) { @@ -2275,7 +2275,11 @@ static int init_pass2( x264_t *h ) expected_bits = 1; for(i=0; inum_entries; i++) - expected_bits += qscale2bits(&rcc->entry[i], get_qscale(h, &rcc->entry[i], 1.0, i)); + { + double q = get_qscale(h, &rcc->entry[i], 1.0, i); + expected_bits += qscale2bits(&rcc->entry[i], q); + rcc->last_qscale_for[rcc->entry[i].pict_type] = q; + } step_mult = all_available_bits / expected_bits; rate_factor = 0; @@ -2292,6 +2296,7 @@ static int init_pass2( x264_t *h ) for(i=0; inum_entries; i++) { qscale[i] = get_qscale(h, &rcc->entry[i], rate_factor, i); + rcc->last_qscale_for[rcc->entry[i].pict_type] = qscale[i]; } /* fixed I/B qscale relative to P */