[x264-devel] commit: Improve VBV, fix bug in 2-pass VBV introduced in MB-tree ( Jason Garrett-Glaser )

git version control git at videolan.org
Mon Oct 12 10:42:28 CEST 2009


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Sat Oct 10 17:35:03 2009 -0700| [7182ae8d08acef6153cad9b9c27efb4fa985a657] | committer: Jason Garrett-Glaser 

Improve VBV, fix bug in 2-pass VBV introduced in MB-tree
Bug caused AQ'd row/frame costs to not be calculated (and thus caused underflows).
Also make VBV more aggressive with more threads in 2-pass mode.
Finally, --ratetol now affects VBV aggressiveness (higher is less aggressive).

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

 encoder/ratecontrol.c |   10 ++++++++--
 x264.c                |    2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index 16ac7de..2bd125f 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -294,7 +294,11 @@ int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame )
             goto fail;
 
         for( i = 0; i < h->mb.i_mb_count; i++ )
+        {
             frame->f_qp_offset[i] = ((float)(int16_t)endian_fix16( rc->qp_buffer[i] )) * (1/256.0);
+            if( h->frames.b_have_lowres )
+                frame->i_inv_qscale_factor[i] = x264_exp2fix8(frame->f_qp_offset[i]);
+        }
     }
     else
         x264_adaptive_quant_frame( h, frame );
@@ -1131,8 +1135,10 @@ void x264_ratecontrol_mb( x264_t *h, int bits )
             /* More threads means we have to be more cautious in letting ratecontrol use up extra bits.
              * In 2-pass mode we can be more trusting of the planned frame sizes, since they were decided
              * by actual encoding instead of SATD prediction. */
-            float rc_tol = h->param.rc.b_stat_read ? (buffer_left_planned / rc->buffer_size) * rc->frame_size_planned
-                                                   : (buffer_left_planned / h->param.i_threads);
+            float rc_tol = buffer_left_planned / h->param.i_threads * rc->rate_tolerance;
+            if( h->param.rc.b_stat_read )
+                rc_tol *= rc->frame_size_planned / rc->buffer_size;
+
             /* Don't modify the row QPs until a sufficent amount of the bits of the frame have been processed, in case a flat */
             /* area at the top of the frame was measured inaccurately. */
             if( row_bits_so_far(h,y) < 0.05 * rc->frame_size_planned )
diff --git a/x264.c b/x264.c
index ab76a93..a440ab7 100644
--- a/x264.c
+++ b/x264.c
@@ -233,7 +233,7 @@ static void Help( x264_param_t *defaults, int longhelp )
     H2( "      --qpmin <integer>       Set min QP [%d]\n", defaults->rc.i_qp_min );
     H2( "      --qpmax <integer>       Set max QP [%d]\n", defaults->rc.i_qp_max );
     H2( "      --qpstep <integer>      Set max QP step [%d]\n", defaults->rc.i_qp_step );
-    H2( "      --ratetol <float>       Allowed variance of average bitrate [%.1f]\n", defaults->rc.f_rate_tolerance );
+    H2( "      --ratetol <float>       Tolerance of ABR ratecontrol and VBV [%.1f]\n", defaults->rc.f_rate_tolerance );
     H2( "      --ipratio <float>       QP factor between I and P [%.2f]\n", defaults->rc.f_ip_factor );
     H2( "      --pbratio <float>       QP factor between P and B [%.2f]\n", defaults->rc.f_pb_factor );
     H2( "      --chroma-qp-offset <integer>  QP difference between chroma and luma [%d]\n", defaults->analyse.i_chroma_qp_offset );



More information about the x264-devel mailing list