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 /****************************************************************************
83 * When using the CLI just display using hb_log as we always did in the past
84 * make sure that we prefix with a nice ERROR message to catch peoples eyes.
85 ****************************************************************************/
86 static void hb_cli_error_handler ( const char *errmsg )
88 fprintf( stderr, "ERROR: %s", errmsg );
91 int main( int argc, char ** argv )
97 /* Parse command line */
98 if( ParseOptions( argc, argv ) ||
99 CheckOptions( argc, argv ) )
104 /* Register our error handler */
105 hb_register_error_handler(&hb_cli_error_handler);
108 h = hb_init( debug, update );
111 fprintf( stderr, "HandBrake %s (%d) - http://handbrake.m0k.org/\n",
112 hb_get_version( h ), hb_get_build( h ) );
114 /* Check for update */
117 if( ( build = hb_check_update( h, &version ) ) > -1 )
119 fprintf( stderr, "You are using an old version of "
120 "HandBrake.\nLatest is %s (build %d).\n", version,
125 fprintf( stderr, "Your version of HandBrake is up to "
133 fprintf( stderr, "%d CPU%s detected\n", hb_get_cpu_count(),
134 hb_get_cpu_count( h ) > 1 ? "s" : "" );
137 fprintf( stderr, "Forcing %d CPU%s\n", cpu,
138 cpu > 1 ? "s" : "" );
139 hb_set_cpu_count( h, cpu );
142 /* Exit ASAP on Ctrl-C */
143 signal( SIGINT, SigHandler );
145 /* Feed libhb with a DVD to scan */
146 fprintf( stderr, "Opening %s...\n", input );
150 * We need to scan for all the titles in order to find the longest
154 hb_scan( h, input, titleindex );
159 #if !defined(SYS_BEOS)
169 FD_SET( STDIN_FILENO, &fds );
170 ret = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
177 read( STDIN_FILENO, &buf[size], 1 ) > 0 )
179 if( buf[size] == '\n' )
186 if( size >= 256 || buf[size] == '\n' )
215 if( input ) free( input );
216 if( output ) free( output );
217 if( format ) free( format );
218 if( audios ) free( audios );
219 if (native_language ) free (native_language );
220 if( x264opts ) free (x264opts );
221 if( x264opts2 ) free (x264opts2 );
223 fprintf( stderr, "HandBrake has exited.\n" );
228 static void ShowCommands()
230 fprintf( stderr, "Commands:\n" );
231 fprintf( stderr, " [h]elp Show this message\n" );
232 fprintf( stderr, " [q]uit Exit HandBrakeCLI\n" );
233 fprintf( stderr, " [p]ause Pause encoding\n" );
234 fprintf( stderr, " [r]esume Resume encoding\n" );
237 static void PrintTitleInfo( hb_title_t * title )
239 hb_chapter_t * chapter;
241 hb_subtitle_t * subtitle;
244 fprintf( stderr, "+ title %d:\n", title->index );
245 fprintf( stderr, " + vts %d, ttn %d, cells %d->%d (%d blocks)\n",
246 title->vts, title->ttn, title->cell_start, title->cell_end,
247 title->block_count );
248 fprintf( stderr, " + duration: %02d:%02d:%02d\n",
249 title->hours, title->minutes, title->seconds );
250 fprintf( stderr, " + size: %dx%d, aspect: %.2f, %.3f fps\n",
251 title->width, title->height,
252 (float) title->aspect / HB_ASPECT_BASE,
253 (float) title->rate / title->rate_base );
254 fprintf( stderr, " + autocrop: %d/%d/%d/%d\n", title->crop[0],
255 title->crop[1], title->crop[2], title->crop[3] );
256 fprintf( stderr, " + chapters:\n" );
257 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
259 chapter = hb_list_item( title->list_chapter, i );
260 fprintf( stderr, " + %d: cells %d->%d, %d blocks, duration "
261 "%02d:%02d:%02d\n", chapter->index,
262 chapter->cell_start, chapter->cell_end,
263 chapter->block_count, chapter->hours, chapter->minutes,
266 fprintf( stderr, " + audio tracks:\n" );
267 for( i = 0; i < hb_list_count( title->list_audio ); i++ )
269 audio = hb_list_item( title->list_audio, i );
270 if( ( audio->codec & HB_ACODEC_AC3 ) || ( audio->codec & HB_ACODEC_DCA) )
272 fprintf( stderr, " + %d, %s, %dHz, %dbps\n", i + 1,
273 audio->lang, audio->rate, audio->bitrate );
277 fprintf( stderr, " + %d, %s\n", i + 1, audio->lang );
280 fprintf( stderr, " + subtitle tracks:\n" );
281 for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
283 subtitle = hb_list_item( title->list_subtitle, i );
284 fprintf( stderr, " + %d, %s (iso639-2: %s)\n", i + 1, subtitle->lang,
289 static int HandleEvents( hb_handle_t * h )
292 hb_get_state( h, &s );
299 #define p s.param.scanning
300 case HB_STATE_SCANNING:
301 /* Show what title is currently being scanned */
302 fprintf( stderr, "Scanning title %d", p.title_cur );
304 fprintf( stderr, " of %d", p.title_count );
305 fprintf( stderr, "...\n" );
309 case HB_STATE_SCANDONE:
315 list = hb_get_titles( h );
317 if( !hb_list_count( list ) )
319 /* No valid title, stop right there */
320 fprintf( stderr, "No title found.\n" );
327 int longest_title_idx=0;
328 int longest_title_pos=-1;
329 int longest_title_time=0;
332 fprintf( stderr, "Searching for longest title...\n" );
334 for( i = 0; i < hb_list_count( list ); i++ )
336 title = hb_list_item( list, i );
337 title_time = (title->hours*60*60 ) + (title->minutes *60) + (title->seconds);
338 fprintf( stderr, " + Title (%d) index %d has length %dsec\n",
339 i, title->index, title_time );
340 if( longest_title_time < title_time )
342 longest_title_time = title_time;
343 longest_title_pos = i;
344 longest_title_idx = title->index;
347 if( longest_title_pos == -1 )
349 fprintf( stderr, "No longest title found.\n" );
353 titleindex = longest_title_idx;
354 fprintf( stderr, "Found longest title, setting title to %d\n",
357 title = hb_list_item( list, longest_title_pos);
359 title = hb_list_item( list, 0 );
364 /* Scan-only mode, print infos and exit */
366 for( i = 0; i < hb_list_count( list ); i++ )
368 title = hb_list_item( list, i );
369 PrintTitleInfo( title );
375 /* Set job settings */
378 PrintTitleInfo( title );
380 if( chapter_start && chapter_end )
382 job->chapter_start = MAX( job->chapter_start,
384 job->chapter_end = MIN( job->chapter_end,
386 job->chapter_end = MAX( job->chapter_start,
390 if ( chapter_markers )
392 job->chapter_markers = chapter_markers;
394 if( marker_file != NULL )
396 hb_csv_file_t * file = hb_open_csv_file( marker_file );
397 hb_csv_cell_t * cell;
401 fprintf( stderr, "Reading chapter markers from file %s\n", marker_file );
405 fprintf( stderr, "Cannot open chapter marker file, using defaults\n" );
409 /* Parse the cells */
410 while( NULL != ( cell = hb_read_next_cell( file ) ) )
412 /* We have a chapter number */
413 if( cell->cell_col == 0 )
415 row = cell->cell_row;
416 chapter = atoi( cell->cell_text );
419 /* We have a chapter name */
420 if( cell->cell_col == 1 && row == cell->cell_row )
422 /* If we have a valid chapter, copy the string an terminate it */
423 if( chapter >= job->chapter_start && chapter <= job->chapter_end )
425 hb_chapter_t * chapter_s;
427 chapter_s = hb_list_item( job->title->list_chapter, chapter - 1);
428 strncpy(chapter_s->title, cell->cell_text, 1023);
429 chapter_s->title[1023] = '\0';
434 hb_dispose_cell( cell );
437 hb_close_csv_file( file );
442 if( crop[0] >= 0 && crop[1] >= 0 &&
443 crop[2] >= 0 && crop[3] >= 0 )
445 memcpy( job->crop, crop, 4 * sizeof( int ) );
448 job->deinterlace = deinterlace;
449 job->grayscale = grayscale;
450 job->pixel_ratio = pixelratio;
452 /* Add selected filters */
453 job->filters = hb_list_init();
456 hb_filter_detelecine.settings = detelecine_opt;
457 hb_list_add( job->filters, &hb_filter_detelecine );
461 hb_filter_deinterlace.settings = deinterlace_opt;
462 hb_list_add( job->filters, &hb_filter_deinterlace );
466 hb_filter_deblock.settings = deblock_opt;
467 hb_list_add( job->filters, &hb_filter_deblock );
471 hb_filter_denoise.settings = denoise_opt;
472 hb_list_add( job->filters, &hb_filter_denoise );
475 if( width && height )
478 job->height = height;
483 hb_fix_aspect( job, HB_KEEP_WIDTH );
487 job->height = height;
488 hb_fix_aspect( job, HB_KEEP_HEIGHT );
490 else if( !width && !height && !pixelratio )
492 hb_fix_aspect( job, HB_KEEP_WIDTH );
495 if( vquality >= 0.0 && vquality <= 1.0 )
497 job->vquality = vquality;
502 job->vquality = -1.0;
503 job->vbitrate = vbitrate;
507 job->vcodec = vcodec;
511 job->h264_level = 13;
515 job->h264_level = 30;
519 job->vrate = 27000000;
520 job->vrate_base = vrate;
529 if( strcasecmp( audios, "none" ) )
535 if( *tmp < '0' || *tmp > '9' )
537 /* Skip non numeric char */
541 job->audio_mixdowns[audio_count] = audio_mixdown;
542 job->audios[audio_count++] =
543 strtol( tmp, &tmp, 0 ) - 1;
545 job->audios[audio_count] = -1;
554 /* default to the first audio track if none has been specified */
556 job->audio_mixdowns[0] = audio_mixdown;
560 job->abitrate = abitrate;
564 job->acodec = acodec;
569 job->vbitrate = hb_calc_bitrate( job, size );
570 fprintf( stderr, "Calculated bitrate: %d kbps\n",
576 job->subtitle = sub - 1;
579 if( native_language )
581 job->native_language = strdup( native_language );
591 job->largeFileSize = 1;
594 job->file = strdup( output );
601 if( x264opts != NULL && *x264opts != '\0' )
603 fprintf( stderr, "Applying the following x264 options: %s\n",
605 job->x264opts = x264opts;
607 else /*avoids a bus error crash when options aren't specified*/
609 job->x264opts = NULL;
612 job->maxWidth = maxWidth;
614 job->maxHeight = maxHeight;
618 job->subtitle_force = subtitle_force;
626 * When subtitle scan is enabled do a fast pre-scan job
627 * which will determine which subtitles to enable, if any.
631 x264opts_tmp = job->x264opts;
633 job->x264opts = NULL;
635 job->indepth_scan = subtitle_scan;
636 fprintf( stderr, "Subtitle Scan Enabled - enabling "
637 "subtitles if found for foreign language segments\n");
638 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
639 *(job->select_subtitle) = NULL;
642 * Add the pre-scan job
646 job->x264opts = x264opts_tmp;
652 * If subtitle_scan is enabled then only turn it on
653 * for the first pass and then off again for the
656 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
658 job->select_subtitle = NULL;
662 job->indepth_scan = 0;
665 * If turbo options have been selected then append them
666 * to the x264opts now (size includes one ':' and the '\0')
668 if( turbo_opts_enabled )
670 int size = (x264opts ? strlen(x264opts) : 0) + strlen(turbo_opts) + 2;
673 tmp_x264opts = malloc(size * sizeof(char));
676 snprintf( tmp_x264opts, size, "%s:%s",
677 x264opts, turbo_opts );
681 * No x264opts to modify, but apply the turbo options
682 * anyway as they may be modifying defaults
684 snprintf( tmp_x264opts, size, "%s",
687 x264opts = tmp_x264opts;
689 fprintf( stderr, "Modified x264 options for pass 1 to append turbo options: %s\n",
692 job->x264opts = x264opts;
696 job->select_subtitle = subtitle_tmp;
700 * On the second pass we turn off subtitle scan so that we
701 * can actually encode using any subtitles that were auto
702 * selected in the first pass (using the whacky select-subtitle
703 * attribute of the job).
705 job->indepth_scan = 0;
707 job->x264opts = x264opts2;
714 * Turn on subtitle scan if requested, note that this option
715 * precludes encoding of any actual subtitles.
718 job->indepth_scan = 0;
726 #define p s.param.working
727 case HB_STATE_WORKING:
728 fprintf( stderr, "\rEncoding: task %d of %d, %.2f %%",
729 p.job_cur, p.job_count, 100.0 * p.progress );
732 fprintf( stderr, " (%.2f fps, avg %.2f fps, ETA "
733 "%02dh%02dm%02ds)", p.rate_cur, p.rate_avg,
734 p.hours, p.minutes, p.seconds );
739 #define p s.param.muxing
740 case HB_STATE_MUXING:
742 fprintf( stderr, "\rMuxing: %.2f %%", 100.0 * p.progress );
747 #define p s.param.workdone
748 case HB_STATE_WORKDONE:
749 /* Print error if any, then exit */
753 fprintf( stderr, "\nRip done!\n" );
755 case HB_ERROR_CANCELED:
756 fprintf( stderr, "\nRip canceled.\n" );
759 fprintf( stderr, "\nRip failed (error %x).\n",
769 /****************************************************************************
771 ****************************************************************************/
772 static volatile int64_t i_die_date = 0;
773 void SigHandler( int i_signal )
778 i_die_date = hb_get_date();
779 fprintf( stderr, "Signal %d received, terminating - do it "
780 "again in case it gets stuck\n", i_signal );
782 else if( i_die_date + 500 < hb_get_date() )
784 fprintf( stderr, "Dying badly, files might remain in your /tmp\n" );
789 /****************************************************************************
791 ****************************************************************************/
792 static void ShowHelp()
797 "Syntax: HandBrakeCLI [options] -i <device> -o <file>\n"
799 "### General Handbrake Options------------------------------------------------\n\n"
800 " -h, --help Print help\n"
801 " -u, --update Check for updates and exit\n"
802 " -v, --verbose Be verbose\n"
803 " -C, --cpu Set CPU count (default: autodetected)\n"
806 "### Source Options-----------------------------------------------------------\n\n"
807 " -i, --input <string> Set input device\n"
808 " -t, --title <number> Select a title to encode (0 to scan only,\n"
810 " -L, --longest Select the longest title\n"
811 " -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n"
812 " 1 to 3, or \"3\" for chapter 3 only,\n"
813 " default: all chapters)\n"
816 "### Destination Options------------------------------------------------------\n\n"
817 " -o, --output <string> Set output file name\n"
818 " -f, --format <string> Set output format (avi/mp4/ogm/mkv, default:\n"
819 " autodetected from file name)\n"
820 " -4, --large-file Use 64-bit mp4 files that can hold more than\n"
821 " 4 GB. Note: Breaks iPod, @TV, PS3 compatibility.\n"""
824 "### Picture Settings---------------------------------------------------------\n\n"
825 " -w, --width <number> Set picture width\n"
826 " -l, --height <number> Set picture height\n"
827 " --crop <T:B:L:R> Set cropping values (default: autocrop)\n"
828 " -Y, --maxHeight <#> Set maximum height\n"
829 " -X, --maxWidth <#> Set maximum width\n"
830 " -s, --subtitle <number> Select subtitle (default: none)\n"
831 " -U, --subtitle-scan Scan for subtitles in an extra first pass, and choose\n"
832 " the one that's only used 10 percent of the time\n"
833 " or less. This should locate subtitles for short\n"
834 " foreign language segments. Best used in conjunction\n"
835 " with --subtitle-forced.\n"
836 " -F, --subtitle-forced Only display subtitles from the selected stream if\n"
837 " the subtitle has the forced flag set. May be used in\n"
838 " conjunction with --subtitle-scan to auto-select\n"
839 " a stream if it contains forced subtitles.\n"
840 " -N, --native-language Select subtitles with this language if it does not\n"
841 " <string> match the Audio language. Provide the language's\n"
842 " iso639-2 code (fre, eng, spa, dut, et cetera)\n"
843 " -m, --markers Add chapter markers (mp4 output format only)\n"
846 "### Video Options------------------------------------------------------------\n\n"
847 " -e, --encoder <string> Set video library encoder (ffmpeg,xvid,\n"
848 " x264,x264b13,x264b30 default: ffmpeg)\n"
849 " -q, --quality <float> Set video quality (0.0..1.0)\n"
850 " -Q, --crf Use with -q for CRF instead of CQP\n"
851 " -S, --size <MB> Set target size\n"
852 " -b, --vb <kb/s> Set video bitrate (default: 1000)\n"
853 " -r, --rate Set video framerate (" );
854 for( i = 0; i < hb_video_rates_count; i++ )
856 fprintf( stderr, hb_video_rates[i].string );
857 if( i != hb_video_rates_count - 1 )
858 fprintf( stderr, "/" );
860 fprintf( stderr, ")\n"
862 " -2, --two-pass Use two-pass mode\n"
863 " -d, --deinterlace Deinterlace video with yadif/mcdeint filter\n"
864 " <YM:FD:MM:QP> (default 0:-1:-1:1)\n"
865 " -7, --deblock Deblock video with pp7 filter\n"
866 " <QP:M> (default 0:2)\n"
867 " -8, --denoise Denoise video with hqdn3d filter\n"
868 " <SL:SC:TL:TC> (default 4:3:6:4.5)\n"
869 " -9, --detelecine Detelecine video with pullup filter\n"
870 " <L:R:T:B:SB:MP> (default 1:1:4:4:0:0)\n"
871 " -g, --grayscale Grayscale encoding\n"
872 " -p, --pixelratio Store pixel aspect ratio in video stream\n"
877 "### Audio Options-----------------------------------------------------------\n\n"
878 " -E, --aencoder <string> Set audio encoder (faac/lame/vorbis/ac3, ac3\n"
879 " meaning passthrough, default: guessed)\n"
880 " -B, --ab <kb/s> Set audio bitrate (default: 128)\n"
881 " -a, --audio <string> Select audio channel(s) (\"none\" for no \n"
882 " audio, default: first one)\n"
883 " -6, --mixdown <string> Format for surround sound downmixing\n"
884 " (mono/stereo/dpl1/dpl2/6ch, default: dpl2)\n"
885 " -R, --arate Set audio samplerate (" );
886 for( i = 0; i < hb_audio_rates_count; i++ )
888 fprintf( stderr, hb_audio_rates[i].string );
889 if( i != hb_audio_rates_count - 1 )
890 fprintf( stderr, "/" );
892 fprintf( stderr, " kHz)\n"
899 "### Advanced H264 Options----------------------------------------------------\n\n"
900 " -x, --x264opts <string> Specify advanced x264 options in the\n"
901 " same style as mencoder:\n"
902 " option1=value1:option2=value2\n"
903 " -T, --turbo When using 2-pass use the turbo options\n"
904 " on the first pass to improve speed\n"
905 " (only works with x264, affects PSNR by about 0.05dB,\n"
906 " and increases first pass speed two to four times)\n");
909 /****************************************************************************
911 ****************************************************************************/
912 static int ParseOptions( int argc, char ** argv )
916 static struct option long_options[] =
918 { "help", no_argument, NULL, 'h' },
919 { "update", no_argument, NULL, 'u' },
920 { "verbose", no_argument, NULL, 'v' },
921 { "cpu", required_argument, NULL, 'C' },
923 { "format", required_argument, NULL, 'f' },
924 { "input", required_argument, NULL, 'i' },
925 { "output", required_argument, NULL, 'o' },
926 { "large-file", no_argument, NULL, '4' },
928 { "title", required_argument, NULL, 't' },
929 { "longest", no_argument, NULL, 'L' },
930 { "chapters", required_argument, NULL, 'c' },
931 { "markers", optional_argument, NULL, 'm' },
932 { "audio", required_argument, NULL, 'a' },
933 { "mixdown", required_argument, NULL, '6' },
934 { "subtitle", required_argument, NULL, 's' },
935 { "subtitle-scan", no_argument, NULL, 'U' },
936 { "subtitle-forced", no_argument, NULL, 'F' },
937 { "native-language", required_argument, NULL,'N' },
939 { "encoder", required_argument, NULL, 'e' },
940 { "aencoder", required_argument, NULL, 'E' },
941 { "two-pass", no_argument, NULL, '2' },
942 { "deinterlace", optional_argument, NULL, 'd' },
943 { "deblock", optional_argument, NULL, '7' },
944 { "denoise", optional_argument, NULL, '8' },
945 { "detelecine", optional_argument, NULL, '9' },
946 { "grayscale", no_argument, NULL, 'g' },
947 { "pixelratio", no_argument, NULL, 'p' },
948 { "width", required_argument, NULL, 'w' },
949 { "height", required_argument, NULL, 'l' },
950 { "crop", required_argument, NULL, 'n' },
952 { "vb", required_argument, NULL, 'b' },
953 { "quality", required_argument, NULL, 'q' },
954 { "size", required_argument, NULL, 'S' },
955 { "ab", required_argument, NULL, 'B' },
956 { "rate", required_argument, NULL, 'r' },
957 { "arate", required_argument, NULL, 'R' },
958 { "crf", no_argument, NULL, 'Q' },
959 { "x264opts", required_argument, NULL, 'x' },
960 { "turbo", no_argument, NULL, 'T' },
962 { "maxHeight", required_argument, NULL, 'Y' },
963 { "maxWidth", required_argument, NULL, 'X' },
968 int option_index = 0;
971 c = getopt_long( argc, argv,
972 "hvuC:f:4i:o:t:Lc:ma:6:s:UFN:e:E:2d789gpw:l:n:b:q:S:B:r:R:Qx:TY:X:",
973 long_options, &option_index );
988 debug = HB_DEBUG_ALL;
991 cpu = atoi( optarg );
995 format = strdup( optarg );
998 input = strdup( optarg );
1001 output = strdup( optarg );
1007 titleindex = atoi( optarg );
1015 if( sscanf( optarg, "%d-%d", &start, &end ) == 2 )
1017 chapter_start = start;
1020 else if( sscanf( optarg, "%d", &start ) == 1 )
1022 chapter_start = start;
1023 chapter_end = chapter_start;
1027 fprintf( stderr, "chapters: invalid syntax (%s)\n",
1034 if( optarg != NULL )
1036 marker_file = strdup( optarg );
1038 chapter_markers = 1;
1041 audios = strdup( optarg );
1044 if( !strcasecmp( optarg, "mono" ) )
1046 audio_mixdown = HB_AMIXDOWN_MONO;
1048 else if( !strcasecmp( optarg, "stereo" ) )
1050 audio_mixdown = HB_AMIXDOWN_STEREO;
1052 else if( !strcasecmp( optarg, "dpl1" ) )
1054 audio_mixdown = HB_AMIXDOWN_DOLBY;
1056 else if( !strcasecmp( optarg, "dpl2" ) )
1058 audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
1060 else if( !strcasecmp( optarg, "6ch" ) )
1062 audio_mixdown = HB_AMIXDOWN_6CH;
1066 sub = atoi( optarg );
1075 native_language = strdup( optarg );
1081 if( optarg != NULL )
1083 deinterlace_opt = strdup( optarg );
1088 if( optarg != NULL )
1090 deblock_opt = strdup( optarg );
1095 if( optarg != NULL )
1097 denoise_opt = strdup( optarg );
1102 if( optarg != NULL )
1104 detelecine_opt = strdup( optarg );
1115 if( !strcasecmp( optarg, "ffmpeg" ) )
1117 vcodec = HB_VCODEC_FFMPEG;
1119 else if( !strcasecmp( optarg, "xvid" ) )
1121 vcodec = HB_VCODEC_XVID;
1123 else if( !strcasecmp( optarg, "x264" ) )
1125 vcodec = HB_VCODEC_X264;
1127 else if( !strcasecmp( optarg, "x264b13" ) )
1129 vcodec = HB_VCODEC_X264;
1132 else if( !strcasecmp( optarg, "x264b30" ) )
1134 vcodec = HB_VCODEC_X264;
1139 fprintf( stderr, "invalid codec (%s)\n", optarg );
1144 if( !strcasecmp( optarg, "ac3" ) )
1146 acodec = HB_ACODEC_AC3;
1148 else if( !strcasecmp( optarg, "lame" ) )
1150 acodec = HB_ACODEC_LAME;
1152 else if( !strcasecmp( optarg, "faac" ) )
1154 acodec = HB_ACODEC_FAAC;
1156 else if( !strcasecmp( optarg, "vorbis") )
1158 acodec = HB_ACODEC_VORBIS;
1162 width = atoi( optarg );
1165 height = atoi( optarg );
1170 char * tmp = optarg;
1171 for( i = 0; i < 4; i++ )
1175 crop[i] = strtol( tmp, &tmp, 0 );
1184 for( i = 0; i < hb_video_rates_count; i++ )
1186 if( !strcmp( optarg, hb_video_rates[i].string ) )
1188 vrate = hb_video_rates[i].rate;
1194 fprintf( stderr, "invalid framerate %s\n", optarg );
1202 for( i = 0; i < hb_audio_rates_count; i++ )
1204 if( !strcmp( optarg, hb_audio_rates[i].string ) )
1206 arate = hb_audio_rates[i].rate;
1212 fprintf( stderr, "invalid framerate %s\n", optarg );
1217 vbitrate = atoi( optarg );
1220 vquality = atof( optarg );
1223 size = atoi( optarg );
1226 abitrate = atoi( optarg );
1232 x264opts = strdup( optarg );
1233 x264opts2 = strdup( optarg );
1236 turbo_opts_enabled = 1;
1239 maxHeight = atoi( optarg );
1242 maxWidth = atoi (optarg );
1246 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
1254 static int CheckOptions( int argc, char ** argv )
1261 if( input == NULL || *input == '\0' )
1263 fprintf( stderr, "Missing input device. Run %s --help for "
1264 "syntax.\n", argv[0] );
1269 if( titleindex > 0 )
1271 if( output == NULL || *output == '\0' )
1273 fprintf( stderr, "Missing output file name. Run %s --help "
1274 "for syntax.\n", argv[0] );
1280 char * p = strrchr( output, '.' );
1283 if( p && !strcasecmp( p, ".avi" ) )
1287 else if( p && ( !strcasecmp( p, ".mp4" ) ||
1288 !strcasecmp( p, ".m4v" ) ) )
1295 else if( p && ( !strcasecmp( p, ".ogm" ) ||
1296 !strcasecmp( p, ".ogg" ) ) )
1300 else if( p && !strcasecmp(p, ".mkv" ) )
1306 fprintf( stderr, "Output format couldn't be guessed "
1307 "from file name, using default.\n" );
1311 else if( !strcasecmp( format, "avi" ) )
1315 else if( !strcasecmp( format, "mp4" ) )
1322 else if( !strcasecmp( format, "ogm" ) ||
1323 !strcasecmp( format, "ogg" ) )
1327 else if( !strcasecmp( format, "mkv" ) )
1333 fprintf( stderr, "Invalid output format (%s). Possible "
1334 "choices are avi, mp4, m4v, ogm, ogg and mkv\n.", format );
1340 if( mux == HB_MUX_MP4 || mux == HB_MUX_IPOD )
1342 acodec = HB_ACODEC_FAAC;
1344 else if( mux == HB_MUX_AVI )
1346 acodec = HB_ACODEC_LAME;
1348 else if( mux == HB_MUX_OGM )
1350 acodec = HB_ACODEC_VORBIS;
1352 else if( mux == HB_MUX_MKV )
1354 acodec = HB_ACODEC_AC3;