]> git.sesse.net Git - x264/commitdiff
Make --weightp 1 a better speed tradeoff
authorAlex Wright <alexw0885@gmail.com>
Wed, 24 Nov 2010 10:19:51 +0000 (02:19 -0800)
committerFiona Glaser <fiona@x264.com>
Thu, 25 Nov 2010 21:46:21 +0000 (13:46 -0800)
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).

common/common.c
common/macroblock.c
encoder/encoder.c
encoder/ratecontrol.c
encoder/slicetype.c
x264.c
x264.h

index 1f99e9e7eaa60b89e7e139df3c3c09a1fa974507..1845e3bc33980941f9f133a56beb9a0e56b8d6a9 100644 (file)
@@ -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" ) )
index 3aa067688ccff6c2b7bb0a0cb8d65465ad9facc9..6eede5acd8f19c33e5fb97c0d93970c3eae5d57a 100644 (file)
@@ -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;
index 887718fa9cf834f3862f51ef637d17473d17a540..01abf5af5ed35bd6d7f5c895b796cb97d0614f98 100644 (file)
@@ -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] );
index 675d94175f1f3c6186303d8a4cbda421de7945ad..13b115ff5545b0d9d53c4da4fddf77c5f2fa213d 100644 (file)
@@ -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 )
index f016529f47f9f2b8a26fdf2f5d7c01af3007fd4b..92efc789085798683c163e54ae2e1949167fa39e 100644 (file)
@@ -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 9a09e66df70f0380aa381a9712137cc69000fde2..48749d266dc83401a179d46da910bea64a0a1228 100644 (file)
--- 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 <integer>     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 <string>           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 c694181cbd9ef3bd3f385d1f69d0841271959aac..b300f27d01835f1515ee806b053aa146b4f01f3a 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -39,7 +39,7 @@
 
 #include <stdarg.h>
 
-#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