From aa2626c567083432f56368bee9c9d43d7c8e1fef Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Sat, 13 Feb 2010 00:52:31 -0800 Subject: [PATCH] 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. --- encoder/ratecontrol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 ) { -- 2.47.3