]> git.videolan.org Git - x264.git/commitdiff
Make the ABR buffer consider the distance to the end of the video
authorJason Garrett-Glaser <darkshikari@gmail.com>
Sat, 13 Feb 2010 08:52:31 +0000 (00:52 -0800)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Mon, 15 Feb 2010 09:00:03 +0000 (01:00 -0800)
Should improve bitrate accuracy in 2-pass mode.
May also slightly improve quality by allowing more variation earlier-on in a file.

Also fix abr_buffer with 1-pass: it does something very different than what it does for 2-pass.
Thus, the earlier change that increased it based on threads caused 1-pass ABR to be somewhat less accurate.

encoder/ratecontrol.c

index 0c946ba841d5e7d5fef38cd484df6d87c134a3cb..8c6158293d770c3db589343c41b4b243b81307da 100644 (file)
@@ -1784,13 +1784,15 @@ static float rate_estimate_qscale( x264_t *h )
     }
     else
     {
-        double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate * h->i_thread_frames;
+        double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate;
 
         if( rcc->b_2pass )
         {
-            //FIXME adjust abr_buffer based on distance to the end of the video
             int64_t diff;
             int64_t predicted_bits = total_bits;
+            /* Adjust ABR buffer based on distance to the end of the video. */
+            if( rcc->num_entries > h->fenc->i_frame )
+                abr_buffer *= 0.5 * sqrt( rcc->num_entries - h->fenc->i_frame );
 
             if( rcc->b_vbv )
             {