From: Fiona Glaser Date: Sun, 11 Oct 2009 00:35:03 +0000 (-0700) Subject: Improve VBV, fix bug in 2-pass VBV introduced in MB-tree X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c51d00b7c742aa84ac7e113ba03d808cb3132af2;p=libx264 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). --- diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index a5df9d4c..0aaf1e96 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 ab76a938..a440ab7f 100644 --- a/x264.c +++ b/x264.c @@ -233,7 +233,7 @@ static void Help( x264_param_t *defaults, int longhelp ) H2( " --qpmin Set min QP [%d]\n", defaults->rc.i_qp_min ); H2( " --qpmax Set max QP [%d]\n", defaults->rc.i_qp_max ); H2( " --qpstep Set max QP step [%d]\n", defaults->rc.i_qp_step ); - H2( " --ratetol Allowed variance of average bitrate [%.1f]\n", defaults->rc.f_rate_tolerance ); + H2( " --ratetol Tolerance of ABR ratecontrol and VBV [%.1f]\n", defaults->rc.f_rate_tolerance ); H2( " --ipratio QP factor between I and P [%.2f]\n", defaults->rc.f_ip_factor ); H2( " --pbratio QP factor between P and B [%.2f]\n", defaults->rc.f_pb_factor ); H2( " --chroma-qp-offset QP difference between chroma and luma [%d]\n", defaults->analyse.i_chroma_qp_offset );