1 /* $Id: test.c,v 1.82 2005/11/19 08:25:54 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
17 static int debug = HB_DEBUG_NONE;
18 static int update = 0;
19 static char * input = NULL;
20 static char * output = NULL;
21 static char * format = NULL;
22 static int titleindex = 1;
23 static int longest_title = 0;
24 static int subtitle_scan = 0;
25 static int subtitle_force = 0;
26 static char * native_language = NULL;
27 static int twoPass = 0;
28 static int deinterlace = 0;
29 static char * deinterlace_opt = 0;
30 static int deblock = 0;
31 static char * deblock_opt = 0;
32 static int denoise = 0;
33 static char * denoise_opt = 0;
34 static int detelecine = 0;
35 static char * detelecine_opt = 0;
36 static int grayscale = 0;
37 static int vcodec = HB_VCODEC_FFMPEG;
38 static int h264_13 = 0;
39 static int h264_30 = 0;
40 static char * audios = NULL;
41 static int audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
44 static int height = 0;
45 static int crop[4] = { -1,-1,-1,-1 };
49 static float vquality = -1.0;
50 static int vbitrate = 0;
52 static int abitrate = 0;
54 static int acodec = 0;
55 static int pixelratio = 0;
56 static int chapter_start = 0;
57 static int chapter_end = 0;
58 static int chapter_markers = 0;
59 static char * marker_file = NULL;
61 static char *x264opts = NULL;
62 static char *x264opts2 = NULL;
63 static int maxHeight = 0;
64 static int maxWidth = 0;
65 static int turbo_opts_enabled = 0;
66 static char * turbo_opts = "ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0";
67 static int largeFileSize = 0;
69 /* Exit cleanly on Ctrl-C */
70 static volatile int die = 0;
71 static void SigHandler( int );
74 static void ShowCommands();
75 static void ShowHelp();
76 static int ParseOptions( int argc, char ** argv );
77 static int CheckOptions( int argc, char ** argv );
78 static int HandleEvents( hb_handle_t * h );
80 int main( int argc, char ** argv )
86 /* Parse command line */
87 if( ParseOptions( argc, argv ) ||
88 CheckOptions( argc, argv ) )
94 h = hb_init( debug, update );
97 fprintf( stderr, "HandBrake %s (%d) - http://handbrake.m0k.org/\n",
98 hb_get_version( h ), hb_get_build( h ) );
100 /* Check for update */
103 if( ( build = hb_check_update( h, &version ) ) > -1 )
105 fprintf( stderr, "You are using an old version of "
106 "HandBrake.\nLatest is %s (build %d).\n", version,
111 fprintf( stderr, "Your version of HandBrake is up to "
119 fprintf( stderr, "%d CPU%s detected\n", hb_get_cpu_count(),
120 hb_get_cpu_count( h ) > 1 ? "s" : "" );
123 fprintf( stderr, "Forcing %d CPU%s\n", cpu,
124 cpu > 1 ? "s" : "" );
125 hb_set_cpu_count( h, cpu );
128 /* Exit ASAP on Ctrl-C */
129 signal( SIGINT, SigHandler );
131 /* Feed libhb with a DVD to scan */
132 fprintf( stderr, "Opening %s...\n", input );
136 * We need to scan for all the titles in order to find the longest
140 hb_scan( h, input, titleindex );
145 #if !defined(SYS_BEOS)
155 FD_SET( STDIN_FILENO, &fds );
156 ret = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
163 read( STDIN_FILENO, &buf[size], 1 ) > 0 )
165 if( buf[size] == '\n' )
172 if( size >= 256 || buf[size] == '\n' )
201 if( input ) free( input );
202 if( output ) free( output );
203 if( format ) free( format );
204 if( audios ) free( audios );
205 if (native_language ) free (native_language );
206 if( x264opts ) free (x264opts );
207 if( x264opts2 ) free (x264opts2 );
209 fprintf( stderr, "HandBrake has exited.\n" );
214 static void ShowCommands()
216 fprintf( stderr, "Commands:\n" );
217 fprintf( stderr, " [h]elp Show this message\n" );
218 fprintf( stderr, " [q]uit Exit HandBrakeCLI\n" );
219 fprintf( stderr, " [p]ause Pause encoding\n" );
220 fprintf( stderr, " [r]esume Resume encoding\n" );
223 static void PrintTitleInfo( hb_title_t * title )
225 hb_chapter_t * chapter;
227 hb_subtitle_t * subtitle;
230 fprintf( stderr, "+ title %d:\n", title->index );
231 fprintf( stderr, " + vts %d, ttn %d, cells %d->%d (%d blocks)\n",
232 title->vts, title->ttn, title->cell_start, title->cell_end,
233 title->block_count );
234 fprintf( stderr, " + duration: %02d:%02d:%02d\n",
235 title->hours, title->minutes, title->seconds );
236 fprintf( stderr, " + size: %dx%d, aspect: %.2f, %.3f fps\n",
237 title->width, title->height,
238 (float) title->aspect / HB_ASPECT_BASE,
239 (float) title->rate / title->rate_base );
240 fprintf( stderr, " + autocrop: %d/%d/%d/%d\n", title->crop[0],
241 title->crop[1], title->crop[2], title->crop[3] );
242 fprintf( stderr, " + chapters:\n" );
243 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
245 chapter = hb_list_item( title->list_chapter, i );
246 fprintf( stderr, " + %d: cells %d->%d, %d blocks, duration "
247 "%02d:%02d:%02d\n", chapter->index,
248 chapter->cell_start, chapter->cell_end,
249 chapter->block_count, chapter->hours, chapter->minutes,
252 fprintf( stderr, " + audio tracks:\n" );
253 for( i = 0; i < hb_list_count( title->list_audio ); i++ )
255 audio = hb_list_item( title->list_audio, i );
256 if( ( audio->codec & HB_ACODEC_AC3 ) || ( audio->codec & HB_ACODEC_DCA) )
258 fprintf( stderr, " + %d, %s, %dHz, %dbps\n", i + 1,
259 audio->lang, audio->rate, audio->bitrate );
263 fprintf( stderr, " + %d, %s\n", i + 1, audio->lang );
266 fprintf( stderr, " + subtitle tracks:\n" );
267 for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
269 subtitle = hb_list_item( title->list_subtitle, i );
270 fprintf( stderr, " + %d, %s (iso639-2: %s)\n", i + 1, subtitle->lang,
275 static int HandleEvents( hb_handle_t * h )
278 hb_get_state( h, &s );
285 #define p s.param.scanning
286 case HB_STATE_SCANNING:
287 /* Show what title is currently being scanned */
288 fprintf( stderr, "Scanning title %d", p.title_cur );
290 fprintf( stderr, " of %d", p.title_count );
291 fprintf( stderr, "...\n" );
295 case HB_STATE_SCANDONE:
301 list = hb_get_titles( h );
303 if( !hb_list_count( list ) )
305 /* No valid title, stop right there */
306 fprintf( stderr, "No title found.\n" );
313 int longest_title_idx=0;
314 int longest_title_pos=-1;
315 int longest_title_time=0;
318 fprintf( stderr, "Searching for longest title...\n" );
320 for( i = 0; i < hb_list_count( list ); i++ )
322 title = hb_list_item( list, i );
323 title_time = (title->hours*60*60 ) + (title->minutes *60) + (title->seconds);
324 fprintf( stderr, " + Title (%d) index %d has length %dsec\n",
325 i, title->index, title_time );
326 if( longest_title_time < title_time )
328 longest_title_time = title_time;
329 longest_title_pos = i;
330 longest_title_idx = title->index;
333 if( longest_title_pos == -1 )
335 fprintf( stderr, "No longest title found.\n" );
339 titleindex = longest_title_idx;
340 fprintf( stderr, "Found longest title, setting title to %d\n",
343 title = hb_list_item( list, longest_title_pos);
345 title = hb_list_item( list, 0 );
350 /* Scan-only mode, print infos and exit */
352 for( i = 0; i < hb_list_count( list ); i++ )
354 title = hb_list_item( list, i );
355 PrintTitleInfo( title );
361 /* Set job settings */
364 PrintTitleInfo( title );
366 if( chapter_start && chapter_end )
368 job->chapter_start = MAX( job->chapter_start,
370 job->chapter_end = MIN( job->chapter_end,
372 job->chapter_end = MAX( job->chapter_start,
376 if ( chapter_markers )
378 job->chapter_markers = chapter_markers;
380 if( marker_file != NULL )
382 hb_csv_file_t * file = hb_open_csv_file( marker_file );
383 hb_csv_cell_t * cell;
387 fprintf( stderr, "Reading chapter markers from file %s\n", marker_file );
391 fprintf( stderr, "Cannot open chapter marker file, using defaults\n" );
395 /* Parse the cells */
396 while( NULL != ( cell = hb_read_next_cell( file ) ) )
398 /* We have a chapter number */
399 if( cell->cell_col == 0 )
401 row = cell->cell_row;
402 chapter = atoi( cell->cell_text );
405 /* We have a chapter name */
406 if( cell->cell_col == 1 && row == cell->cell_row )
408 /* If we have a valid chapter, copy the string an terminate it */
409 if( chapter >= job->chapter_start && chapter <= job->chapter_end )
411 hb_chapter_t * chapter_s;
413 chapter_s = hb_list_item( job->title->list_chapter, chapter - 1);
414 strncpy(chapter_s->title, cell->cell_text, 1023);
415 chapter_s->title[1023] = '\0';
420 hb_dispose_cell( cell );
423 hb_close_csv_file( file );
428 if( crop[0] >= 0 && crop[1] >= 0 &&
429 crop[2] >= 0 && crop[3] >= 0 )
431 memcpy( job->crop, crop, 4 * sizeof( int ) );
434 job->deinterlace = deinterlace;
435 job->grayscale = grayscale;
436 job->pixel_ratio = pixelratio;
438 /* Add selected filters */
439 job->filters = hb_list_init();
442 hb_filter_detelecine.settings = detelecine_opt;
443 hb_list_add( job->filters, &hb_filter_detelecine );
447 hb_filter_deinterlace.settings = deinterlace_opt;
448 hb_list_add( job->filters, &hb_filter_deinterlace );
452 hb_filter_deblock.settings = deblock_opt;
453 hb_list_add( job->filters, &hb_filter_deblock );
457 hb_filter_denoise.settings = denoise_opt;
458 hb_list_add( job->filters, &hb_filter_denoise );
461 if( width && height )
464 job->height = height;
469 hb_fix_aspect( job, HB_KEEP_WIDTH );
473 job->height = height;
474 hb_fix_aspect( job, HB_KEEP_HEIGHT );
476 else if( !width && !height && !pixelratio )
478 hb_fix_aspect( job, HB_KEEP_WIDTH );
481 if( vquality >= 0.0 && vquality <= 1.0 )
483 job->vquality = vquality;
488 job->vquality = -1.0;
489 job->vbitrate = vbitrate;
493 job->vcodec = vcodec;
497 job->h264_level = 13;
501 job->h264_level = 30;
505 job->vrate = 27000000;
506 job->vrate_base = vrate;
515 if( strcasecmp( audios, "none" ) )
521 if( *tmp < '0' || *tmp > '9' )
523 /* Skip non numeric char */
527 job->audio_mixdowns[audio_count] = audio_mixdown;
528 job->audios[audio_count++] =
529 strtol( tmp, &tmp, 0 ) - 1;
531 job->audios[audio_count] = -1;
540 /* default to the first audio track if none has been specified */
542 job->audio_mixdowns[0] = audio_mixdown;
546 job->abitrate = abitrate;
550 job->acodec = acodec;
555 job->vbitrate = hb_calc_bitrate( job, size );
556 fprintf( stderr, "Calculated bitrate: %d kbps\n",
562 job->subtitle = sub - 1;
565 if( native_language )
567 job->native_language = strdup( native_language );
577 job->largeFileSize = 1;
580 job->file = strdup( output );
587 if( x264opts != NULL && *x264opts != '\0' )
589 fprintf( stderr, "Applying the following x264 options: %s\n",
591 job->x264opts = x264opts;
593 else /*avoids a bus error crash when options aren't specified*/
595 job->x264opts = NULL;
598 job->maxWidth = maxWidth;
600 job->maxHeight = maxHeight;
604 job->subtitle_force = subtitle_force;
612 * When subtitle scan is enabled do a fast pre-scan job
613 * which will determine which subtitles to enable, if any.
617 x264opts_tmp = job->x264opts;
619 job->x264opts = NULL;
621 job->subtitle_scan = subtitle_scan;
622 fprintf( stderr, "Subtitle Scan Enabled - enabling "
623 "subtitles if found for foreign language segments\n");
624 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
625 *(job->select_subtitle) = NULL;
628 * Add the pre-scan job
632 job->x264opts = x264opts_tmp;
638 * If subtitle_scan is enabled then only turn it on
639 * for the first pass and then off again for the
642 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
644 job->select_subtitle = NULL;
648 job->subtitle_scan = 0;
651 * If turbo options have been selected then append them
652 * to the x264opts now (size includes one ':' and the '\0')
654 if( turbo_opts_enabled )
656 int size = (x264opts ? strlen(x264opts) : 0) + strlen(turbo_opts) + 2;
659 tmp_x264opts = malloc(size * sizeof(char));
662 snprintf( tmp_x264opts, size, "%s:%s",
663 x264opts, turbo_opts );
667 * No x264opts to modify, but apply the turbo options
668 * anyway as they may be modifying defaults
670 snprintf( tmp_x264opts, size, "%s",
673 x264opts = tmp_x264opts;
675 fprintf( stderr, "Modified x264 options for pass 1 to append turbo options: %s\n",
678 job->x264opts = x264opts;
682 job->select_subtitle = subtitle_tmp;
686 * On the second pass we turn off subtitle scan so that we
687 * can actually encode using any subtitles that were auto
688 * selected in the first pass (using the whacky select-subtitle
689 * attribute of the job).
691 job->subtitle_scan = 0;
693 job->x264opts = x264opts2;
700 * Turn on subtitle scan if requested, note that this option
701 * precludes encoding of any actual subtitles.
704 job->subtitle_scan = 0;
712 #define p s.param.working
713 case HB_STATE_WORKING:
714 fprintf( stderr, "\rEncoding: task %d of %d, %.2f %%",
715 p.job_cur, p.job_count, 100.0 * p.progress );
718 fprintf( stderr, " (%.2f fps, avg %.2f fps, ETA "
719 "%02dh%02dm%02ds)", p.rate_cur, p.rate_avg,
720 p.hours, p.minutes, p.seconds );
725 #define p s.param.muxing
726 case HB_STATE_MUXING:
728 fprintf( stderr, "\rMuxing: %.2f %%", 100.0 * p.progress );
733 #define p s.param.workdone
734 case HB_STATE_WORKDONE:
735 /* Print error if any, then exit */
739 fprintf( stderr, "\nRip done!\n" );
741 case HB_ERROR_CANCELED:
742 fprintf( stderr, "\nRip canceled.\n" );
745 fprintf( stderr, "\nRip failed (error %x).\n",
755 /****************************************************************************
757 ****************************************************************************/
758 static volatile int64_t i_die_date = 0;
759 void SigHandler( int i_signal )
764 i_die_date = hb_get_date();
765 fprintf( stderr, "Signal %d received, terminating - do it "
766 "again in case it gets stuck\n", i_signal );
768 else if( i_die_date + 500 < hb_get_date() )
770 fprintf( stderr, "Dying badly, files might remain in your /tmp\n" );
775 /****************************************************************************
777 ****************************************************************************/
778 static void ShowHelp()
783 "Syntax: HandBrakeCLI [options] -i <device> -o <file>\n"
785 "### General Handbrake Options------------------------------------------------\n\n"
786 " -h, --help Print help\n"
787 " -u, --update Check for updates and exit\n"
788 " -v, --verbose Be verbose\n"
789 " -C, --cpu Set CPU count (default: autodetected)\n"
792 "### Source Options-----------------------------------------------------------\n\n"
793 " -i, --input <string> Set input device\n"
794 " -t, --title <number> Select a title to encode (0 to scan only,\n"
796 " -L, --longest Select the longest title\n"
797 " -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n"
798 " 1 to 3, or \"3\" for chapter 3 only,\n"
799 " default: all chapters)\n"
802 "### Destination Options------------------------------------------------------\n\n"
803 " -o, --output <string> Set output file name\n"
804 " -f, --format <string> Set output format (avi/mp4/ogm/mkv, default:\n"
805 " autodetected from file name)\n"
806 " -4, --large-file Use 64-bit mp4 files that can hold more than\n"
807 " 4 GB. Note: Breaks iPod, @TV, PS3 compatibility.\n"""
810 "### Picture Settings---------------------------------------------------------\n\n"
811 " -w, --width <number> Set picture width\n"
812 " -l, --height <number> Set picture height\n"
813 " --crop <T:B:L:R> Set cropping values (default: autocrop)\n"
814 " -Y, --maxHeight <#> Set maximum height\n"
815 " -X, --maxWidth <#> Set maximum width\n"
816 " -s, --subtitle <number> Select subtitle (default: none)\n"
817 " -U, --subtitle-scan Scan for subtitles on the first pass, and choose\n"
818 " the one that's only used 10 percent of the time\n"
819 " or less. This should locate subtitles for short\n"
820 " foreign language segments. Only works with 2-pass.\n"
821 " -F, --subtitle-forced Only display subtitles from the selected stream if\n"
822 " the subtitle has the forced flag set. May be used in\n"
823 " conjunction with --subtitle-scan to auto-select\n"
824 " a stream if it contains forced subtitles.\n"
825 " -N, --native-language Select subtitles with this language if it does not\n"
826 " <string> match the Audio language. Provide the language's\n"
827 " iso639-2 code (fre, eng, spa, dut, et cetera)\n"
828 " -m, --markers Add chapter markers (mp4 output format only)\n"
831 "### Video Options------------------------------------------------------------\n\n"
832 " -e, --encoder <string> Set video library encoder (ffmpeg,xvid,\n"
833 " x264,x264b13,x264b30 default: ffmpeg)\n"
834 " -q, --quality <float> Set video quality (0.0..1.0)\n"
835 " -Q, --crf Use with -q for CRF instead of CQP\n"
836 " -S, --size <MB> Set target size\n"
837 " -b, --vb <kb/s> Set video bitrate (default: 1000)\n"
838 " -r, --rate Set video framerate (" );
839 for( i = 0; i < hb_video_rates_count; i++ )
841 fprintf( stderr, hb_video_rates[i].string );
842 if( i != hb_video_rates_count - 1 )
843 fprintf( stderr, "/" );
845 fprintf( stderr, ")\n"
847 " -2, --two-pass Use two-pass mode\n"
848 " -d, --deinterlace Deinterlace video with yadif/mcdeint filter\n"
849 " <YM:FD:MM:QP> (default 0:-1:-1:1)\n"
850 " -7, --deblock Deblock video with pp7 filter\n"
851 " <QP:M> (default 0:2)\n"
852 " -8, --denoise Denoise video with hqdn3d filter\n"
853 " <SL:SC:TL:TC> (default 4:3:6:4.5)\n"
854 " -9, --detelecine Detelecine video with pullup filter\n"
855 " <L:R:T:B:SB:MP> (default 1:1:4:4:0:0)\n"
856 " -g, --grayscale Grayscale encoding\n"
857 " -p, --pixelratio Store pixel aspect ratio in video stream\n"
862 "### Audio Options-----------------------------------------------------------\n\n"
863 " -E, --aencoder <string> Set audio encoder (faac/lame/vorbis/ac3, ac3\n"
864 " meaning passthrough, default: guessed)\n"
865 " -B, --ab <kb/s> Set audio bitrate (default: 128)\n"
866 " -a, --audio <string> Select audio channel(s) (\"none\" for no \n"
867 " audio, default: first one)\n"
868 " -6, --mixdown <string> Format for surround sound downmixing\n"
869 " (mono/stereo/dpl1/dpl2/6ch, default: dpl2)\n"
870 " -R, --arate Set audio samplerate (" );
871 for( i = 0; i < hb_audio_rates_count; i++ )
873 fprintf( stderr, hb_audio_rates[i].string );
874 if( i != hb_audio_rates_count - 1 )
875 fprintf( stderr, "/" );
877 fprintf( stderr, " kHz)\n"
884 "### Advanced H264 Options----------------------------------------------------\n\n"
885 " -x, --x264opts <string> Specify advanced x264 options in the\n"
886 " same style as mencoder:\n"
887 " option1=value1:option2=value2\n"
888 " -T, --turbo When using 2-pass use the turbo options\n"
889 " on the first pass to improve speed\n"
890 " (only works with x264, affects PSNR by about 0.05dB,\n"
891 " and increases first pass speed two to four times)\n");
894 /****************************************************************************
896 ****************************************************************************/
897 static int ParseOptions( int argc, char ** argv )
901 static struct option long_options[] =
903 { "help", no_argument, NULL, 'h' },
904 { "update", no_argument, NULL, 'u' },
905 { "verbose", no_argument, NULL, 'v' },
906 { "cpu", required_argument, NULL, 'C' },
908 { "format", required_argument, NULL, 'f' },
909 { "input", required_argument, NULL, 'i' },
910 { "output", required_argument, NULL, 'o' },
911 { "large-file", no_argument, NULL, '4' },
913 { "title", required_argument, NULL, 't' },
914 { "longest", no_argument, NULL, 'L' },
915 { "chapters", required_argument, NULL, 'c' },
916 { "markers", optional_argument, NULL, 'm' },
917 { "audio", required_argument, NULL, 'a' },
918 { "mixdown", required_argument, NULL, '6' },
919 { "subtitle", required_argument, NULL, 's' },
920 { "subtitle-scan", no_argument, NULL, 'U' },
921 { "subtitle-forced", no_argument, NULL, 'F' },
922 { "native-language", required_argument, NULL,'N' },
924 { "encoder", required_argument, NULL, 'e' },
925 { "aencoder", required_argument, NULL, 'E' },
926 { "two-pass", no_argument, NULL, '2' },
927 { "deinterlace", optional_argument, NULL, 'd' },
928 { "deblock", optional_argument, NULL, '7' },
929 { "denoise", optional_argument, NULL, '8' },
930 { "detelecine", optional_argument, NULL, '9' },
931 { "grayscale", no_argument, NULL, 'g' },
932 { "pixelratio", no_argument, NULL, 'p' },
933 { "width", required_argument, NULL, 'w' },
934 { "height", required_argument, NULL, 'l' },
935 { "crop", required_argument, NULL, 'n' },
937 { "vb", required_argument, NULL, 'b' },
938 { "quality", required_argument, NULL, 'q' },
939 { "size", required_argument, NULL, 'S' },
940 { "ab", required_argument, NULL, 'B' },
941 { "rate", required_argument, NULL, 'r' },
942 { "arate", required_argument, NULL, 'R' },
943 { "crf", no_argument, NULL, 'Q' },
944 { "x264opts", required_argument, NULL, 'x' },
945 { "turbo", no_argument, NULL, 'T' },
947 { "maxHeight", required_argument, NULL, 'Y' },
948 { "maxWidth", required_argument, NULL, 'X' },
953 int option_index = 0;
956 c = getopt_long( argc, argv,
957 "hvuC:f:4i:o:t:Lc:ma:6:s:UFN:e:E:2d789gpw:l:n:b:q:S:B:r:R:Qx:TY:X:",
958 long_options, &option_index );
973 debug = HB_DEBUG_ALL;
976 cpu = atoi( optarg );
980 format = strdup( optarg );
983 input = strdup( optarg );
986 output = strdup( optarg );
992 titleindex = atoi( optarg );
1000 if( sscanf( optarg, "%d-%d", &start, &end ) == 2 )
1002 chapter_start = start;
1005 else if( sscanf( optarg, "%d", &start ) == 1 )
1007 chapter_start = start;
1008 chapter_end = chapter_start;
1012 fprintf( stderr, "chapters: invalid syntax (%s)\n",
1019 if( optarg != NULL )
1021 marker_file = strdup( optarg );
1023 chapter_markers = 1;
1026 audios = strdup( optarg );
1029 if( !strcasecmp( optarg, "mono" ) )
1031 audio_mixdown = HB_AMIXDOWN_MONO;
1033 else if( !strcasecmp( optarg, "stereo" ) )
1035 audio_mixdown = HB_AMIXDOWN_STEREO;
1037 else if( !strcasecmp( optarg, "dpl1" ) )
1039 audio_mixdown = HB_AMIXDOWN_DOLBY;
1041 else if( !strcasecmp( optarg, "dpl2" ) )
1043 audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
1045 else if( !strcasecmp( optarg, "6ch" ) )
1047 audio_mixdown = HB_AMIXDOWN_6CH;
1051 sub = atoi( optarg );
1060 native_language = strdup( optarg );
1066 if( optarg != NULL )
1068 deinterlace_opt = strdup( optarg );
1073 if( optarg != NULL )
1075 deblock_opt = strdup( optarg );
1080 if( optarg != NULL )
1082 denoise_opt = strdup( optarg );
1087 if( optarg != NULL )
1089 detelecine_opt = strdup( optarg );
1100 if( !strcasecmp( optarg, "ffmpeg" ) )
1102 vcodec = HB_VCODEC_FFMPEG;
1104 else if( !strcasecmp( optarg, "xvid" ) )
1106 vcodec = HB_VCODEC_XVID;
1108 else if( !strcasecmp( optarg, "x264" ) )
1110 vcodec = HB_VCODEC_X264;
1112 else if( !strcasecmp( optarg, "x264b13" ) )
1114 vcodec = HB_VCODEC_X264;
1117 else if( !strcasecmp( optarg, "x264b30" ) )
1119 vcodec = HB_VCODEC_X264;
1124 fprintf( stderr, "invalid codec (%s)\n", optarg );
1129 if( !strcasecmp( optarg, "ac3" ) )
1131 acodec = HB_ACODEC_AC3;
1133 else if( !strcasecmp( optarg, "lame" ) )
1135 acodec = HB_ACODEC_LAME;
1137 else if( !strcasecmp( optarg, "faac" ) )
1139 acodec = HB_ACODEC_FAAC;
1141 else if( !strcasecmp( optarg, "vorbis") )
1143 acodec = HB_ACODEC_VORBIS;
1147 width = atoi( optarg );
1150 height = atoi( optarg );
1155 char * tmp = optarg;
1156 for( i = 0; i < 4; i++ )
1160 crop[i] = strtol( tmp, &tmp, 0 );
1169 for( i = 0; i < hb_video_rates_count; i++ )
1171 if( !strcmp( optarg, hb_video_rates[i].string ) )
1173 vrate = hb_video_rates[i].rate;
1179 fprintf( stderr, "invalid framerate %s\n", optarg );
1187 for( i = 0; i < hb_audio_rates_count; i++ )
1189 if( !strcmp( optarg, hb_audio_rates[i].string ) )
1191 arate = hb_audio_rates[i].rate;
1197 fprintf( stderr, "invalid framerate %s\n", optarg );
1202 vbitrate = atoi( optarg );
1205 vquality = atof( optarg );
1208 size = atoi( optarg );
1211 abitrate = atoi( optarg );
1217 x264opts = strdup( optarg );
1218 x264opts2 = strdup( optarg );
1221 turbo_opts_enabled = 1;
1224 maxHeight = atoi( optarg );
1227 maxWidth = atoi (optarg );
1231 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
1239 static int CheckOptions( int argc, char ** argv )
1246 if( input == NULL || *input == '\0' )
1248 fprintf( stderr, "Missing input device. Run %s --help for "
1249 "syntax.\n", argv[0] );
1254 if( titleindex > 0 )
1256 if( output == NULL || *output == '\0' )
1258 fprintf( stderr, "Missing output file name. Run %s --help "
1259 "for syntax.\n", argv[0] );
1265 char * p = strrchr( output, '.' );
1268 if( p && !strcasecmp( p, ".avi" ) )
1272 else if( p && ( !strcasecmp( p, ".mp4" ) ||
1273 !strcasecmp( p, ".m4v" ) ) )
1280 else if( p && ( !strcasecmp( p, ".ogm" ) ||
1281 !strcasecmp( p, ".ogg" ) ) )
1285 else if( p && !strcasecmp(p, ".mkv" ) )
1291 fprintf( stderr, "Output format couldn't be guessed "
1292 "from file name, using default.\n" );
1296 else if( !strcasecmp( format, "avi" ) )
1300 else if( !strcasecmp( format, "mp4" ) )
1307 else if( !strcasecmp( format, "ogm" ) ||
1308 !strcasecmp( format, "ogg" ) )
1312 else if( !strcasecmp( format, "mkv" ) )
1318 fprintf( stderr, "Invalid output format (%s). Possible "
1319 "choices are avi, mp4, m4v, ogm, ogg and mkv\n.", format );
1325 if( mux == HB_MUX_MP4 || mux == HB_MUX_IPOD )
1327 acodec = HB_ACODEC_FAAC;
1329 else if( mux == HB_MUX_AVI )
1331 acodec = HB_ACODEC_LAME;
1333 else if( mux == HB_MUX_OGM )
1335 acodec = HB_ACODEC_VORBIS;
1337 else if( mux == HB_MUX_MKV )
1339 acodec = HB_ACODEC_AC3;