OSDN Git Service

Adds a configuration option for whether the COLR atom and h.264 VUI header should...
authorjbrjake <jbrjake@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 19 Oct 2008 23:39:52 +0000 (23:39 +0000)
committerjbrjake <jbrjake@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 19 Oct 2008 23:39:52 +0000 (23:39 +0000)
git-svn-id: svn://localhost/HandBrake/trunk@1851 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.h
libhb/encx264.c
libhb/muxmp4.c
libhb/work.c
test/test.c

index 5c89430..c00268d 100644 (file)
@@ -187,6 +187,7 @@ struct hb_job_s
     int             crf;
     char            *x264opts;
     int             areBframes;
+    int             color_matrix;
 
     /* List of audio settings. */
     hb_list_t     * list_audio;
index 4a831ba..0e3edd0 100644 (file)
@@ -195,8 +195,21 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
 
     /* set up the VUI color model & gamma to match what the COLR atom
      * set in muxmp4.c says. See libhb/muxmp4.c for notes. */
-
-    if ( job->title->height >= 720 )
+    if( job->color_matrix == 1 )
+    {
+        // ITU BT.601 DVD or SD TV content
+        param.vui.i_colorprim = 6;
+        param.vui.i_transfer = 1;
+        param.vui.i_colmatrix = 6;
+    }
+    else if( job->color_matrix == 2 )
+    {
+        // ITU BT.709 HD content
+        param.vui.i_colorprim = 1;
+        param.vui.i_transfer = 1;
+        param.vui.i_colmatrix = 1;
+    }
+    else if ( job->title->width >= 1280 || job->title->width >= 720 )
     {
         // we guess that 720p or above is ITU BT.709 HD content
         param.vui.i_colorprim = 1;
index a6ddedf..dfee48c 100644 (file)
@@ -251,10 +251,21 @@ static int MP4Init( hb_mux_object_t * m )
     // Per the notes at:
     //   http://developer.apple.com/quicktime/icefloe/dispatch019.html#colr
     //   http://forum.doom9.org/showthread.php?t=133982#post1090068
+    // the user can set it from job->color_matrix, otherwise by default
     // we say anything that's likely to be HD content is ITU BT.709 and
     // DVD, SD TV & other content is ITU BT.601.  We look at the title height
     // rather than the job height here to get uncropped input dimensions.
-    if ( job->title->height >= 720 )
+    if( job->color_matrix == 1 )
+    {
+        // ITU BT.601 DVD or SD TV content
+        MP4AddColr(m->file, mux_data->track, 6, 1, 6);
+    }
+    else if( job->color_matrix == 2 )
+    {
+        // ITU BT.709 HD content
+        MP4AddColr(m->file, mux_data->track, 1, 1, 1);        
+    }
+    else if ( job->title->width >= 1280 || job->title->height >= 720 )
     {
         // we guess that 720p or above is ITU BT.709 HD content
         MP4AddColr(m->file, mux_data->track, 1, 1, 1);
index f64738e..6caa153 100644 (file)
@@ -214,6 +214,15 @@ hb_display_job_info( hb_job_t * job )
                 title->width, title->height, job->width, job->height,
                 job->crop[0], job->crop[1], job->crop[2], job->crop[3] );
     }
+    
+    if( job->color_matrix )
+    {
+        hb_log( "   + color space: %s", job->color_matrix == 1 ? "ITU Bt.601 (SD)" : "ITU Bt.709 (HD)");
+    }
+    else
+    {
+        hb_log( "   + color space: %s", ( title->width < 1280 || title->height < 720 ) ? "ITU Bt.601 (SD)" : "ITU Bt.709 (HD)");        
+    }
 
     if ( job->grayscale )
         hb_log( "   + grayscale mode" );
index dc61c57..a92be42 100644 (file)
@@ -91,6 +91,7 @@ static char * preset_name   = 0;
 static int    cfr           = 0;
 static int    mp4_optimize  = 0;
 static int    ipod_atom     = 0;
+static int    color_matrix  = 0;
 
 /* Exit cleanly on Ctrl-C */
 static volatile int die = 0;
@@ -1302,6 +1303,11 @@ static int HandleEvents( hb_handle_t * h )
             {
                 job->crf = 1;
             }
+            
+            if( color_matrix )
+            {
+                job->color_matrix = color_matrix;
+            }
 
             if( x264opts != NULL && *x264opts != '\0' )
             {
@@ -1605,6 +1611,9 @@ static void ShowHelp()
     "          <MOD:PARX:PARY>   Takes as optional arguments what number you want\n"
     "                            the dimensions to divide cleanly by (default 16)\n"
     "                            and the pixel ratio to use (default autodetected)\n"
+    "    -M  --color-matrix      Set the color space signalled by the output\n"
+    "          <601 or 709>      (Bt.601 is mostly for SD content, Bt.709 for HD,\n"
+    "                             default: set by resolution)\n"
 
 
        "\n"
@@ -1761,6 +1770,7 @@ static int ParseOptions( int argc, char ** argv )
             { "preset-list", no_argument,       NULL,    'z' },
 
             { "aname",       required_argument, NULL,    'A' },
+            { "color-matrix",required_argument, NULL,    'M' },
 
             { 0, 0, 0, 0 }
           };
@@ -1769,7 +1779,7 @@ static int ParseOptions( int argc, char ** argv )
         int c;
 
                c = getopt_long( argc, argv,
-                                                "hv::uC:f:4i:Io:t:Lc:m::a:A:6:s:UFN:e:E:2dD:7895gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z",
+                                                "hv::uC:f:4i:Io:t:Lc:m::M:a:A:6:s:UFN:e:E:2dD:7895gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z",
                          long_options, &option_index );
         if( c < 0 )
         {
@@ -2106,7 +2116,12 @@ static int ParseOptions( int argc, char ** argv )
                     anames = strdup( optarg );
                 }
                 break;
-
+            case 'M':
+                if( atoi( optarg ) == 601 )
+                    color_matrix = 1;
+                else if( atoi( optarg ) == 709 )
+                    color_matrix = 2;
+                break;
             default:
                 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
                 return -1;