[x264-devel] Add "--stitchable" option for segmented encoding

Jason Garrett-Glaser git at videolan.org
Thu Jul 4 03:01:42 CEST 2013


x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Fri May 31 17:01:29 2013 -0700| [8c8b46f1fbcf1c4b684afff9160d074077909965] | committer: Jason Garrett-Glaser

Add "--stitchable" option for segmented encoding

Stops x264 from attempting to optimize global stream headers, ensuring that
different segments of a video will have identical headers when used with
identical encoding settings.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=8c8b46f1fbcf1c4b684afff9160d074077909965
---

 common/common.c       |    4 ++++
 encoder/encoder.c     |    1 +
 encoder/ratecontrol.c |    3 ++-
 encoder/set.c         |    2 +-
 x264.c                |    3 +++
 x264.h                |    7 ++++++-
 6 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/common/common.c b/common/common.c
index d83956c..5001f8f 100644
--- a/common/common.c
+++ b/common/common.c
@@ -1037,6 +1037,8 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->b_fake_interlaced = atobool(value);
     OPT("frame-packing")
         p->i_frame_packing = atoi(value);
+    OPT("stitchable")
+        p->b_stitchable = atobool(value);
     OPT("opencl")
         p->b_opencl = atobool( value );
     OPT("opencl-clbin")
@@ -1330,6 +1332,8 @@ char *x264_param2string( x264_param_t *p, int b_res )
     s += sprintf( s, " decimate=%d", p->analyse.b_dct_decimate );
     s += sprintf( s, " interlaced=%s", p->b_interlaced ? p->b_tff ? "tff" : "bff" : p->b_fake_interlaced ? "fake" : "0" );
     s += sprintf( s, " bluray_compat=%d", p->b_bluray_compat );
+    if( p->b_stitchable )
+        s += sprintf( s, " stitchable=%d", p->b_stitchable );
 
     s += sprintf( s, " constrained_intra=%d", p->b_constrained_intra );
 
diff --git a/encoder/encoder.c b/encoder/encoder.c
index a1d1ea2..5deea49 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1079,6 +1079,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
     BOOLIFY( b_fake_interlaced );
     BOOLIFY( b_open_gop );
     BOOLIFY( b_bluray_compat );
+    BOOLIFY( b_stitchable );
     BOOLIFY( b_full_recon );
     BOOLIFY( b_opencl );
     BOOLIFY( analyse.b_transform_8x8 );
diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index 0fc7a0a..d8cec78 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -1118,7 +1118,8 @@ parse_error:
             total_qp_aq += qp_aq;
             p = next;
         }
-        h->pps->i_pic_init_qp = SPEC_QP( (int)(total_qp_aq / rc->num_entries + 0.5) );
+        if( !h->param.b_stitchable )
+            h->pps->i_pic_init_qp = SPEC_QP( (int)(total_qp_aq / rc->num_entries + 0.5) );
 
         x264_free( stats_buf );
 
diff --git a/encoder/set.c b/encoder/set.c
index fdedf98..d514aa3 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -430,7 +430,7 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
     pps->b_weighted_pred = param->analyse.i_weighted_pred > 0;
     pps->b_weighted_bipred = param->analyse.b_weighted_bipred ? 2 : 0;
 
-    pps->i_pic_init_qp = param->rc.i_rc_method == X264_RC_ABR ? 26 + QP_BD_OFFSET : SPEC_QP( param->rc.i_qp_constant );
+    pps->i_pic_init_qp = param->rc.i_rc_method == X264_RC_ABR || param->b_stitchable ? 26 + QP_BD_OFFSET : SPEC_QP( param->rc.i_qp_constant );
     pps->i_pic_init_qs = 26 + QP_BD_OFFSET;
 
     pps->i_chroma_qp_index_offset = param->analyse.i_chroma_qp_offset;
diff --git a/x264.c b/x264.c
index df18a1b..bd996b9 100644
--- a/x264.c
+++ b/x264.c
@@ -790,6 +790,8 @@ static void help( x264_param_t *defaults, int longhelp )
     H0( "      --frames <integer>      Maximum number of frames to encode\n" );
     H0( "      --level <string>        Specify level (as defined by Annex A)\n" );
     H1( "      --bluray-compat         Enable compatibility hacks for Blu-ray support\n" );
+    H1( "      --stitchable            Don't optimize headers based on video content\n"
+        "                              Ensures ability to recombine a segmented encode\n" );
     H1( "\n" );
     H1( "  -v, --verbose               Print stats for each frame\n" );
     H1( "      --no-progress           Don't show the progress indicator while encoding\n" );
@@ -1036,6 +1038,7 @@ static struct option long_options[] =
     { "dts-compress",      no_argument, NULL, OPT_DTS_COMPRESSION },
     { "output-csp",  required_argument, NULL, OPT_OUTPUT_CSP },
     { "input-range", required_argument, NULL, OPT_INPUT_RANGE },
+    { "stitchable",        no_argument, NULL, 0 },
     {0, 0, 0, 0}
 };
 
diff --git a/x264.h b/x264.h
index b32db8d..7c3e349 100644
--- a/x264.h
+++ b/x264.h
@@ -41,7 +41,7 @@
 
 #include "x264_config.h"
 
-#define X264_BUILD 133
+#define X264_BUILD 134
 
 /* Application developers planning to link against a shared library version of
  * libx264 from a Microsoft Visual Studio or similar development environment
@@ -474,6 +474,11 @@ typedef struct x264_param_t
 
     int b_fake_interlaced;
 
+    /* Don't optimize header parameters based on video content, e.g. ensure that splitting an input video, compressing
+     * each part, and stitching them back together will result in identical SPS/PPS. This is necessary for stitching
+     * with container formats that don't allow multiple SPS/PPS. */
+    int b_stitchable;
+
     int b_opencl;            /* use OpenCL when available */
     int i_opencl_device;     /* specify count of GPU devices to skip, for CLI users */
     void *opencl_device_id;  /* pass explicit cl_device_id as void*, for API users */



More information about the x264-devel mailing list