]> git.videolan.org Git - x264.git/commitdiff
Correct misprediction of bitrate in threaded mode
authorGabriel Bouvigne <bouvigne@mp3-tech.org>
Tue, 16 Sep 2008 08:54:37 +0000 (01:54 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 16 Sep 2008 08:57:39 +0000 (01:57 -0700)
Improves bitrate accuracy in cases with large numbers of threads.
Loosely based on a patch by BugMaster.

encoder/ratecontrol.c

index 1559c72333a53536b5bd8c937980d3f26e0c939e..103e73bd66b56c59508e7a2b04510e580dec73aa 100644 (file)
@@ -1348,6 +1348,21 @@ static float rate_estimate_qscale( x264_t *h )
                           + h->stat.i_slice_size[SLICE_TYPE_P]
                           + h->stat.i_slice_size[SLICE_TYPE_B]);
 
+    if( h->param.i_threads > 1 )
+    {
+        int j = h->rc - h->thread[0]->rc;
+        int i;
+        for( i=1; i<h->param.i_threads; i++ )
+        {
+            x264_t *t = h->thread[ (j+i)%h->param.i_threads ];
+            double bits = t->rc->frame_size_planned;
+            if( !t->b_thread_active )
+                continue;
+            bits  = X264_MAX(bits, x264_ratecontrol_get_estimated_size(t));
+            total_bits += (int64_t)bits;
+        }
+    }
+
     if( rcc->b_2pass )
     {
         rce = *rcc->rce;