OSDN Git Service

Merge the 5.1 branch into the trunk.
[handbrake-jp/handbrake-jp-git.git] / test / test.c
index dc66aa6..de44786 100644 (file)
@@ -26,6 +26,7 @@ static int    vcodec      = HB_VCODEC_FFMPEG;
 static int    h264_13     = 0;
 static int    h264_30     = 0;
 static char * audios      = NULL;
+static int    surround    = 0;
 static int    sub         = 0;
 static int    width       = 0;
 static int    height      = 0;
@@ -39,9 +40,14 @@ static int    size        = 0;
 static int    abitrate    = 0;
 static int    mux         = 0;
 static int    acodec      = 0;
+static int    pixelratio  = 0;
 static int    chapter_start = 0;
 static int    chapter_end   = 0;
 static int       crf                   = 0;
+static char      *x264opts             = NULL;
+static char      *x264opts2    = NULL;
+static int       maxHeight             = 0;
+static int       maxWidth              = 0;
 
 /* Exit cleanly on Ctrl-C */
 static volatile int die = 0;
@@ -172,7 +178,9 @@ int main( int argc, char ** argv )
     if( output ) free( output );
     if( format ) free( format );
     if( audios ) free( audios );
-
+       if( x264opts ) free (x264opts );
+       if( x264opts2 ) free (x264opts2 );
+       
     fprintf( stderr, "HandBrake has exited.\n" );
 
     return 0;
@@ -182,7 +190,7 @@ static void ShowCommands()
 {
     fprintf( stderr, "Commands:\n" );
     fprintf( stderr, " [h]elp    Show this message\n" );
-    fprintf( stderr, " [q]uit    Exit HBTest\n" );
+    fprintf( stderr, " [q]uit    Exit HandBrakeCLI\n" );
     fprintf( stderr, " [p]ause   Pause encoding\n" );
     fprintf( stderr, " [r]esume  Resume encoding\n" );
 }
@@ -310,6 +318,7 @@ static int HandleEvents( hb_handle_t * h )
 
             job->deinterlace = deinterlace;
             job->grayscale   = grayscale;
+            job->pixel_ratio = pixelratio;
 
             if( width && height )
             {
@@ -326,7 +335,7 @@ static int HandleEvents( hb_handle_t * h )
                 job->height = height;
                 hb_fix_aspect( job, HB_KEEP_HEIGHT );
             }
-            else
+            else if( !width && !height && !pixelratio )
             {
                 hb_fix_aspect( job, HB_KEEP_WIDTH );
             }
@@ -349,9 +358,9 @@ static int HandleEvents( hb_handle_t * h )
             { 
                 job->h264_level = 13; 
             }
-           if( h264_30 )
-           {
-               job->h264_level = 30;
+               if( h264_30 )
+               {
+                   job->h264_level = 30;
             }
             if( vrate )
             {
@@ -387,6 +396,10 @@ static int HandleEvents( hb_handle_t * h )
                     job->audios[0] = -1;
                 }
             }
+                       if( surround )
+                       {
+                               job->surround = 1;
+                       }
             if( abitrate )
             {
                 job->abitrate = abitrate;
@@ -402,7 +415,7 @@ static int HandleEvents( hb_handle_t * h )
                 fprintf( stderr, "Calculated bitrate: %d kbps\n",
                          job->vbitrate );
             }
-            
+
             if( sub )
             {
                 job->subtitle = sub - 1;
@@ -419,11 +432,26 @@ static int HandleEvents( hb_handle_t * h )
                                job->crf = 1;
                        }
 
+                       if (x264opts != NULL && *x264opts != '\0' )
+                       {
+                               hb_log("Applying the following x264 options: %s", x264opts);
+                               job->x264opts = x264opts;
+                       }
+                       else /*avoids a bus error crash when options aren't specified*/
+                       {
+                               job->x264opts =  NULL;
+                       }
+                       if (maxWidth)
+                               job->maxWidth = maxWidth;
+                       if (maxHeight)
+                               job->maxHeight = maxHeight;
+                               
             if( twoPass )
             {
                 job->pass = 1;
                 hb_add( h, job );
                 job->pass = 2;
+                               job->x264opts = x264opts2;
                 hb_add( h, job );
             }
             else
