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 char * native_language = NULL;
26 static int twoPass = 0;
27 static int deinterlace = 0;
28 static char * deinterlace_opt = 0;
29 static int deblock = 0;
30 static char * deblock_opt = 0;
31 static int denoise = 0;
32 static char * denoise_opt = 0;
33 static int detelecine = 0;
34 static char * detelecine_opt = 0;
35 static int grayscale = 0;
36 static int vcodec = HB_VCODEC_FFMPEG;
37 static int h264_13 = 0;
38 static int h264_30 = 0;
39 static char * audios = NULL;
40 static int audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
43 static int height = 0;
44 static int crop[4] = { -1,-1,-1,-1 };
48 static float vquality = -1.0;
49 static int vbitrate = 0;
51 static int abitrate = 0;
53 static int acodec = 0;
54 static int pixelratio = 0;
55 static int chapter_start = 0;
56 static int chapter_end = 0;
57 static int chapter_markers = 0;
58 static char * marker_file = NULL;
60 static char *x264opts = NULL;
61 static char *x264opts2 = NULL;
62 static int maxHeight = 0;
63 static int maxWidth = 0;
64 static int turbo_opts_enabled = 0;
65 static char * turbo_opts = "ref=1:subme=1:me=dia:analyse=none:weightb=0:trellis=0:no-fast-pskip=0:8x8dct=0";
66 static int largeFileSize = 0;
68 /* Exit cleanly on Ctrl-C */
69 static volatile int die = 0;
70 static void SigHandler( int );
73 static void ShowCommands();
74 static void ShowHelp();
75 static int ParseOptions( int argc, char ** argv );
76 static int CheckOptions( int argc, char ** argv );
77 static int HandleEvents( hb_handle_t * h );
79 int main( int argc, char ** argv )
85 /* Parse command line */
86 if( ParseOptions( argc, argv ) ||
87 CheckOptions( argc, argv ) )
93 h = hb_init( debug, update );
96 fprintf( stderr, "HandBrake %s (%d) - http://handbrake.m0k.org/\n",
97 hb_get_version( h ), hb_get_build( h ) );
99 /* Check for update */
102 if( ( build = hb_check_update( h, &version ) ) > -1 )
104 fprintf( stderr, "You are using an old version of "
105 "HandBrake.\nLatest is %s (build %d).\n", version,
110 fprintf( stderr, "Your version of HandBrake is up to "
118 fprintf( stderr, "%d CPU%s detected\n", hb_get_cpu_count(),
119 hb_get_cpu_count( h ) > 1 ? "s" : "" );
122 fprintf( stderr, "Forcing %d CPU%s\n", cpu,
123 cpu > 1 ? "s" : "" );
124 hb_set_cpu_count( h, cpu );
127 /* Exit ASAP on Ctrl-C */
128 signal( SIGINT, SigHandler );
130 /* Feed libhb with a DVD to scan */
131 fprintf( stderr, "Opening %s...\n", input );
135 * We need to scan for all the titles in order to find the longest
139 hb_scan( h, input, titleindex );
144 #if !defined(SYS_BEOS)
154 FD_SET( STDIN_FILENO, &fds );
155 ret = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
162 read( STDIN_FILENO, &buf[size], 1 ) > 0 )
164 if( buf[size] == '\n' )
171 if( size >= 256 || buf[size] == '\n' )
200 if( input ) free( input );
201 if( output ) free( output );
202 if( format ) free( format );
203 if( audios ) free( audios );
204 if (native_language ) free (native_language );
205 if( x264opts ) free (x264opts );
206 if( x264opts2 ) free (x264opts2 );
208 fprintf( stderr, "HandBrake has exited.\n" );
213 static void ShowCommands()
215 fprintf( stderr, "Commands:\n" );
216 fprintf( stderr, " [h]elp Show this message\n" );
217 fprintf( stderr, " [q]uit Exit HandBrakeCLI\n" );
218 fprintf( stderr, " [p]ause Pause encoding\n" );
219 fprintf( stderr, " [r]esume Resume encoding\n" );
222 static void PrintTitleInfo( hb_title_t * title )
224 hb_chapter_t * chapter;
226 hb_subtitle_t * subtitle;
229 fprintf( stderr, "+ title %d:\n", title->index );
230 fprintf( stderr, " + vts %d, ttn %d, cells %d->%d (%d blocks)\n",
231 title->vts, title->ttn, title->cell_start, title->cell_end,
232 title->block_count );
233 fprintf( stderr, " + duration: %02d:%02d:%02d\n",
234 title->hours, title->minutes, title->seconds );
235 fprintf( stderr, " + size: %dx%d, aspect: %.2f, %.3f fps\n",
236 title->width, title->height,
237 (float) title->aspect / HB_ASPECT_BASE,
238 (float) title->rate / title->rate_base );
239 fprintf( stderr, " + autocrop: %d/%d/%d/%d\n", title->crop[0],
240 title->crop[1], title->crop[2], title->crop[3] );
241 fprintf( stderr, " + chapters:\n" );
242 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
244 chapter = hb_list_item( title->list_chapter, i );
245 fprintf( stderr, " + %d: cells %d->%d, %d blocks, duration "
246 "%02d:%02d:%02d\n", chapter->index,
247 chapter->cell_start, chapter->cell_end,
248 chapter->block_count, chapter->hours, chapter->minutes,
251 fprintf( stderr, " + audio tracks:\n" );
252 for( i = 0; i < hb_list_count( title->list_audio ); i++ )
254 audio = hb_list_item( title->list_audio, i );
255 if( ( audio->codec & HB_ACODEC_AC3 ) || ( audio->codec & HB_ACODEC_DCA) )
257 fprintf( stderr, " + %d, %s, %dHz, %dbps\n", i + 1,
258 audio->lang, audio->rate, audio->bitrate );
262 fprintf( stderr, " + %d, %s\n", i + 1, audio->lang );
265 fprintf( stderr, " + subtitle tracks:\n" );
266 for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
268 subtitle = hb_list_item( title->list_subtitle, i );
269 fprintf( stderr, " + %d, %s (iso639-2: %s)\n", i + 1, subtitle->lang,
274 static int HandleEvents( hb_handle_t * h )
277 hb_get_state( h, &s );
284 #define p s.param.scanning
285 case HB_STATE_SCANNING:
286 /* Show what title is currently being scanned */
287 fprintf( stderr, "Scanning title %d", p.title_cur );
289 fprintf( stderr, " of %d", p.title_count );
290 fprintf( stderr, "...\n" );
294 case HB_STATE_SCANDONE:
300 list = hb_get_titles( h );
302 if( !hb_list_count( list ) )
304 /* No valid title, stop right there */
305 fprintf( stderr, "No title found.\n" );
312 int longest_title_idx=0;
313 int longest_title_pos=-1;
314 int longest_title_time=0;
317 fprintf( stderr, "Searching for longest title...\n" );
319 for( i = 0; i < hb_list_count( list ); i++ )
321 title = hb_list_item( list, i );
322 title_time = (title->hours*60*60 ) + (title->minutes *60) + (title->seconds);
323 fprintf( stderr, " + Title (%d) index %d has length %dsec\n",
324 i, title->index, title_time );
325 if( longest_title_time < title_time )
327 longest_title_time = title_time;
328 longest_title_pos = i;
329 longest_title_idx = title->index;
332 if( longest_title_pos == -1 )
334 fprintf( stderr, "No longest title found.\n" );
338 titleindex = longest_title_idx;
339 fprintf( stderr, "Found longest title, setting title to %d\n",
342 title = hb_list_item( list, longest_title_pos);
344 title = hb_list_item( list, 0 );
349 /* Scan-only mode, print infos and exit */
351 for( i = 0; i < hb_list_count( list ); i++ )
353 title = hb_list_item( list, i );
354 PrintTitleInfo( title );
360 /* Set job settings */
363 PrintTitleInfo( title );
365 if( chapter_start && chapter_end )
367 job->chapter_start = MAX( job->chapter_start,
369 job->chapter_end = MIN( job->chapter_end,
371 job->chapter_end = MAX( job->chapter_start,
375 if ( chapter_markers )
377 job->chapter_markers = chapter_markers;
379 if( marker_file != NULL )
381 hb_csv_file_t * file = hb_open_csv_file( marker_file );
382 hb_csv_cell_t * cell;
386 fprintf( stderr, "Reading chapter markers from file %s\n", marker_file );
390 fprintf( stderr, "Cannot open chapter marker file, using defaults\n" );
394 /* Parse the cells */
395 while( NULL != ( cell = hb_read_next_cell( file ) ) )
397 /* We have a chapter number */
398 if( cell->cell_col == 0 )
400 row = cell->cell_row;
401 chapter = atoi( cell->cell_text );
404 /* We have a chapter name */
405 if( cell->cell_col == 1 && row == cell->cell_row )
407 /* If we have a valid chapter, copy the string an terminate it */
408 if( chapter >= job->chapter_start && chapter <= job->chapter_end )
410 hb_chapter_t * chapter_s;
412 chapter_s = hb_list_item( job->title->list_chapter, chapter - 1);
413 strncpy(chapter_s->title, cell->cell_text, 1023);
414 chapter_s->title[1023] = '\0';
419 hb_dispose_cell( cell );
422 hb_close_csv_file( file );
427 if( crop[0] >= 0 && crop[1] >= 0 &&
428 crop[2] >= 0 && crop[3] >= 0 )
430 memcpy( job->crop, crop, 4 * sizeof( int ) );
433 job->deinterlace = deinterlace;
434 job->grayscale = grayscale;
435 job->pixel_ratio = pixelratio;
437 /* Add selected filters */
438 job->filters = hb_list_init();
441 hb_filter_detelecine.settings = detelecine_opt;
442 hb_list_add( job->filters, &hb_filter_detelecine );
446 hb_filter_deinterlace.settings = deinterlace_opt;
447 hb_list_add( job->filters, &hb_filter_deinterlace );
451 hb_filter_deblock.settings = deblock_opt;
452 hb_list_add( job->filters, &hb_filter_deblock );
456 hb_filter_denoise.settings = denoise_opt;
457 hb_list_add( job->filters, &hb_filter_denoise );
460 if( width && height )
463 job->height = height;
468 hb_fix_aspect( job, HB_KEEP_WIDTH );
472 job->height = height;
473 hb_fix_aspect( job, HB_KEEP_HEIGHT );
475 else if( !width && !height && !pixelratio )
477 hb_fix_aspect( job, HB_KEEP_WIDTH );
480 if( vquality >= 0.0 && vquality <= 1.0 )
482 job->vquality = vquality;
487 job->vquality = -1.0;
488 job->vbitrate = vbitrate;
492 job->vcodec = vcodec;
496 job->h264_level = 13;
500 job->h264_level = 30;
504 job->vrate = 27000000;
505 job->vrate_base = vrate;
514 if( strcasecmp( audios, "none" ) )
520 if( *tmp < '0' || *tmp > '9' )
522 /* Skip non numeric char */
526 job->audio_mixdowns[audio_count] = audio_mixdown;
527 job->audios[audio_count++] =
528 strtol( tmp, &tmp, 0 ) - 1;
530 job->audios[audio_count] = -1;
539 /* default to the first audio track if none has been specified */
541 job->audio_mixdowns[0] = audio_mixdown;
545 job->abitrate = abitrate;
549 job->acodec = acodec;
554 job->vbitrate = hb_calc_bitrate( job, size );
555 fprintf( stderr, "Calculated bitrate: %d kbps\n",
561 job->subtitle = sub - 1;
564 if( native_language )
566 job->native_language = strdup( native_language );
576 job->largeFileSize = 1;
579 job->file = strdup( output );
586 if( x264opts != NULL && *x264opts != '\0' )
588 fprintf( stderr, "Applying the following x264 options: %s\n",
590 job->x264opts = x264opts;
592 else /*avoids a bus error crash when options aren't specified*/
594 job->x264opts = NULL;
597 job->maxWidth = maxWidth;
599 job->maxHeight = maxHeight;
604 * If subtitle_scan is enabled then only turn it on
605 * for the first pass and then off again for the
609 job->subtitle_scan = subtitle_scan;
612 fprintf( stderr, "Subtitle Scan Enabled - enabling "
613 "subtitles if found for foreign language segments\n");
614 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
615 *(job->select_subtitle) = NULL;
619 * If turbo options have been selected then append them
620 * to the x264opts now (size includes one ':' and the '\0')
622 if( turbo_opts_enabled )
624 int size = (x264opts ? strlen(x264opts) : 0) + strlen(turbo_opts) + 2;
627 tmp_x264opts = malloc(size * sizeof(char));
630 snprintf( tmp_x264opts, size, "%s:%s",
631 x264opts, turbo_opts );
635 * No x264opts to modify, but apply the turbo options
636 * anyway as they may be modifying defaults
638 snprintf( tmp_x264opts, size, "%s",
641 x264opts = tmp_x264opts;
643 fprintf( stderr, "Modified x264 options for pass 1 to append turbo options: %s\n",
646 job->x264opts = x264opts;
651 * On the second pass we turn off subtitle scan so that we
652 * can actually encode using any subtitles that were auto
653 * selected in the first pass (using the whacky select-subtitle
654 * attribute of the job).
656 job->subtitle_scan = 0;
658 job->x264opts = x264opts2;
665 * Turn on subtitle scan if requested, note that this option
666 * precludes encoding of any actual subtitles.
670 fprintf( stderr, "Warning: Subtitle Scan only works in two-pass, disabling\n");
679 #define p s.param.working
680 case HB_STATE_WORKING:
681 fprintf( stderr, "\rEncoding: task %d of %d, %.2f %%",
682 p.job_cur, p.job_count, 100.0 * p.progress );
685 fprintf( stderr, " (%.2f fps, avg %.2f fps, ETA "
686 "%02dh%02dm%02ds)", p.rate_cur, p.rate_avg,
687 p.hours, p.minutes, p.seconds );
692 #define p s.param.muxing
693 case HB_STATE_MUXING:
695 fprintf( stderr, "\rMuxing: %.2f %%", 100.0 * p.progress );
700 #define p s.param.workdone
701 case HB_STATE_WORKDONE:
702 /* Print error if any, then exit */
706 fprintf( stderr, "\nRip done!\n" );
708 case HB_ERROR_CANCELED:
709 fprintf( stderr, "\nRip canceled.\n" );
712 fprintf( stderr, "\nRip failed (error %x).\n",
722 /****************************************************************************
724 ****************************************************************************/
725 static volatile int64_t i_die_date = 0;
726 void SigHandler( int i_signal )
731 i_die_date = hb_get_date();
732 fprintf( stderr, "Signal %d received, terminating - do it "
733 "again in case it gets stuck\n", i_signal );
735 else if( i_die_date + 500 < hb_get_date() )
737 fprintf( stderr, "Dying badly, files might remain in your /tmp\n" );
742 /****************************************************************************
744 ****************************************************************************/
745 static void ShowHelp()
750 "Syntax: HandBrakeCLI [options] -i <device> -o <file>\n"
752 "### General Handbrake Options------------------------------------------------\n\n"
753 " -h, --help Print help\n"
754 " -u, --update Check for updates and exit\n"
755 " -v, --verbose Be verbose\n"
756 " -C, --cpu Set CPU count (default: autodetected)\n"
759 "### Source Options-----------------------------------------------------------\n\n"
760 " -i, --input <string> Set input device\n"
761 " -t, --title <number> Select a title to encode (0 to scan only,\n"
763 " -L, --longest Select the longest title\n"
764 " -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n"
765 " 1 to 3, or \"3\" for chapter 3 only,\n"
766 " default: all chapters)\n"
769 "### Destination Options------------------------------------------------------\n\n"
770 " -o, --output <string> Set output file name\n"
771 " -f, --format <string> Set output format (avi/mp4/ogm/mkv, default:\n"
772 " autodetected from file name)\n"
773 " -4, --large-file Use 64-bit mp4 files that can hold more than\n"
774 " 4 GB. Note: Breaks iPod, @TV, PS3 compatibility.\n"""
777 "### Picture Settings---------------------------------------------------------\n\n"
778 " -w, --width <number> Set picture width\n"
779 " -l, --height <number> Set picture height\n"
780 " --crop <T:B:L:R> Set cropping values (default: autocrop)\n"
781 " -Y, --maxHeight <#> Set maximum height\n"
782 " -X, --maxWidth <#> Set maximum width\n"
783 " -s, --subtitle <number> Select subtitle (default: none)\n"
784 " -U, --subtitle-scan Scan for subtitles on the first pass, and choose\n"
785 " the one that's only used 20 percent of the time\n"
786 " or less. This should locate subtitles for short\n"
787 " foreign language segments. Only works with 2-pass.\n"
788 " -N, --native-language Select subtitles with this language if it does not\n"
789 " <string> match the Audio language. Provide the language's\n"
790 " iso639-2 code (fre, eng, spa, dut, et cetera)\n"
791 " -m, --markers Add chapter markers (mp4 output format only)\n"
794 "### Video Options------------------------------------------------------------\n\n"
795 " -e, --encoder <string> Set video library encoder (ffmpeg,xvid,\n"
796 " x264,x264b13,x264b30 default: ffmpeg)\n"
797 " -q, --quality <float> Set video quality (0.0..1.0)\n"
798 " -Q, --crf Use with -q for CRF instead of CQP\n"
799 " -S, --size <MB> Set target size\n"
800 " -b, --vb <kb/s> Set video bitrate (default: 1000)\n"
801 " -r, --rate Set video framerate (" );
802 for( i = 0; i < hb_video_rates_count; i++ )
804 fprintf( stderr, hb_video_rates[i].string );
805 if( i != hb_video_rates_count - 1 )
806 fprintf( stderr, "/" );
808 fprintf( stderr, ")\n"
810 " -2, --two-pass Use two-pass mode\n"
811 " -d, --deinterlace Deinterlace video with yadif/mcdeint filter\n"
812 " <YM:FD:MM:QP> (default 0:-1:-1:1)\n"
813 " -7, --deblock Deblock video with pp7 filter\n"
814 " <QP:M> (default 0:2)\n"
815 " -8, --denoise Denoise video with hqdn3d filter\n"
816 " <SL:SC:TL:TC> (default 4:3:6:4.5)\n"
817 " -9, --detelecine Detelecine video with pullup filter\n"
818 " <L:R:T:B:SB:MP> (default 1:1:4:4:0:0)\n"
819 " -g, --grayscale Grayscale encoding\n"
820 " -p, --pixelratio Store pixel aspect ratio in video stream\n"
825 "### Audio Options-----------------------------------------------------------\n\n"
826 " -E, --aencoder <string> Set audio encoder (faac/lame/vorbis/ac3, ac3\n"
827 " meaning passthrough, default: guessed)\n"
828 " -B, --ab <kb/s> Set audio bitrate (default: 128)\n"
829 " -a, --audio <string> Select audio channel(s) (\"none\" for no \n"
830 " audio, default: first one)\n"
831 " -6, --mixdown <string> Format for surround sound downmixing\n"
832 " (mono/stereo/dpl1/dpl2/6ch, default: dpl2)\n"
833 " -R, --arate Set audio samplerate (" );
834 for( i = 0; i < hb_audio_rates_count; i++ )
836 fprintf( stderr, hb_audio_rates[i].string );
837 if( i != hb_audio_rates_count - 1 )
838 fprintf( stderr, "/" );
840 fprintf( stderr, " kHz)\n"
847 "### Advanced H264 Options----------------------------------------------------\n\n"
848 " -x, --x264opts <string> Specify advanced x264 options in the\n"
849 " same style as mencoder:\n"
850 " option1=value1:option2=value2\n"
851 " -T, --turbo When using 2-pass use the turbo options\n"
852 " on the first pass to improve speed\n"
853 " (only works with x264, affects PSNR by about 0.05dB,\n"
854 " and increases first pass speed two to four times)\n");
857 /****************************************************************************
859 ****************************************************************************/
860 static int ParseOptions( int argc, char ** argv )
864 static struct option long_options[] =
866 { "help", no_argument, NULL, 'h' },
867 { "update", no_argument, NULL, 'u' },
868 { "verbose", no_argument, NULL, 'v' },
869 { "cpu", required_argument, NULL, 'C' },
871 { "format", required_argument, NULL, 'f' },
872 { "input", required_argument, NULL, 'i' },
873 { "output", required_argument, NULL, 'o' },
874 { "large-file", no_argument, NULL, '4' },
876 { "title", required_argument, NULL, 't' },
877 { "longest", no_argument, NULL, 'L' },
878 { "chapters", required_argument, NULL, 'c' },
879 { "markers", optional_argument, NULL, 'm' },
880 { "audio", required_argument, NULL, 'a' },
881 { "mixdown", required_argument, NULL, '6' },
882 { "subtitle", required_argument, NULL, 's' },
883 { "subtitle-scan", no_argument, NULL, 'U' },
884 { "native-language", required_argument, NULL,'N' },
886 { "encoder", required_argument, NULL, 'e' },
887 { "aencoder", required_argument, NULL, 'E' },
888 { "two-pass", no_argument, NULL, '2' },
889 { "deinterlace", optional_argument, NULL, 'd' },
890 { "deblock", optional_argument, NULL, '7' },
891 { "denoise", optional_argument, NULL, '8' },
892 { "detelecine", optional_argument, NULL, '9' },
893 { "grayscale", no_argument, NULL, 'g' },
894 { "pixelratio", no_argument, NULL, 'p' },
895 { "width", required_argument, NULL, 'w' },
896 { "height", required_argument, NULL, 'l' },
897 { "crop", required_argument, NULL, 'n' },
899 { "vb", required_argument, NULL, 'b' },
900 { "quality", required_argument, NULL, 'q' },
901 { "size", required_argument, NULL, 'S' },
902 { "ab", required_argument, NULL, 'B' },
903 { "rate", required_argument, NULL, 'r' },
904 { "arate", required_argument, NULL, 'R' },
905 { "crf", no_argument, NULL, 'Q' },
906 { "x264opts", required_argument, NULL, 'x' },
907 { "turbo", no_argument, NULL, 'T' },
909 { "maxHeight", required_argument, NULL, 'Y' },
910 { "maxWidth", required_argument, NULL, 'X' },
915 int option_index = 0;
918 c = getopt_long( argc, argv,
919 "hvuC:f:4i:o:t:Lc:ma:6:s:UN:e:E:2d789gpw:l:n:b:q:S:B:r:R:Qx:TY:X:",
920 long_options, &option_index );
935 debug = HB_DEBUG_ALL;
938 cpu = atoi( optarg );
942 format = strdup( optarg );
945 input = strdup( optarg );
948 output = strdup( optarg );
954 titleindex = atoi( optarg );
962 if( sscanf( optarg, "%d-%d", &start, &end ) == 2 )
964 chapter_start = start;
967 else if( sscanf( optarg, "%d", &start ) == 1 )
969 chapter_start = start;
970 chapter_end = chapter_start;
974 fprintf( stderr, "chapters: invalid syntax (%s)\n",
983 marker_file = strdup( optarg );
988 audios = strdup( optarg );
991 if( !strcasecmp( optarg, "mono" ) )
993 audio_mixdown = HB_AMIXDOWN_MONO;
995 else if( !strcasecmp( optarg, "stereo" ) )
997 audio_mixdown = HB_AMIXDOWN_STEREO;
999 else if( !strcasecmp( optarg, "dpl1" ) )
1001 audio_mixdown = HB_AMIXDOWN_DOLBY;
1003 else if( !strcasecmp( optarg, "dpl2" ) )
1005 audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
1007 else if( !strcasecmp( optarg, "6ch" ) )
1009 audio_mixdown = HB_AMIXDOWN_6CH;
1013 sub = atoi( optarg );
1019 native_language = strdup( optarg );
1025 if( optarg != NULL )
1027 deinterlace_opt = strdup( optarg );
1032 if( optarg != NULL )
1034 deblock_opt = strdup( optarg );
1039 if( optarg != NULL )
1041 denoise_opt = strdup( optarg );
1046 if( optarg != NULL )
1048 detelecine_opt = strdup( optarg );
1059 if( !strcasecmp( optarg, "ffmpeg" ) )
1061 vcodec = HB_VCODEC_FFMPEG;
1063 else if( !strcasecmp( optarg, "xvid" ) )
1065 vcodec = HB_VCODEC_XVID;
1067 else if( !strcasecmp( optarg, "x264" ) )
1069 vcodec = HB_VCODEC_X264;
1071 else if( !strcasecmp( optarg, "x264b13" ) )
1073 vcodec = HB_VCODEC_X264;
1076 else if( !strcasecmp( optarg, "x264b30" ) )
1078 vcodec = HB_VCODEC_X264;
1083 fprintf( stderr, "invalid codec (%s)\n", optarg );
1088 if( !strcasecmp( optarg, "ac3" ) )
1090 acodec = HB_ACODEC_AC3;
1092 else if( !strcasecmp( optarg, "lame" ) )
1094 acodec = HB_ACODEC_LAME;
1096 else if( !strcasecmp( optarg, "faac" ) )
1098 acodec = HB_ACODEC_FAAC;
1100 else if( !strcasecmp( optarg, "vorbis") )
1102 acodec = HB_ACODEC_VORBIS;
1106 width = atoi( optarg );
1109 height = atoi( optarg );
1114 char * tmp = optarg;
1115 for( i = 0; i < 4; i++ )
1119 crop[i] = strtol( tmp, &tmp, 0 );
1128 for( i = 0; i < hb_video_rates_count; i++ )
1130 if( !strcmp( optarg, hb_video_rates[i].string ) )
1132 vrate = hb_video_rates[i].rate;
1138 fprintf( stderr, "invalid framerate %s\n", optarg );
1146 for( i = 0; i < hb_audio_rates_count; i++ )
1148 if( !strcmp( optarg, hb_audio_rates[i].string ) )
1150 arate = hb_audio_rates[i].rate;
1156 fprintf( stderr, "invalid framerate %s\n", optarg );
1161 vbitrate = atoi( optarg );
1164 vquality = atof( optarg );
1167 size = atoi( optarg );
1170 abitrate = atoi( optarg );
1176 x264opts = strdup( optarg );
1177 x264opts2 = strdup( optarg );
1180 turbo_opts_enabled = 1;
1183 maxHeight = atoi( optarg );
1186 maxWidth = atoi (optarg );
1190 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
1198 static int CheckOptions( int argc, char ** argv )
1205 if( input == NULL || *input == '\0' )
1207 fprintf( stderr, "Missing input device. Run %s --help for "
1208 "syntax.\n", argv[0] );
1213 if( titleindex > 0 )
1215 if( output == NULL || *output == '\0' )
1217 fprintf( stderr, "Missing output file name. Run %s --help "
1218 "for syntax.\n", argv[0] );
1224 char * p = strrchr( output, '.' );
1227 if( p && !strcasecmp( p, ".avi" ) )
1231 else if( p && ( !strcasecmp( p, ".mp4" ) ||
1232 !strcasecmp( p, ".m4v" ) ) )
1239 else if( p && ( !strcasecmp( p, ".ogm" ) ||
1240 !strcasecmp( p, ".ogg" ) ) )
1244 else if( p && !strcasecmp(p, ".mkv" ) )
1250 fprintf( stderr, "Output format couldn't be guessed "
1251 "from file name, using default.\n" );
1255 else if( !strcasecmp( format, "avi" ) )
1259 else if( !strcasecmp( format, "mp4" ) )
1266 else if( !strcasecmp( format, "ogm" ) ||
1267 !strcasecmp( format, "ogg" ) )
1271 else if( !strcasecmp( format, "mkv" ) )
1277 fprintf( stderr, "Invalid output format (%s). Possible "
1278 "choices are avi, mp4, m4v, ogm, ogg and mkv\n.", format );
1284 if( mux == HB_MUX_MP4 || mux == HB_MUX_IPOD )
1286 acodec = HB_ACODEC_FAAC;
1288 else if( mux == HB_MUX_AVI )
1290 acodec = HB_ACODEC_LAME;
1292 else if( mux == HB_MUX_OGM )
1294 acodec = HB_ACODEC_VORBIS;
1296 else if( mux == HB_MUX_MKV )
1298 acodec = HB_ACODEC_AC3;