From: Jason Garrett-Glaser Date: Sat, 13 Feb 2010 08:52:31 +0000 (-0800) Subject: Make the ABR buffer consider the distance to the end of the video X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=aa2626c567083432f56368bee9c9d43d7c8e1fef;p=x264.git Make the ABR buffer consider the distance to the end of the video 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. --- diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 0c946ba8..8c615829 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -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 ) {