[x264-devel] [PATCH] Add an option for forcing POC type 0

Martin Storsjo martin at martin.st
Sat Sep 21 00:17:34 CEST 2013


Some Android phones have problems switching from one video variant
to another in HLS (http live streaming) streams, unless the stream
uses POC type 0. (On some devices, the symptom is that the video
freezes permanently, others freeze for one segment duration and
manage to reinitialize after that.)
---
 common/common.c   |    4 ++++
 encoder/encoder.c |    1 +
 encoder/set.c     |    3 ++-
 x264.c            |    3 +++
 x264.h            |    1 +
 5 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/common/common.c b/common/common.c
index c736c95..bebcaf0 100644
--- a/common/common.c
+++ b/common/common.c
@@ -88,6 +88,7 @@ void x264_param_default( x264_param_t *param )
     param->i_bframe_pyramid = X264_B_PYRAMID_NORMAL;
     param->b_interlaced = 0;
     param->b_constrained_intra = 0;
+    param->b_force_poc_type_0 = 0;
 
     param->b_deblocking_filter = 1;
     param->i_deblocking_filter_alphac0 = 0;
@@ -808,6 +809,8 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
     }
     OPT("constrained-intra")
         p->b_constrained_intra = atobool(value);
+    OPT("force-poc-type-0")
+        p->b_force_poc_type_0 = atobool(value);
     OPT("cqm")
     {
         if( strstr( value, "flat" ) )
@@ -1359,6 +1362,7 @@ char *x264_param2string( x264_param_t *p, int b_res )
         s += sprintf( s, " stitchable=%d", p->b_stitchable );
 
     s += sprintf( s, " constrained_intra=%d", p->b_constrained_intra );
+    s += sprintf( s, " force_poc_type_0=%d", p->b_force_poc_type_0 );
 
     s += sprintf( s, " bframes=%d", p->i_bframe );
     if( p->i_bframe )
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 78ad56a..2f567af 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1226,6 +1226,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
     BOOLIFY( b_full_recon );
     BOOLIFY( b_opencl );
     BOOLIFY( b_avcintra_compat );
+    BOOLIFY( b_force_poc_type_0 );
     BOOLIFY( analyse.b_transform_8x8 );
     BOOLIFY( analyse.b_weighted_bipred );
     BOOLIFY( analyse.b_chroma_me );
diff --git a/encoder/set.c b/encoder/set.c
index bf83a0d..f1d6057 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -165,7 +165,8 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     while( (1 << sps->i_log2_max_frame_num) <= max_frame_num )
         sps->i_log2_max_frame_num++;
 
-    sps->i_poc_type = param->i_bframe || param->b_interlaced ? 0 : 2;
+    sps->i_poc_type = param->i_bframe || param->b_interlaced ||
+                      param->b_force_poc_type_0 ? 0 : 2;
     if( sps->i_poc_type == 0 )
     {
         int max_delta_poc = (param->i_bframe + 2) * (!!param->i_bframe_pyramid + 1) * 2;
diff --git a/x264.c b/x264.c
index 67fa26b..d75ea7e 100644
--- a/x264.c
+++ b/x264.c
@@ -693,6 +693,8 @@ static void help( x264_param_t *defaults, int longhelp )
     H0( "      --tff                   Enable interlaced mode (top field first)\n" );
     H0( "      --bff                   Enable interlaced mode (bottom field first)\n" );
     H2( "      --constrained-intra     Enable constrained intra prediction.\n" );
+    H2( "      --force-poc-type-0      Force using POC type 0 even if it wouldn't\n"
+        "                              strictly be necessary\n" );
     H0( "      --pulldown <string>     Use soft pulldown to change frame rate\n"
         "                                  - none, 22, 32, 64, double, triple, euro (requires cfr input)\n" );
     H2( "      --fake-interlaced       Flag stream as interlaced but encode progressive.\n"
@@ -1000,6 +1002,7 @@ static struct option long_options[] =
     { "bff",               no_argument, NULL, OPT_INTERLACED },
     { "no-interlaced",     no_argument, NULL, OPT_INTERLACED },
     { "constrained-intra", no_argument, NULL, 0 },
+    { "force-poc-type-0",  no_argument, NULL, 0 },
     { "cabac",             no_argument, NULL, 0 },
     { "no-cabac",          no_argument, NULL, 0 },
     { "qp",          required_argument, NULL, 'q' },
diff --git a/x264.h b/x264.h
index 69dce07..0002942 100644
--- a/x264.h
+++ b/x264.h
@@ -332,6 +332,7 @@ typedef struct x264_param_t
 
     int         b_interlaced;
     int         b_constrained_intra;
+    int         b_force_poc_type_0;
 
     int         i_cqm_preset;
     char        *psz_cqm_file;      /* filename (in UTF-8) of CQM file, JM format */
-- 
1.7.9.4



More information about the x264-devel mailing list