New "superfast" preset, much faster intra analysis
authorFiona Glaser <fiona@x264.com>
Fri, 26 Mar 2010 22:33:20 +0000 (15:33 -0700)
committerFiona Glaser <fiona@x264.com>
Sat, 27 Mar 2010 19:47:36 +0000 (12:47 -0700)
Especially at the fastest settings, intra analysis was taking up the majority of MB analysis time.
This patch takes a ton more shortcuts at the fastest encoding settings, decreasing compression 0.5-5% but improving speed greatly.
Also rearrange the fastest presets a bit: now we have ultrafast, superfast, veryfast, faster.
superfast is the old veryfast (but much faster due to this patch).
veryfast is between the old veryfast and faster.
faster is the same as before except with MB-tree on.

Encoding with subme >= 5 should be unaffected by this patch.

common/common.c
encoder/analyse.c
x264.c
x264.h

index 00cdc4f..dec02b8 100644 (file)
@@ -184,7 +184,7 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset )
         param->rc.b_mb_tree = 0;
         param->analyse.i_weighted_pred = X264_WEIGHTP_NONE;
     }
-    else if( !strcasecmp( preset, "veryfast" ) )
+    else if( !strcasecmp( preset, "superfast" ) )
     {
         param->analyse.inter = X264_ANALYSE_I8x8|X264_ANALYSE_I4x4;
         param->analyse.i_me_method = X264_ME_DIA;
@@ -195,13 +195,23 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset )
         param->rc.b_mb_tree = 0;
         param->analyse.i_weighted_pred = X264_WEIGHTP_NONE;
     }
+    else if( !strcasecmp( preset, "veryfast" ) )
+    {
+        param->analyse.i_me_method = X264_ME_HEX;
+        param->analyse.i_subpel_refine = 2;
+        param->i_frame_reference = 1;
+        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;
+    }
     else if( !strcasecmp( preset, "faster" ) )
     {
         param->analyse.b_mixed_references = 0;
         param->i_frame_reference = 2;
         param->analyse.i_subpel_refine = 4;
-        param->rc.b_mb_tree = 0;
         param->analyse.i_weighted_pred = X264_WEIGHTP_BLIND;
+        param->rc.i_lookahead = 20;
     }
     else if( !strcasecmp( preset, "fast" ) )
     {
index efb5d73..3e091d9 100644 (file)
@@ -478,12 +478,14 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
         /* Fast intra decision */
         if( h->mb.i_mb_xy - h->sh.i_first_mb > 4 )
         {
-            if(   IS_INTRA( h->mb.i_mb_type_left )
-               || IS_INTRA( h->mb.i_mb_type_top )
-               || IS_INTRA( h->mb.i_mb_type_topleft )
-               || IS_INTRA( h->mb.i_mb_type_topright )
-               || (h->sh.i_type == SLICE_TYPE_P && IS_INTRA( h->fref0[0]->mb_type[h->mb.i_mb_xy] ))
-               || (h->mb.i_mb_xy - h->sh.i_first_mb < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_8x8] + h->stat.frame.i_mb_count[I_16x16])) )
+            /* Always run in fast-intra mode for subme < 3 */
+            if( h->mb.i_subpel_refine > 2 &&
+              ( IS_INTRA( h->mb.i_mb_type_left ) ||
+                IS_INTRA( h->mb.i_mb_type_top ) ||
+                IS_INTRA( h->mb.i_mb_type_topleft ) ||
+                IS_INTRA( h->mb.i_mb_type_topright ) ||
+                (h->sh.i_type == SLICE_TYPE_P && IS_INTRA( h->fref0[0]->mb_type[h->mb.i_mb_xy] )) ||
+                (h->mb.i_mb_xy - h->sh.i_first_mb < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_8x8] + h->stat.frame.i_mb_count[I_16x16])) ) )
             { /* intra is likely */ }
             else
             {
@@ -680,7 +682,11 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
     if( h->sh.i_type == SLICE_TYPE_B )
         /* cavlc mb type prefix */
         a->i_satd_i16x16 += a->i_lambda * i_mb_b_cost_table[I_16x16];
-    if( a->b_fast_intra && a->i_satd_i16x16 > 2*i_satd_inter )
+
+    /* Not heavily tuned */
+    const uint8_t i16x16_thresh[11] = { 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4 };
+    int thresh = i16x16_thresh[h->mb.i_subpel_refine];
+    if( a->b_fast_intra && a->i_satd_i16x16 > (thresh*i_satd_inter)>>1 )
         return;
 
     /* 8x8 prediction selection */
@@ -773,7 +779,10 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
             a->i_satd_i8x8 = COST_MAX;
             i_cost = (i_cost * cost_div_fix8[idx]) >> 8;
         }
-        if( X264_MIN(i_cost, a->i_satd_i16x16) > i_satd_inter*(5+!!a->i_mbrd)/4 )
+        /* Not heavily tuned */
+        const uint8_t i8x8_thresh[11] = { 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6 };
+        int thresh = i8x8_thresh[h->mb.i_subpel_refine];
+        if( X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*thresh)>>2 )
             return;
     }
 
diff --git a/x264.c b/x264.c
index 22fd2ce..f00afce 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -288,13 +288,16 @@ static void Help( x264_param_t *defaults, int longhelp )
         "                                    --partitions none --ref 1 --scenecut 0\n"
         "                                    --subme 0 --trellis 0 --no-weightb\n"
         "                                    --weightp 0\n"
-        "                                  - veryfast:\n"
+        "                                  - superfast:\n"
         "                                    --no-mbtree --me dia --no-mixed-refs\n"
         "                                    --partitions i8x8,i4x4 --ref 1\n"
         "                                    --subme 1 --trellis 0 --weightp 0\n"
+        "                                  - veryfast:\n"
+        "                                    --no-mbtree --no-mixed-refs --ref 1\n"
+        "                                    --subme 2 --trellis 0 --weightp 0\n"
         "                                  - faster:\n"
-        "                                    --no-mbtree --no-mixed-refs --ref 2\n"
-        "                                    --subme 4 --weightp 1\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"
         "                                  - medium:\n"
@@ -317,8 +320,8 @@ static void Help( x264_param_t *defaults, int longhelp )
         "                                    --me tesa --merange 24 --partitions all\n"
         "                                    --rc-lookahead 60 --ref 16 --subme 10\n"
         "                                    --trellis 2\n" );
-    else H0( "                                  - ultrafast,veryfast,faster,fast,medium\n"
-             "                                  - slow,slower,veryslow,placebo\n" );
+    else H0( "                                  - ultrafast,superfast,veryfast,faster,fast\n"
+             "                                  - medium,slow,slower,veryslow,placebo\n" );
     H0( "      --tune                  Tune the settings for a particular type of source\n"
         "                              or situation\n"
         "                                  Overridden by user settings.\n"
diff --git a/x264.h b/x264.h
index 8b753f5..9157d76 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -35,7 +35,7 @@
 
 #include <stdarg.h>
 
-#define X264_BUILD 91
+#define X264_BUILD 92
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -426,7 +426,7 @@ int x264_param_parse( x264_param_t *, const char *name, const char *value );
  *      (either can be NULL, which implies no preset or no tune, respectively)
  *
  *      Currently available presets are, ordered from fastest to slowest: */
-static const char * const x264_preset_names[] = { "ultrafast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 };
+static const char * const x264_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 };
 
 /*      Warning: the speed of these presets scales dramatically.  Ultrafast is a full
  *      100 times faster than placebo!