From f30aed6d810ef408cbf19cc6760605b0b87cbfde Mon Sep 17 00:00:00 2001 From: Fiona Glaser Date: Fri, 11 Dec 2009 17:22:18 -0800 Subject: [PATCH] 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. --- encoder/ratecontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 02164a4a..b52de4ff 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 */ -- 2.40.0