@@ -506,7 +534,7 @@ static void ShowHelp()
     int i;
     
     fprintf( stderr,
-    "Syntax: HBTest [options] -i <device> -o <file>\n"
+    "Syntax: HandBrakeCLI [options] -i <device> -o <file>\n"
     "\n"
     "    -h, --help              Print help\n"
     "    -u, --update            Check for updates and exit\n"
@@ -525,6 +553,7 @@ static void ShowHelp()
     "                            default: all chapters)\n"
     "    -a, --audio <string>    Select audio channel(s) (\"none\" for no \n"
     "                            audio, default: first one)\n"
+    "    -6, --surround          Export 5.1 surround as 6-channel AAC\n"
     "\n"
     "    -s, --subtitle <number> Select subtitle (default: none)\n"
     "    -e, --encoder <string>  Set video library encoder (ffmpeg,xvid,\n"
@@ -534,6 +563,7 @@ static void ShowHelp()
     "    -2, --two-pass          Use two-pass mode\n"
     "    -d, --deinterlace       Deinterlace video\n"
     "    -g, --grayscale         Grayscale encoding\n"
+    "    -p, --pixelratio        Store pixel aspect ratio in video stream\n"
     "\n"
     "    -r, --rate              Set video framerate (" );
     for( i = 0; i < hb_video_rates_count; i++ )
@@ -558,7 +588,13 @@ static void ShowHelp()
     "    -B, --ab <kb/s>         Set audio bitrate (default: 128)\n"
     "    -w, --width <number>    Set picture width\n"
     "    -l, --height <number>   Set picture height\n"
-    "        --crop <T:B:L:R>    Set cropping values (default: autocrop)\n" );
+    "        --crop <T:B:L:R>    Set cropping values (default: autocrop)\n"
+       "    -Y, --maxHeight <#>     Set maximum height\n"
+       "    -X, --maxWidth <#>      Set maximum width\n"
+       "\n"
+       "    -x, --x264opts <string> Specify advanced x264 options in the\n"
+       "                            same style as mencoder:\n"
+       "                            option1=value1:option2=value2\n" );
 }
 
 /****************************************************************************
@@ -582,6 +618,7 @@ static int ParseOptions( int argc, char ** argv )
             { "title",       required_argument, NULL,    't' },
             { "chapters",    required_argument, NULL,    'c' },
             { "audio",       required_argument, NULL,    'a' },
+            { "surround",    no_argument,       NULL,    '6' },
             { "subtitle",    required_argument, NULL,    's' },
 
             { "encoder",     required_argument, NULL,    'e' },
@@ -589,6 +626,7 @@ static int ParseOptions( int argc, char ** argv )
             { "two-pass",    no_argument,       NULL,    '2' },
             { "deinterlace", no_argument,       NULL,    'd' },
             { "grayscale",   no_argument,       NULL,    'g' },
+            { "pixelratio",  no_argument,       NULL,    'p' },
             { "width",       required_argument, NULL,    'w' },
             { "height",      required_argument, NULL,    'l' },
             { "crop",        required_argument, NULL,    'n' },
@@ -600,6 +638,9 @@ static int ParseOptions( int argc, char ** argv )
             { "rate",        required_argument, NULL,    'r' },
             { "arate",       required_argument, NULL,    'R' },
                        { "crf",                 no_argument,           NULL,    'Q' },
+                       { "x264opts",    required_argument, NULL,    'x' },
+                       { "maxHeight",   required_argument, NULL,        'Y' },
+                       { "maxWidth",    required_argument, NULL,        'X' },
                        
             { 0, 0, 0, 0 }
           };
@@ -608,7 +649,7 @@ static int ParseOptions( int argc, char ** argv )
         int c;
 
         c = getopt_long( argc, argv,
-                         "hvuC:f:i:o:t:c:a:s:e:E:2dgw:l:n:b:q:S:B:r:R:Q",
+                         "hvuC:f:i:o:t:c:a:s:e:E:2dgpw:l:n:b:q:S:B:r:R:Qx:Y:X:",
                          long_options, &option_index );
         if( c < 0 )
         {
@@ -667,6 +708,9 @@ static int ParseOptions( int argc, char ** argv )
             case 'a':
                 audios = strdup( optarg );
                 break;
+            case '6':
+                surround = 1;
+                break;
             case 's':
                 sub = atoi( optarg );
                 break;
@@ -680,6 +724,9 @@ static int ParseOptions( int argc, char ** argv )
             case 'g':
                 grayscale = 1;
                 break;
+            case 'p':
+                pixelratio = 1;
+                break;
             case 'e':
                 if( !strcasecmp( optarg, "ffmpeg" ) )
                 {
@@ -789,7 +836,17 @@ static int ParseOptions( int argc, char ** argv )
                        case 'Q':
                                crf = 1;
                                break;
-
+                       case 'x':
+                               x264opts = strdup( optarg );
+                               x264opts2 = strdup( optarg );
+                           break;
+                       case 'Y':
+                               maxHeight = atoi( optarg );
+                               break;
+                       case 'X':
+                               maxWidth = atoi (optarg );
+                               break;
+                               
             default:
                 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
                 return -1;
@@ -889,6 +946,13 @@ static int CheckOptions( int argc, char ** argv )
                 acodec = HB_ACODEC_VORBIS;
             }
         }
+               
+               if (acodec != HB_ACODEC_FAAC)
+               {
+                       /* only attempt 5.1 export if exporting to AAC */
+                       surround = 0;
+               }
+               
     }
 
     return 0;