[x264-devel] commit: Add support for level 1b (Takashi Hirata )

git at videolan.org git at videolan.org
Sat Sep 4 01:24:51 CEST 2010


x264 | branch: master | Takashi Hirata <silverfilain at gmail.com> | Mon Aug 30 18:13:49 2010 +0900| [c27666276eb4d63b0c9ee2b9a375feabc27c8f4e] | committer: Jason Garrett-Glaser 

Add support for level 1b
This level is a stupid hack in the H.264 spec, so it's a stupid hack in x264 too.
Since level is an integer, calling applications need to set level_idc=9 to use it.
String-based option handling will accept "1b" just fine though, so CLI users don't have to worry.

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

 common/common.c   |    4 +++-
 common/set.h      |    1 +
 encoder/encoder.c |   12 ++++++++----
 encoder/set.c     |   17 ++++++++++++++---
 4 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/common/common.c b/common/common.c
index 47fcaa2..b0bb4e7 100644
--- a/common/common.c
+++ b/common/common.c
@@ -603,7 +603,9 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->b_deterministic = atobool(value);
     OPT2("level", "level-idc")
     {
-        if( atof(value) < 6 )
+        if( !strcmp(value, "1b") )
+            p->i_level_idc = 9;
+        else if( atof(value) < 6 )
             p->i_level_idc = (int)(10*atof(value)+.5);
         else
             p->i_level_idc = atoi(value);
diff --git a/common/set.h b/common/set.h
index ee27d74..6625ae4 100644
--- a/common/set.h
+++ b/common/set.h
@@ -59,6 +59,7 @@ typedef struct
     int b_constraint_set0;
     int b_constraint_set1;
     int b_constraint_set2;
+    int b_constraint_set3;
 
     int i_log2_max_frame_num;
 
diff --git a/encoder/encoder.c b/encoder/encoder.c
index c22b9bf..e9aa05c 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1157,16 +1157,20 @@ x264_t *x264_encoder_open( x264_param_t *param )
                           h->sps->i_profile_idc == PROFILE_HIGH ? "High" :
                           h->sps->i_profile_idc == PROFILE_HIGH10 ? "High 10" :
                           "High 4:4:4 Predictive";
+    char level[4];
+    snprintf( level, sizeof(level), "%d.%d", h->sps->i_level_idc/10, h->sps->i_level_idc%10 );
+    if( h->sps->i_level_idc == 9 || ( h->sps->i_level_idc == 11 && h->sps->b_constraint_set3 ) )
+        strcpy( level, "1b" );
 
     if( h->sps->i_profile_idc < PROFILE_HIGH10 )
     {
-        x264_log( h, X264_LOG_INFO, "profile %s, level %d.%d\n",
-            profile, h->sps->i_level_idc/10, h->sps->i_level_idc%10 );
+        x264_log( h, X264_LOG_INFO, "profile %s, level %s\n",
+            profile, level );
     }
     else
     {
-        x264_log( h, X264_LOG_INFO, "profile %s, level %d.%d, bit depth %d\n",
-            profile, h->sps->i_level_idc/10, h->sps->i_level_idc%10, BIT_DEPTH );
+        x264_log( h, X264_LOG_INFO, "profile %s, level %s, bit depth %d\n",
+            profile, level, BIT_DEPTH );
     }
 
     return h;
diff --git a/encoder/set.c b/encoder/set.c
index 2b3bbce..3dee484 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -112,7 +112,6 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
         sps->i_profile_idc  = PROFILE_MAIN;
     else
         sps->i_profile_idc  = PROFILE_BASELINE;
-    sps->i_level_idc = param->i_level_idc;
 
     sps->b_constraint_set0  = sps->i_profile_idc == PROFILE_BASELINE;
     /* x264 doesn't support the features that are in Baseline and not in Main,
@@ -121,6 +120,17 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     /* Never set constraint_set2, it is not necessary and not used in real world. */
     sps->b_constraint_set2  = 0;
 
+    if( param->i_level_idc == 9 && ( sps->i_profile_idc >= PROFILE_BASELINE && sps->i_profile_idc <= PROFILE_EXTENDED ) )
+    {
+        sps->b_constraint_set3 = 1; /* level 1b with Baseline, Main or Extended profile is signalled via constraint_set3 */
+        sps->i_level_idc      = 11;
+    }
+    else
+    {
+        sps->b_constraint_set3 = 0;
+        sps->i_level_idc = param->i_level_idc;
+    }
+
     sps->vui.i_num_reorder_frames = param->i_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0;
     /* extra slot with pyramid so that we don't have to override the
      * order of forgetting old pictures */
@@ -252,8 +262,9 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )
     bs_write( s, 1, sps->b_constraint_set0 );
     bs_write( s, 1, sps->b_constraint_set1 );
     bs_write( s, 1, sps->b_constraint_set2 );
+    bs_write( s, 1, sps->b_constraint_set3 );
 
-    bs_write( s, 5, 0 );    /* reserved */
+    bs_write( s, 4, 0 );    /* reserved */
 
     bs_write( s, 8, sps->i_level_idc );
 
@@ -640,7 +651,7 @@ void x264_filler_write( x264_t *h, bs_t *s, int filler )
 const x264_level_t x264_levels[] =
 {
     { 10,   1485,    99,   152064,     64,    175,  64, 64,  0, 2, 0, 0, 1 },
-//  {"1b",  1485,    99,   152064,    128,    350,  64, 64,  0, 2, 0, 0, 1 },
+    {  9,   1485,    99,   152064,    128,    350,  64, 64,  0, 2, 0, 0, 1 }, /* "1b" */
     { 11,   3000,   396,   345600,    192,    500, 128, 64,  0, 2, 0, 0, 1 },
     { 12,   6000,   396,   912384,    384,   1000, 128, 64,  0, 2, 0, 0, 1 },
     { 13,  11880,   396,   912384,    768,   2000, 128, 64,  0, 2, 0, 0, 1 },



More information about the x264-devel mailing list