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 int grayscale = 0;
29 static int vcodec = HB_VCODEC_FFMPEG;
30 static int h264_13 = 0;
31 static int h264_30 = 0;
32 static char * audios = NULL;
33 static int audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
36 static int height = 0;
37 static int crop[4] = { -1,-1,-1,-1 };
41 static float vquality = -1.0;
42 static int vbitrate = 0;
44 static int abitrate = 0;
46 static int acodec = 0;
47 static int pixelratio = 0;
48 static int chapter_start = 0;
49 static int chapter_end = 0;
50 static int chapter_markers = 0;
51 static char * marker_file = NULL;
53 static char *x264opts = NULL;
54 static char *x264opts2 = NULL;
55 static int maxHeight = 0;
56 static int maxWidth = 0;
57 static int turbo_opts_enabled = 0;
58 static char * turbo_opts = "no-fast-pskip=0:subme=1:me=dia:trellis=0:analyse=none";
60 /* Exit cleanly on Ctrl-C */
61 static volatile int die = 0;
62 static void SigHandler( int );
65 static void ShowCommands();
66 static void ShowHelp();
67 static int ParseOptions( int argc, char ** argv );
68 static int CheckOptions( int argc, char ** argv );
69 static int HandleEvents( hb_handle_t * h );
71 int main( int argc, char ** argv )
77 /* Parse command line */
78 if( ParseOptions( argc, argv ) ||
79 CheckOptions( argc, argv ) )
85 h = hb_init( debug, update );
88 fprintf( stderr, "HandBrake %s (%d) - http://handbrake.m0k.org/\n",
89 hb_get_version( h ), hb_get_build( h ) );
91 /* Check for update */
94 if( ( build = hb_check_update( h, &version ) ) > -1 )
96 fprintf( stderr, "You are using an old version of "
97 "HandBrake.\nLatest is %s (build %d).\n", version,
102 fprintf( stderr, "Your version of HandBrake is up to "
110 fprintf( stderr, "%d CPU%s detected\n", hb_get_cpu_count(),
111 hb_get_cpu_count( h ) > 1 ? "s" : "" );
114 fprintf( stderr, "Forcing %d CPU%s\n", cpu,
115 cpu > 1 ? "s" : "" );
116 hb_set_cpu_count( h, cpu );
119 /* Exit ASAP on Ctrl-C */
120 signal( SIGINT, SigHandler );
122 /* Feed libhb with a DVD to scan */
123 fprintf( stderr, "Opening %s...\n", input );
127 * We need to scan for all the titles in order to find the longest
131 hb_scan( h, input, titleindex );
136 #if !defined(SYS_BEOS)
146 FD_SET( STDIN_FILENO, &fds );
147 ret = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
154 read( STDIN_FILENO, &buf[size], 1 ) > 0 )
156 if( buf[size] == '\n' )
163 if( size >= 256 || buf[size] == '\n' )
192 if( input ) free( input );
193 if( output ) free( output );
194 if( format ) free( format );
195 if( audios ) free( audios );
196 if (native_language ) free (native_language );
197 if( x264opts ) free (x264opts );
198 if( x264opts2 ) free (x264opts2 );
200 fprintf( stderr, "HandBrake has exited.\n" );
205 static void ShowCommands()
207 fprintf( stderr, "Commands:\n" );
208 fprintf( stderr, " [h]elp Show this message\n" );
209 fprintf( stderr, " [q]uit Exit HandBrakeCLI\n" );
210 fprintf( stderr, " [p]ause Pause encoding\n" );
211 fprintf( stderr, " [r]esume Resume encoding\n" );
214 static void PrintTitleInfo( hb_title_t * title )
216 hb_chapter_t * chapter;
218 hb_subtitle_t * subtitle;
221 fprintf( stderr, "+ title %d:\n", title->index );
222 fprintf( stderr, " + vts %d, ttn %d, cells %d->%d (%d blocks)\n",
223 title->vts, title->ttn, title->cell_start, title->cell_end,
224 title->block_count );
225 fprintf( stderr, " + duration: %02d:%02d:%02d\n",
226 title->hours, title->minutes, title->seconds );
227 fprintf( stderr, " + size: %dx%d, aspect: %.2f, %.3f fps\n",
228 title->width, title->height,
229 (float) title->aspect / HB_ASPECT_BASE,
230 (float) title->rate / title->rate_base );
231 fprintf( stderr, " + autocrop: %d/%d/%d/%d\n", title->crop[0],
232 title->crop[1], title->crop[2], title->crop[3] );
233 fprintf( stderr, " + chapters:\n" );
234 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
236 chapter = hb_list_item( title->list_chapter, i );
237 fprintf( stderr, " + %d: cells %d->%d, %d blocks, duration "
238 "%02d:%02d:%02d\n", chapter->index,
239 chapter->cell_start, chapter->cell_end,
240 chapter->block_count, chapter->hours, chapter->minutes,
243 fprintf( stderr, " + audio tracks:\n" );
244 for( i = 0; i < hb_list_count( title->list_audio ); i++ )
246 audio = hb_list_item( title->list_audio, i );
247 if( ( audio->codec & HB_ACODEC_AC3 ) || ( audio->codec & HB_ACODEC_DCA) )
249 fprintf( stderr, " + %d, %s, %dHz, %dbps\n", i + 1,
250 audio->lang, audio->rate, audio->bitrate );
254 fprintf( stderr, " + %d, %s\n", i + 1, audio->lang );
257 fprintf( stderr, " + subtitle tracks:\n" );
258 for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
260 subtitle = hb_list_item( title->list_subtitle, i );
261 fprintf( stderr, " + %d, %s (iso639-2: %s)\n", i + 1, subtitle->lang,
266 static int HandleEvents( hb_handle_t * h )
269 hb_get_state( h, &s );
276 #define p s.param.scanning
277 case HB_STATE_SCANNING:
278 /* Show what title is currently being scanned */
279 fprintf( stderr, "Scanning title %d", p.title_cur );
281 fprintf( stderr, " of %d", p.title_count );
282 fprintf( stderr, "...\n" );
286 case HB_STATE_SCANDONE:
292 list = hb_get_titles( h );
294 if( !hb_list_count( list ) )
296 /* No valid title, stop right there */
297 fprintf( stderr, "No title found.\n" );
304 int longest_title_idx=0;
305 int longest_title_pos=-1;
306 int longest_title_time=0;
309 fprintf( stderr, "Searching for longest title...\n" );
311 for( i = 0; i < hb_list_count( list ); i++ )
313 title = hb_list_item( list, i );
314 title_time = (title->hours*60*60 ) + (title->minutes *60) + (title->seconds);
315 fprintf( stderr, " + Title (%d) index %d has length %dsec\n",
316 i, title->index, title_time );
317 if( longest_title_time < title_time )
319 longest_title_time = title_time;
320 longest_title_pos = i;
321 longest_title_idx = title->index;
324 if( longest_title_pos == -1 )
326 fprintf( stderr, "No longest title found.\n" );
330 titleindex = longest_title_idx;
331 fprintf( stderr, "Found longest title, setting title to %d\n",
334 title = hb_list_item( list, longest_title_pos);
336 title = hb_list_item( list, 0 );
341 /* Scan-only mode, print infos and exit */
343 for( i = 0; i < hb_list_count( list ); i++ )
345 title = hb_list_item( list, i );
346 PrintTitleInfo( title );
352 /* Set job settings */
355 PrintTitleInfo( title );
357 if( chapter_start && chapter_end )
359 job->chapter_start = MAX( job->chapter_start,
361 job->chapter_end = MIN( job->chapter_end,
363 job->chapter_end = MAX( job->chapter_start,
367 if ( chapter_markers )
369 job->chapter_markers = chapter_markers;
371 if( marker_file != NULL )
373 hb_csv_file_t * file = hb_open_csv_file( marker_file );
374 hb_csv_cell_t * cell;
378 fprintf( stderr, "Reading chapter markers from file %s\n", marker_file );
382 fprintf( stderr, "Cannot open chapter marker file, using defaults\n" );
386 /* Parse the cells */
387 while( NULL != ( cell = hb_read_next_cell( file ) ) )
389 /* We have a chapter number */
390 if( cell->cell_col == 0 )
392 row = cell->cell_row;
393 chapter = atoi( cell->cell_text );
396 /* We have a chapter name */
397 if( cell->cell_col == 1 && row == cell->cell_row )
399 /* If we have a valid chapter, copy the string an terminate it */
400 if( chapter >= job->chapter_start && chapter <= job->chapter_end )
402 hb_chapter_t * chapter_s;
404 chapter_s = hb_list_item( job->title->list_chapter, chapter - 1);
405 strncpy(chapter_s->title, cell->cell_text, 1023);
406 chapter_s->title[1023] = '\0';
411 hb_dispose_cell( cell );
414 hb_close_csv_file( file );
419 if( crop[0] >= 0 && crop[1] >= 0 &&
420 crop[2] >= 0 && crop[3] >= 0 )
422 memcpy( job->crop, crop, 4 * sizeof( int ) );
425 job->deinterlace = deinterlace;
426 job->grayscale = grayscale;
427 job->pixel_ratio = pixelratio;
429 if( width && height )
432 job->height = height;
437 hb_fix_aspect( job, HB_KEEP_WIDTH );
441 job->height = height;
442 hb_fix_aspect( job, HB_KEEP_HEIGHT );
444 else if( !width && !height && !pixelratio )
446 hb_fix_aspect( job, HB_KEEP_WIDTH );
449 if( vquality >= 0.0 && vquality <= 1.0 )
451 job->vquality = vquality;
456 job->vquality = -1.0;
457 job->vbitrate = vbitrate;
461 job->vcodec = vcodec;
465 job->h264_level = 13;
469 job->h264_level = 30;
473 job->vrate = 27000000;
474 job->vrate_base = vrate;
483 if( strcasecmp( audios, "none" ) )
489 if( *tmp < '0' || *tmp > '9' )
491 /* Skip non numeric char */
495 job->audio_mixdowns[audio_count] = audio_mixdown;
496 job->audios[audio_count++] =
497 strtol( tmp, &tmp, 0 ) - 1;
499 job->audios[audio_count] = -1;
508 /* default to the first audio track if none has been specified */
510 job->audio_mixdowns[0] = audio_mixdown;
514 job->abitrate = abitrate;
518 job->acodec = acodec;
523 job->vbitrate = hb_calc_bitrate( job, size );
524 fprintf( stderr, "Calculated bitrate: %d kbps\n",
530 job->subtitle = sub - 1;
533 if( native_language )
535 job->native_language = strdup( native_language );
542 job->file = strdup( output );
549 if( x264opts != NULL && *x264opts != '\0' )
551 fprintf( stderr, "Applying the following x264 options: %s\n",
553 job->x264opts = x264opts;
555 else /*avoids a bus error crash when options aren't specified*/
557 job->x264opts = NULL;
560 job->maxWidth = maxWidth;
562 job->maxHeight = maxHeight;
567 * If subtitle_scan is enabled then only turn it on
568 * for the first pass and then off again for the
572 job->subtitle_scan = subtitle_scan;
575 fprintf( stderr, "Subtitle Scan Enabled - enabling "
576 "subtitles if found for foreign language segments\n");
577 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
578 *(job->select_subtitle) = NULL;
582 * If turbo options have been selected then append them
583 * to the x264opts now (size includes one ':' and the '\0')
585 if( turbo_opts_enabled )
587 int size = strlen(x264opts) + strlen(turbo_opts) + 2;
590 tmp_x264opts = malloc(size * sizeof(char));
593 snprintf( tmp_x264opts, size, "%s:%s",
594 x264opts, turbo_opts );
598 * No x264opts to modify, but apply the turbo options
599 * anyway as they may be modifying defaults
601 snprintf( tmp_x264opts, size, "%s",
604 x264opts = tmp_x264opts;
606 fprintf( stderr, "Modified x264 options for pass 1 to append turbo options: %s\n",
609 job->x264opts = x264opts;
614 * On the second pass we turn off subtitle scan so that we
615 * can actually encode using any subtitles that were auto
616 * selected in the first pass (using the whacky select-subtitle
617 * attribute of the job).
619 job->subtitle_scan = 0;
621 job->x264opts = x264opts2;
628 * Turn on subtitle scan if requested, note that this option
629 * precludes encoding of any actual subtitles.
631 job->subtitle_scan = subtitle_scan;
634 fprintf( stderr, "Subtitle Scan Enabled, will scan all "
635 "subtitles matching the audio language for any\n"
636 "that meet our auto-selection criteria.\n");
645 #define p s.param.working
646 case HB_STATE_WORKING:
647 fprintf( stderr, "\rEncoding: task %d of %d, %.2f %%",
648 p.job_cur, p.job_count, 100.0 * p.progress );
651 fprintf( stderr, " (%.2f fps, avg %.2f fps, ETA "
652 "%02dh%02dm%02ds)", p.rate_cur, p.rate_avg,
653 p.hours, p.minutes, p.seconds );
658 #define p s.param.muxing
659 case HB_STATE_MUXING:
661 fprintf( stderr, "\rMuxing: %.2f %%", 100.0 * p.progress );
666 #define p s.param.workdone
667 case HB_STATE_WORKDONE:
668 /* Print error if any, then exit */
672 fprintf( stderr, "\nRip done!\n" );
674 case HB_ERROR_CANCELED:
675 fprintf( stderr, "\nRip canceled.\n" );
678 fprintf( stderr, "\nRip failed (error %x).\n",
688 /****************************************************************************
690 ****************************************************************************/
691 static volatile int64_t i_die_date = 0;
692 void SigHandler( int i_signal )
697 i_die_date = hb_get_date();
698 fprintf( stderr, "Signal %d received, terminating - do it "
699 "again in case it gets stuck\n", i_signal );
701 else if( i_die_date + 500 < hb_get_date() )
703 fprintf( stderr, "Dying badly, files might remain in your /tmp\n" );
708 /****************************************************************************
710 ****************************************************************************/
711 static void ShowHelp()
716 "Syntax: HandBrakeCLI [options] -i <device> -o <file>\n"
718 "### General Handbrake Options------------------------------------------------\n\n"
719 " -h, --help Print help\n"
720 " -u, --update Check for updates and exit\n"
721 " -v, --verbose Be verbose\n"
722 " -C, --cpu Set CPU count (default: autodetected)\n"
725 "### Source Options-----------------------------------------------------------\n\n"
726 " -i, --input <string> Set input device\n"
727 " -t, --title <number> Select a title to encode (0 to scan only,\n"
729 " -L, --longest Select the longest title\n"
730 " -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n"
731 " 1 to 3, or \"3\" for chapter 3 only,\n"
732 " default: all chapters)\n"
735 "### Destination Options------------------------------------------------------\n\n"
736 " -o, --output <string> Set output file name\n"
737 " -f, --format <string> Set output format (avi/mp4/ogm, default:\n"
738 " autodetected from file name)\n"
741 "### Picture Settings---------------------------------------------------------\n\n"
742 " -w, --width <number> Set picture width\n"
743 " -l, --height <number> Set picture height\n"
744 " --crop <T:B:L:R> Set cropping values (default: autocrop)\n"
745 " -Y, --maxHeight <#> Set maximum height\n"
746 " -X, --maxWidth <#> Set maximum width\n"
747 " -s, --subtitle <number> Select subtitle (default: none)\n"
748 " -U, --subtitle-scan Scan for subtitles on the first pass, and choose\n"
749 " the one that's only used 20 percent of the time\n"
750 " or less. This should locate subtitles for short\n"
751 " foreign language segments. Only works with 2-pass.\n"
752 " -N, --native-language Select subtitles with this language if it does not\n"
753 " <string> match the Audio language. Provide the language's\n"
754 " iso639-2 code (fre, eng, spa, dut, et cetera)\n"
755 " -m, --markers Add chapter markers (mp4 output format only)\n"
758 "### Video Options------------------------------------------------------------\n\n"
759 " -e, --encoder <string> Set video library encoder (ffmpeg,xvid,\n"
760 " x264,x264b13,x264b30 default: ffmpeg)\n"
761 " -q, --quality <float> Set video quality (0.0..1.0)\n"
762 " -Q, --crf Use with -q for CRF instead of CQP\n"
763 " -S, --size <MB> Set target size\n"
764 " -b, --vb <kb/s> Set video bitrate (default: 1000)\n"
765 " -r, --rate Set video framerate (" );
766 for( i = 0; i < hb_video_rates_count; i++ )
768 fprintf( stderr, hb_video_rates[i].string );
769 if( i != hb_video_rates_count - 1 )
770 fprintf( stderr, "/" );
772 fprintf( stderr, ")\n"
774 " -2, --two-pass Use two-pass mode\n"
775 " -d, --deinterlace Deinterlace video\n"
776 " -g, --grayscale Grayscale encoding\n"
777 " -p, --pixelratio Store pixel aspect ratio in video stream\n"
782 "### Audio Options-----------------------------------------------------------\n\n"
783 " -E, --aencoder <string> Set audio encoder (faac/lame/vorbis/ac3, ac3\n"
784 " meaning passthrough, default: guessed)\n"
785 " -B, --ab <kb/s> Set audio bitrate (default: 128)\n"
786 " -a, --audio <string> Select audio channel(s) (\"none\" for no \n"
787 " audio, default: first one)\n"
788 " -6, --mixdown <string> Format for surround sound downmixing\n"
789 " (mono/stereo/dpl1/dpl2/6ch, default: dpl2)\n"
790 " -R, --arate Set audio samplerate (" );
791 for( i = 0; i < hb_audio_rates_count; i++ )
793 fprintf( stderr, hb_audio_rates[i].string );
794 if( i != hb_audio_rates_count - 1 )
795 fprintf( stderr, "/" );
797 fprintf( stderr, " kHz)\n"
804 "### Advanced H264 Options----------------------------------------------------\n\n"
805 " -x, --x264opts <string> Specify advanced x264 options in the\n"
806 " same style as mencoder:\n"
807 " option1=value1:option2=value2\n"
808 " -T, --turbo When using 2-pass use the turbo options\n"
809 " on the first pass to improve speed\n"
810 " (only works with x264, affects PSNR by about 0.05dB,\n"
811 " and increases first pass speed two to four times)\n");
814 /****************************************************************************
816 ****************************************************************************/
817 static int ParseOptions( int argc, char ** argv )
821 static struct option long_options[] =
823 { "help", no_argument, NULL, 'h' },
824 { "update", no_argument, NULL, 'u' },
825 { "verbose", no_argument, NULL, 'v' },
826 { "cpu", required_argument, NULL, 'C' },
828 { "format", required_argument, NULL, 'f' },
829 { "input", required_argument, NULL, 'i' },
830 { "output", required_argument, NULL, 'o' },
832 { "title", required_argument, NULL, 't' },
833 { "longest", no_argument, NULL, 'L' },
834 { "chapters", required_argument, NULL, 'c' },
835 { "markers", optional_argument, NULL, 'm' },
836 { "audio", required_argument, NULL, 'a' },
837 { "mixdown", required_argument, NULL, '6' },
838 { "subtitle", required_argument, NULL, 's' },
839 { "subtitle-scan", no_argument, NULL, 'U' },
840 { "native-language", required_argument, NULL,'N' },
842 { "encoder", required_argument, NULL, 'e' },
843 { "aencoder", required_argument, NULL, 'E' },
844 { "two-pass", no_argument, NULL, '2' },
845 { "deinterlace", no_argument, NULL, 'd' },
846 { "grayscale", no_argument, NULL, 'g' },
847 { "pixelratio", no_argument, NULL, 'p' },
848 { "width", required_argument, NULL, 'w' },
849 { "height", required_argument, NULL, 'l' },
850 { "crop", required_argument, NULL, 'n' },
852 { "vb", required_argument, NULL, 'b' },
853 { "quality", required_argument, NULL, 'q' },
854 { "size", required_argument, NULL, 'S' },
855 { "ab", required_argument, NULL, 'B' },
856 { "rate", required_argument, NULL, 'r' },
857 { "arate", required_argument, NULL, 'R' },
858 { "crf", no_argument, NULL, 'Q' },
859 { "x264opts", required_argument, NULL, 'x' },
860 { "turbo", no_argument, NULL, 'T' },
862 { "maxHeight", required_argument, NULL, 'Y' },
863 { "maxWidth", required_argument, NULL, 'X' },
868 int option_index = 0;
871 c = getopt_long( argc, argv,
872 "hvuC:f:i:o:t:Lc:ma:6:s:UN:e:E:2dgpw:l:n:b:q:S:B:r:R:Qx:TY:X:",
873 long_options, &option_index );
888 debug = HB_DEBUG_ALL;
891 cpu = atoi( optarg );
895 format = strdup( optarg );
898 input = strdup( optarg );
901 output = strdup( optarg );
905 titleindex = atoi( optarg );
913 if( sscanf( optarg, "%d-%d", &start, &end ) == 2 )
915 chapter_start = start;
918 else if( sscanf( optarg, "%d", &start ) == 1 )
920 chapter_start = start;
921 chapter_end = chapter_start;
925 fprintf( stderr, "chapters: invalid syntax (%s)\n",
934 marker_file = strdup( optarg );
939 audios = strdup( optarg );
942 if( !strcasecmp( optarg, "mono" ) )
944 audio_mixdown = HB_AMIXDOWN_MONO;
946 else if( !strcasecmp( optarg, "stereo" ) )
948 audio_mixdown = HB_AMIXDOWN_STEREO;
950 else if( !strcasecmp( optarg, "dpl1" ) )
952 audio_mixdown = HB_AMIXDOWN_DOLBY;
954 else if( !strcasecmp( optarg, "dpl2" ) )
956 audio_mixdown = HB_AMIXDOWN_DOLBYPLII;
958 else if( !strcasecmp( optarg, "6ch" ) )
960 audio_mixdown = HB_AMIXDOWN_6CH;
964 sub = atoi( optarg );
970 native_language = strdup( optarg );
985 if( !strcasecmp( optarg, "ffmpeg" ) )
987 vcodec = HB_VCODEC_FFMPEG;
989 else if( !strcasecmp( optarg, "xvid" ) )
991 vcodec = HB_VCODEC_XVID;
993 else if( !strcasecmp( optarg, "x264" ) )
995 vcodec = HB_VCODEC_X264;
997 else if( !strcasecmp( optarg, "x264b13" ) )
999 vcodec = HB_VCODEC_X264;
1002 else if( !strcasecmp( optarg, "x264b30" ) )
1004 vcodec = HB_VCODEC_X264;
1009 fprintf( stderr, "invalid codec (%s)\n", optarg );
1014 if( !strcasecmp( optarg, "ac3" ) )
1016 acodec = HB_ACODEC_AC3;
1018 else if( !strcasecmp( optarg, "lame" ) )
1020 acodec = HB_ACODEC_LAME;
1024 width = atoi( optarg );
1027 height = atoi( optarg );
1032 char * tmp = optarg;
1033 for( i = 0; i < 4; i++ )
1037 crop[i] = strtol( tmp, &tmp, 0 );
1046 for( i = 0; i < hb_video_rates_count; i++ )
1048 if( !strcmp( optarg, hb_video_rates[i].string ) )
1050 vrate = hb_video_rates[i].rate;
1056 fprintf( stderr, "invalid framerate %s\n", optarg );
1064 for( i = 0; i < hb_audio_rates_count; i++ )
1066 if( !strcmp( optarg, hb_audio_rates[i].string ) )
1068 arate = hb_audio_rates[i].rate;
1074 fprintf( stderr, "invalid framerate %s\n", optarg );
1079 vbitrate = atoi( optarg );
1082 vquality = atof( optarg );
1085 size = atoi( optarg );
1088 abitrate = atoi( optarg );
1094 x264opts = strdup( optarg );
1095 x264opts2 = strdup( optarg );
1098 turbo_opts_enabled = 1;
1101 maxHeight = atoi( optarg );
1104 maxWidth = atoi (optarg );
1108 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
1116 static int CheckOptions( int argc, char ** argv )
1123 if( input == NULL || *input == '\0' )
1125 fprintf( stderr, "Missing input device. Run %s --help for "
1126 "syntax.\n", argv[0] );
1131 if( titleindex > 0 )
1133 if( output == NULL || *output == '\0' )
1135 fprintf( stderr, "Missing output file name. Run %s --help "
1136 "for syntax.\n", argv[0] );
1142 char * p = strrchr( output, '.' );
1145 if( p && !strcasecmp( p, ".avi" ) )
1149 else if( p && ( !strcasecmp( p, ".mp4" ) ||
1150 !strcasecmp( p, ".m4v" ) ) )
1157 else if( p && ( !strcasecmp( p, ".ogm" ) ||
1158 !strcasecmp( p, ".ogg" ) ) )
1164 fprintf( stderr, "Output format couldn't be guessed "
1165 "from file name, using default.\n" );
1169 else if( !strcasecmp( format, "avi" ) )
1173 else if( !strcasecmp( format, "mp4" ) )
1180 else if( !strcasecmp( format, "ogm" ) ||
1181 !strcasecmp( format, "ogg" ) )
1187 fprintf( stderr, "Invalid output format (%s). Possible "
1188 "choices are avi, mp4 and ogm\n.", format );
1194 if( mux == HB_MUX_MP4 || mux == HB_MUX_IPOD )
1196 acodec = HB_ACODEC_FAAC;
1198 else if( mux == HB_MUX_AVI )
1200 acodec = HB_ACODEC_LAME;
1202 else if( mux == HB_MUX_OGM )
1204 acodec = HB_ACODEC_VORBIS;