]> git.sesse.net Git - x264/commitdiff
Improve VBV, fix bug in 2-pass VBV introduced in MB-tree
authorFiona Glaser <fiona@x264.com>
Sun, 11 Oct 2009 00:35:03 +0000 (17:35 -0700)
committerFiona Glaser <fiona@x264.com>
Mon, 12 Oct 2009 08:41:38 +0000 (01:41 -0700)
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).

encoder/ratecontrol.c
x264.c

index a5df9d4cb7f02c2fd3019530f1aaf3f4cd79fd87..0aaf1e963b47c45d59c286c2e2e5a6b514a775b0 100644 (file)
@@ -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 ab76a9385c6ff8d7c8ccd8db8e8648dba893eb6b..a440ab7f7b18d1ae4956d4b402e9c148ad07f1d7 100644 (file)
--- 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 );