changeset 15964:d244178a3105

x264 fast first pass, patch by Robert Swain < robert POUM swain AH gmail POUM com >
author gpoirier
date Mon, 11 Jul 2005 17:52:03 +0000
parents 02066fe870f5
children 6ca3e46894b6
files ChangeLog DOCS/man/en/mplayer.1 libmpcodecs/ve_x264.c
diffstat 3 files changed, 66 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jul 11 11:37:42 2005 +0000
+++ b/ChangeLog	Mon Jul 11 17:52:03 2005 +0000
@@ -57,6 +57,7 @@
     * XviD's encoding zones and luminance masking
     * raw audio muxer
     * fixed various bugs in the EDL code
+    * x264 "turbo mode" to speed up first pass of multi-pass encoding
 
     Ports:
     * improved timer function on Mac OS X
--- a/DOCS/man/en/mplayer.1	Mon Jul 11 11:37:42 2005 +0000
+++ b/DOCS/man/en/mplayer.1	Mon Jul 11 17:52:03 2005 +0000
@@ -7947,6 +7947,31 @@
 .REss
 .
 .TP
+.B turbo=<0\-2>
+Fast first pass mode.
+During the first pass of a 2 or more pass encode it is possible to gain
+speed through disabling some options with negligible to no impact on the
+final pass output quality.
+.PD 0
+.RSs
+.IPs 0
+disabled (default)
+.IPs 1
+reduce subq, frameref and disable some inter macroblock partition analysis
+modes
+.IPs 2
+reduce subq and frameref to 1, use a diamond ME search and disable all
+sub-partition analysis modes
+.RE
+.RS
+Level 1 can increase first pass speed up to 2x with no change in the global
+PSNR of the final pass compared to a full quality first pass.
+.br
+Level 2 can increase first pass speed up to 4x with about +/- 0.05dB change
+in the global PSNR of the final pass compared to a full quality first pass.
+.REss
+.
+.TP
 .B keyint=<value>
 Sets maximum interval between IDR-frames (default: 250).
 Larger values save bits, thus improve quality, at the cost of seeking
--- a/libmpcodecs/ve_x264.c	Mon Jul 11 11:37:42 2005 +0000
+++ b/libmpcodecs/ve_x264.c	Mon Jul 11 17:52:03 2005 +0000
@@ -104,6 +104,7 @@
 static int level_idc = 40;
 static int psnr = 0;
 static int log_level = 2;
+static int turbo = 0;
 
 m_option_t x264encopts_conf[] = {
     {"bitrate", &bitrate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL},
@@ -212,24 +213,6 @@
                "2 pass encoding enabled, but no bitrate specified.\n");
         return 0;
     }
-    switch(pass) {
-    case 0:
-        mod->param.rc.b_stat_write = 0;
-        mod->param.rc.b_stat_read = 0;
-        break;
-    case 1:
-        mod->param.rc.b_stat_write = 1;
-        mod->param.rc.b_stat_read = 0;
-        break;
-    case 2:
-        mod->param.rc.b_stat_write = 0;
-        mod->param.rc.b_stat_read = 1;
-        break;
-    case 3:
-        mod->param.rc.b_stat_write = 1;
-        mod->param.rc.b_stat_read = 1;
-        break;
-    }
     if(bitrate > 0) {
         if((vbv_maxrate > 0) != (vbv_bufsize > 0)) {
             mp_msg(MSGT_MENCODER, MSGL_ERR,
@@ -252,8 +235,6 @@
         case 3: mod->param.analyse.i_me_method = X264_ME_UMH; break;
         case 4: mod->param.analyse.i_me_method = X264_ME_ESA; break;
     }
-    if(me_method >= 3)
-        mod->param.analyse.i_me_range = me_range;
     mod->param.analyse.inter = 0;
     if(p4x4mv) mod->param.analyse.inter |= X264_ANALYSE_PSUB8x8;
     if(p8x8mv) mod->param.analyse.inter |= X264_ANALYSE_PSUB16x16;
@@ -277,6 +258,45 @@
     mod->param.vui.i_sar_height = d_height*width;
     mod->param.i_threads = threads;
 
+    switch(pass) {
+    case 0:
+        mod->param.rc.b_stat_write = 0;
+        mod->param.rc.b_stat_read = 0;
+        break;
+    case 1:
+        /* Adjust or disable some flags to gain speed in the first pass */
+        if(turbo == 1)
+        {
+            mod->param.i_frame_reference = ( frame_ref + 1 ) >> 1;
+            mod->param.analyse.i_subpel_refine = max( min( 3, subq - 1 ), 1 );
+            mod->param.analyse.inter &= ( ~X264_ANALYSE_PSUB8x8 );
+            mod->param.analyse.inter &= ( ~X264_ANALYSE_BSUB16x16 );
+        }
+        else if(turbo == 2)
+        {
+            mod->param.i_frame_reference = 1;
+            mod->param.analyse.i_subpel_refine = 1;
+            mod->param.analyse.i_me_method = X264_ME_DIA;
+            mod->param.analyse.inter = 0;
+            mod->param.analyse.b_transform_8x8 = 0;
+            mod->param.analyse.b_weighted_bipred = 0;
+        }
+        mod->param.rc.b_stat_write = 1;
+        mod->param.rc.b_stat_read = 0;
+        break;
+    case 2:
+        mod->param.rc.b_stat_write = 0;
+        mod->param.rc.b_stat_read = 1;
+        break;
+    case 3:
+        mod->param.rc.b_stat_write = 1;
+        mod->param.rc.b_stat_read = 1;
+        break;
+    }
+
+    if(me_method >= 3)
+        mod->param.analyse.i_me_range = me_range;
+
     switch(outfmt) {
     case IMGFMT_I420:
         mod->param.i_csp = X264_CSP_I420;