From: Jason Garrett-Glaser Date: Sat, 19 Jun 2010 08:41:07 +0000 (-0700) Subject: Improve 2-pass bitrate prediction X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=f7ca49910a4663fd743734f288ea88079e09deeb;p=x264.git Improve 2-pass bitrate prediction Adapt based on distance to the end in bits, not in frames. Helps in videos with absurdly simple end sections, e.g. black frames. --- diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index aef50836..16afbf05 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -2034,9 +2034,6 @@ static float rate_estimate_qscale( x264_t *h ) double lmax = rcc->lmax[pict_type]; 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->i_frame ) - abr_buffer *= 0.5 * sqrt( rcc->num_entries - h->i_frame ); if( rcc->b_vbv ) { @@ -2062,6 +2059,15 @@ static float rate_estimate_qscale( x264_t *h ) predicted_bits += (int64_t)(h->i_thread_frames - 1) * rcc->bitrate / rcc->fps; } + /* Adjust ABR buffer based on distance to the end of the video. */ + if( rcc->num_entries > h->i_frame ) + { + double final_bits = rcc->entry[rcc->num_entries-1].expected_bits; + double video_pos = rce.expected_bits / final_bits; + double scale_factor = sqrt( (1 - video_pos) * rcc->num_entries ); + abr_buffer *= 0.5 * X264_MAX( scale_factor, 0.5 ); + } + diff = predicted_bits - (int64_t)rce.expected_bits; q = rce.new_qscale; q /= x264_clip3f((double)(abr_buffer - diff) / abr_buffer, .5, 2);