[x264-devel] commit: Fix two bugs in 2-pass ratecontrol (Jason Garrett-Glaser )

git version control git at videolan.org
Tue Dec 15 21:47:07 CET 2009


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Fri Dec 11 17:22:18 2009 -0800| [c9cafc75352f036bdcb90f2a26e7233920567b13] | committer: Jason Garrett-Glaser 

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.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=c9cafc75352f036bdcb90f2a26e7233920567b13
---

 encoder/ratecontrol.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index 03b603b..43bad45 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; 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 */



More information about the x264-devel mailing list