]> git.videolan.org Git - x264.git/commitdiff
Fix two bugs in 2-pass ratecontrol
authorJason Garrett-Glaser <darkshikari@gmail.com>
Sat, 12 Dec 2009 01:22:18 +0000 (17:22 -0800)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 15 Dec 2009 20:45:06 +0000 (12:45 -0800)
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

index 03b603baac74e8266c9a0a6fa336455c02202a80..43bad454e439f95fa2715abb427b0171158eaf9c 100644 (file)
@@ -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; i<rcc->num_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; i<rcc->num_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 */