From: Alex Wright Date: Wed, 24 Nov 2010 10:19:51 +0000 (-0800) Subject: Make --weightp 1 a better speed tradeoff X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=e440dc0f7909c67cdca148fc8a9ea413521e0e5b;p=x264.git Make --weightp 1 a better speed tradeoff Since fade analysis is now so fast, weightp 1 now does fade analysis but no reference duplication. This is the opposite of what it used to do (reference duplication but no fade analysis). This also gives weightp's better fade quality to faster presets (up to superfast). --- diff --git a/common/common.c b/common/common.c index 1f99e9e7..1845e3bc 100644 --- a/common/common.c +++ b/common/common.c @@ -204,7 +204,7 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset ) param->analyse.b_mixed_references = 0; param->analyse.i_trellis = 0; param->rc.b_mb_tree = 0; - param->analyse.i_weighted_pred = X264_WEIGHTP_NONE; + param->analyse.i_weighted_pred = X264_WEIGHTP_SIMPLE; param->rc.i_lookahead = 0; } else if( !strcasecmp( preset, "veryfast" ) ) @@ -214,7 +214,7 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset ) param->i_frame_reference = 1; param->analyse.b_mixed_references = 0; param->analyse.i_trellis = 0; - param->analyse.i_weighted_pred = X264_WEIGHTP_NONE; + param->analyse.i_weighted_pred = X264_WEIGHTP_SIMPLE; param->rc.i_lookahead = 10; } else if( !strcasecmp( preset, "faster" ) ) @@ -222,13 +222,14 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset ) param->analyse.b_mixed_references = 0; param->i_frame_reference = 2; param->analyse.i_subpel_refine = 4; - param->analyse.i_weighted_pred = X264_WEIGHTP_BLIND; + param->analyse.i_weighted_pred = X264_WEIGHTP_SIMPLE; param->rc.i_lookahead = 20; } else if( !strcasecmp( preset, "fast" ) ) { param->i_frame_reference = 2; param->analyse.i_subpel_refine = 6; + param->analyse.i_weighted_pred = X264_WEIGHTP_SIMPLE; param->rc.i_lookahead = 30; } else if( !strcasecmp( preset, "medium" ) ) diff --git a/common/macroblock.c b/common/macroblock.c index 5c76d3f8..9075efc9 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -239,8 +239,6 @@ int x264_macroblock_cache_allocate( x264_t *h ) int i_refs = X264_MIN(X264_REF_MAX, (i ? 1 + !!h->param.i_bframe_pyramid : h->param.i_frame_reference) ) << h->param.b_interlaced; if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) i_refs = X264_MIN(X264_REF_MAX, i_refs + 1 + (BIT_DEPTH == 8)); //smart weights add two duplicate frames, one in >8-bit - else if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_BLIND ) - i_refs = X264_MIN(X264_REF_MAX, i_refs + 1); //blind weights add one duplicate frame for( int j = !i; j < i_refs; j++ ) { @@ -277,7 +275,7 @@ int x264_macroblock_cache_allocate( x264_t *h ) //SMART can weight one ref and one offset -1 numweightbuf = 2; else - //blind only has one weighted copy (offset -1) + //simple only has one weighted ref numweightbuf = 1; } @@ -398,7 +396,7 @@ void x264_macroblock_slice_init( x264_t *h ) { memset( h->mb.cache.skip, 0, sizeof( h->mb.cache.skip ) ); - if( h->sh.i_disable_deblocking_filter_idc != 1 && h->param.analyse.i_weighted_pred ) + if( h->sh.i_disable_deblocking_filter_idc != 1 && h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) { deblock_ref_table(-2) = -2; deblock_ref_table(-1) = -1; @@ -999,7 +997,7 @@ void x264_macroblock_cache_load_deblock( x264_t *h ) h->mb.i_neighbour = new_neighbour; } - if( h->param.analyse.i_weighted_pred && h->sh.i_type == SLICE_TYPE_P ) + if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART && h->sh.i_type == SLICE_TYPE_P ) { /* Handle reference frame duplicates */ int i8 = x264_scan8[0] - 8; diff --git a/encoder/encoder.c b/encoder/encoder.c index e8fb3d9f..3c2d3d75 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -772,8 +772,6 @@ static int x264_validate_parameters( x264_t *h ) h->param.analyse.i_weighted_pred = x264_clip3( h->param.analyse.i_weighted_pred, X264_WEIGHTP_NONE, X264_WEIGHTP_SMART ); if( !h->param.analyse.i_weighted_pred && h->param.rc.b_mb_tree && h->param.analyse.b_psy && !h->param.b_interlaced ) h->param.analyse.i_weighted_pred = X264_WEIGHTP_FAKE; - if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_BLIND && BIT_DEPTH > 8 ) - h->param.analyse.i_weighted_pred = X264_WEIGHTP_NONE; if( h->i_thread_frames > 1 ) { @@ -996,7 +994,7 @@ x264_t *x264_encoder_open( x264_param_t *param ) || h->param.i_bframe_adaptive || h->param.i_scenecut_threshold || h->param.rc.b_mb_tree - || h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ); + || h->param.analyse.i_weighted_pred ); h->frames.b_have_lowres |= h->param.rc.b_stat_read && h->param.rc.i_vbv_buffer_size > 0; h->frames.b_have_sub8x8_esa = !!(h->param.analyse.inter & X264_ANALYSE_PSUB8x8); @@ -1433,6 +1431,10 @@ int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t if( i <= 1 ) /* empty list, definitely can't duplicate frame */ return -1; + //Duplication is only used in X264_WEIGHTP_SMART + if( h->param.analyse.i_weighted_pred != X264_WEIGHTP_SMART ) + return -1; + /* Duplication is a hack to compensate for crappy rounding in motion compensation. * With high bit depth, it's not worth doing, so turn it off except in the case of * unweighted dupes. */ @@ -1610,7 +1612,7 @@ static inline void x264_reference_build_list( x264_t *h, int i_poc ) if( h->fenc->i_type == X264_TYPE_P ) { int idx = -1; - if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) + if( h->param.analyse.i_weighted_pred >= X264_WEIGHTP_SIMPLE ) { x264_weight_t w[3]; w[1].weightfn = w[2].weightfn = NULL; @@ -1639,15 +1641,6 @@ static inline void x264_reference_build_list( x264_t *h, int i_poc ) } } } - else if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_BLIND ) - { - //weighted offset=-1 - x264_weight_t w[3]; - SET_WEIGHT( w[0], 1, 1, 0, -1 ); - h->fenc->weight[0][0].i_denom = 0; - w[1].weightfn = w[2].weightfn = NULL; - idx = x264_weighted_reference_duplicate( h, 0, w ); - } h->mb.ref_blind_dupe = idx; } @@ -2877,7 +2870,7 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current, if( h->sh.i_type == SLICE_TYPE_P ) { h->stat.i_consecutive_bframes[h->fdec->i_frame - h->fref0[0]->i_frame - 1]++; - if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) + if( h->param.analyse.i_weighted_pred >= X264_WEIGHTP_SIMPLE ) { h->stat.i_wpred[0] += !!h->sh.weight[0][0].weightfn; h->stat.i_wpred[1] += !!h->sh.weight[0][1].weightfn || !!h->sh.weight[0][2].weightfn; @@ -3226,7 +3219,7 @@ void x264_encoder_close ( x264_t *h ) fixed_pred_modes[3][2] * 100.0 / sum_pred_modes[3], fixed_pred_modes[3][3] * 100.0 / sum_pred_modes[3] ); - if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART && h->stat.i_frame_count[SLICE_TYPE_P] > 0 ) + if( h->param.analyse.i_weighted_pred >= X264_WEIGHTP_SIMPLE && h->stat.i_frame_count[SLICE_TYPE_P] > 0 ) x264_log( h, X264_LOG_INFO, "Weighted P-Frames: Y:%.1f%% UV:%.1f%%\n", h->stat.i_wpred[0] * 100.0 / h->stat.i_frame_count[SLICE_TYPE_P], h->stat.i_wpred[1] * 100.0 / h->stat.i_frame_count[SLICE_TYPE_P] ); diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index e949e242..780c0e15 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -284,7 +284,7 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame, float *quant_off } } /* Need variance data for weighted prediction */ - if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_FAKE || h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) + if( h->param.analyse.i_weighted_pred ) { for( int mb_y = 0; mb_y < h->mb.i_mb_height; mb_y++ ) for( int mb_x = 0; mb_x < h->mb.i_mb_width; mb_x++ ) @@ -1558,7 +1558,7 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler ) goto fail; } - if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART && h->sh.weight[0][0].weightfn ) + if( h->param.analyse.i_weighted_pred >= X264_WEIGHTP_SIMPLE && h->sh.weight[0][0].weightfn ) { if( fprintf( rc->p_stat_file_out, "w:%d,%d,%d", h->sh.weight[0][0].i_denom, h->sh.weight[0][0].i_scale, h->sh.weight[0][0].i_offset ) < 0 ) diff --git a/encoder/slicetype.c b/encoder/slicetype.c index a2f2a6c2..49d9e51f 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -647,8 +647,7 @@ static int x264_slicetype_frame_cost( x264_t *h, x264_mb_analysis_t *a, do_search[1] = b != p1 && frames[b]->lowres_mvs[1][p1-b-1][0][0] == 0x7FFF; if( do_search[0] ) { - if( ( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART || - h->param.analyse.i_weighted_pred == X264_WEIGHTP_FAKE ) && b == p1 ) + if( h->param.analyse.i_weighted_pred && b == p1 ) { x264_emms(); x264_weights_analyse( h, frames[b], frames[p0], 1 ); @@ -1549,7 +1548,7 @@ void x264_slicetype_decide( x264_t *h ) /* Analyse for weighted P frames */ if( !h->param.rc.b_stat_read && h->lookahead->next.list[bframes]->i_type == X264_TYPE_P - && h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) + && h->param.analyse.i_weighted_pred >= X264_WEIGHTP_SIMPLE ) { x264_emms(); x264_weights_analyse( h, h->lookahead->next.list[bframes], h->lookahead->last_nonb, 0 ); diff --git a/x264.c b/x264.c index 2fbf3e46..6fdd24a7 100644 --- a/x264.c +++ b/x264.c @@ -436,15 +436,16 @@ static void help( x264_param_t *defaults, int longhelp ) " - superfast:\n" " --no-mbtree --me dia --no-mixed-refs\n" " --partitions i8x8,i4x4 --rc-lookahead 0\n" - " --ref 1 --subme 1 --trellis 0 --weightp 0\n" + " --ref 1 --subme 1 --trellis 0 --weightp 1\n" " - veryfast:\n" " --no-mixed-refs --rc-lookahead 10\n" - " --ref 1 --subme 2 --trellis 0 --weightp 0\n" + " --ref 1 --subme 2 --trellis 0 --weightp 1\n" " - faster:\n" " --no-mixed-refs --rc-lookahead 20\n" " --ref 2 --subme 4 --weightp 1\n" " - fast:\n" " --rc-lookahead 30 --ref 2 --subme 6\n" + " --weightp 1\n" " - medium:\n" " Default settings apply.\n" " - slow:\n" @@ -609,8 +610,8 @@ static void help( x264_param_t *defaults, int longhelp ) H2( " --no-weightb Disable weighted prediction for B-frames\n" ); H1( " --weightp Weighted prediction for P-frames [%d]\n" " - 0: Disabled\n" - " - 1: Blind offset\n" - " - 2: Smart analysis\n", defaults->analyse.i_weighted_pred ); + " - 1: Weighted refs\n" + " - 2: Weighted refs + Duplicates\n", defaults->analyse.i_weighted_pred ); H1( " --me Integer pixel motion estimation method [\"%s\"]\n", strtable_lookup( x264_motion_est_names, defaults->analyse.i_me_method ) ); H2( " - dia: diamond search, radius 1 (fast)\n" diff --git a/x264.h b/x264.h index e144e514..bfe478b1 100644 --- a/x264.h +++ b/x264.h @@ -39,7 +39,7 @@ #include -#define X264_BUILD 109 +#define X264_BUILD 110 /* x264_t: * opaque handler for encoder */ @@ -151,7 +151,7 @@ typedef struct #define X264_B_ADAPT_FAST 1 #define X264_B_ADAPT_TRELLIS 2 #define X264_WEIGHTP_NONE 0 -#define X264_WEIGHTP_BLIND 1 +#define X264_WEIGHTP_SIMPLE 1 #define X264_WEIGHTP_SMART 2 #define X264_B_PYRAMID_NONE 0 #define X264_B_PYRAMID_STRICT 1