]> git.videolan.org Git - x264.git/commitdiff
Add support for level 1b
authorTakashi Hirata <silverfilain@gmail.com>
Mon, 30 Aug 2010 09:13:49 +0000 (18:13 +0900)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Fri, 3 Sep 2010 20:34:31 +0000 (13:34 -0700)
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.

common/common.c
common/set.h
encoder/encoder.c
encoder/set.c

index 47fcaa2690354bb24beafc19a4a243c7ebbf52be..b0bb4e766f8320cd58916fc0bae5946449ba98c5 100644 (file)
@@ -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);
index ee27d7429cfe09aef959abf7a6baca2875e2412f..6625ae470a9a351ad8f57e20df44fb0b51567d45 100644 (file)
@@ -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;
 
index c22b9bfbf910084dec373474caefe2703452d923..e9aa05cd734cf8b855d810aafce1028c5f1e9f93 100644 (file)
@@ -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;
index 2b3bbce47a34b282f144a1bcd876e7ee14c7791c..3dee484dfca1db123b22de5af349e3c4fb799a33 100644 (file)
@@ -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 },