[x264-devel] commit: Improve 2-pass bitrate prediction (Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Fri Jun 25 09:58:06 CEST 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Sat Jun 19 01:41:07 2010 -0700| [f7ca49910a4663fd743734f288ea88079e09deeb] | committer: Jason Garrett-Glaser 

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.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=f7ca49910a4663fd743734f288ea88079e09deeb
---

 encoder/ratecontrol.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index aef5083..16afbf0 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);



More information about the x264-devel mailing list