OSDN Git Service

Update 2006-01-10
[handbrake-jp/handbrake-jp-git.git] / test / test.c
1 /* $Id: test.c,v 1.82 2005/11/19 08:25:54 titer Exp $
2
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. */
6
7 #include <signal.h>
8 #include <getopt.h>
9
10 #include "hb.h"
11
12 /* Options */
13 static int    debug       = HB_DEBUG_NONE;
14 static int    update      = 0;
15 static char * input       = NULL;
16 static char * output      = NULL;
17 static char * format      = NULL;
18 static int    titleindex  = 1;
19 static int    twoPass     = 0;
20 static int    deinterlace = 0;
21 static int    grayscale   = 0;
22 static int    vcodec      = HB_VCODEC_FFMPEG;
23 static int    h264_13     = 0;
24 static char * audios      = NULL;
25 static int    sub         = 0;
26 static int    width       = 0;
27 static int    height      = 0;
28 static int    crop[4]     = { -1,-1,-1,-1 };
29 static int    cpu         = 0;
30 static int    vrate       = 0;
31 static int    arate       = 0;
32 static float  vquality    = -1.0;
33 static int    vbitrate    = 0;
34 static int    size        = 0;
35 static int    abitrate    = 0;
36 static int    mux         = 0;
37 static int    acodec      = 0;
38 static int    chapter_start = 0;
39 static int    chapter_end   = 0;
40
41 /* Exit cleanly on Ctrl-C */
42 static volatile int die = 0;
43 static void SigHandler( int );
44
45 /* Utils */
46 static void ShowCommands();
47 static void ShowHelp();
48 static int  ParseOptions( int argc, char ** argv );
49 static int  CheckOptions( int argc, char ** argv );
50 static int  HandleEvents( hb_handle_t * h );
51
52 int main( int argc, char ** argv )
53 {
54     hb_handle_t * h;
55     int           build;
56     char        * version;
57
58     /* Parse command line */
59     if( ParseOptions( argc, argv ) ||
60         CheckOptions( argc, argv ) )
61     {
62         return 1;
63     }
64
65     /* Init libhb */
66     h = hb_init( debug, update );
67
68     /* Show version */
69     fprintf( stderr, "HandBrake %s (%d) - http://handbrake.m0k.org/\n",
70              hb_get_version( h ), hb_get_build( h ) );
71
72     /* Check for update */
73     if( update )
74     {
75         if( ( build = hb_check_update( h, &version ) ) > -1 )
76         {
77             fprintf( stderr, "You are using an old version of "
78                      "HandBrake.\nLatest is %s (build %d).\n", version,
79                      build );
80         }
81         else
82         {
83             fprintf( stderr, "Your version of HandBrake is up to "
84                      "date.\n" );
85         }
86         hb_close( &h );
87         return 0;
88     }
89
90     /* Geeky */
91     fprintf( stderr, "%d CPU%s detected\n", hb_get_cpu_count(),
92              hb_get_cpu_count( h ) > 1 ? "s" : "" );
93     if( cpu )
94     {
95         fprintf( stderr, "Forcing %d CPU%s\n", cpu,
96                  cpu > 1 ? "s" : "" );
97         hb_set_cpu_count( h, cpu );
98     }
99
100     /* Exit ASAP on Ctrl-C */
101     signal( SIGINT, SigHandler );
102
103     /* Feed libhb with a DVD to scan */
104     fprintf( stderr, "Opening %s...\n", input );
105     hb_scan( h, input, titleindex );
106
107     /* Wait... */
108     while( !die )
109     {
110 #if !defined(SYS_BEOS)
111         fd_set         fds;
112         struct timeval tv;
113         int            ret;
114         char           buf[257];
115
116         tv.tv_sec  = 0;
117         tv.tv_usec = 100000;
118
119         FD_ZERO( &fds );
120         FD_SET( STDIN_FILENO, &fds );
121         ret = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
122
123         if( ret > 0 )
124         {
125             int size = 0;
126
127             while( size < 256 &&
128                    read( STDIN_FILENO, &buf[size], 1 ) > 0 )
129             {
130                 if( buf[size] == '\n' )
131                 {
132                     break;
133                 }
134                 size++;
135             }
136
137             if( size >= 256 || buf[size] == '\n' )
138             {
139                 switch( buf[0] )
140                 {
141                     case 'q':
142                         die = 1;
143                         break;
144                     case 'p':
145                         hb_pause( h );
146                         break;
147                     case 'r':
148                         hb_resume( h );
149                         break;
150                     case 'h':
151                         ShowCommands();
152                         break;
153                 }
154             }
155         }
156 #else
157         hb_snooze( 200 );
158 #endif
159
160         HandleEvents( h );
161     }
162
163     /* Clean up */
164     hb_close( &h );
165     if( input )  free( input );
166     if( output ) free( output );
167     if( format ) free( format );
168     if( audios ) free( audios );
169
170     fprintf( stderr, "HandBrake has exited.\n" );
171
172     return 0;
173 }
174
175 static void ShowCommands()
176 {
177     fprintf( stderr, "Commands:\n" );
178     fprintf( stderr, " [h]elp    Show this message\n" );
179     fprintf( stderr, " [q]uit    Exit HBTest\n" );
180     fprintf( stderr, " [p]ause   Pause encoding\n" );
181     fprintf( stderr, " [r]esume  Resume encoding\n" );
182 }
183
184 static void PrintTitleInfo( hb_title_t * title )
185 {
186     hb_chapter_t  * chapter;
187     hb_audio_t    * audio;
188     hb_subtitle_t * subtitle;
189     int i;
190
191     fprintf( stderr, "+ title %d:\n", title->index );
192     fprintf( stderr, "  + vts %d, ttn %d, cells %d->%d (%d blocks)\n",
193              title->vts, title->ttn, title->cell_start, title->cell_end,
194              title->block_count );
195     fprintf( stderr, "  + duration: %02d:%02d:%02d\n",
196              title->hours, title->minutes, title->seconds );
197     fprintf( stderr, "  + size: %dx%d, aspect: %.2f, %.3f fps\n",
198              title->width, title->height,
199              (float) title->aspect / HB_ASPECT_BASE,
200              (float) title->rate / title->rate_base );
201     fprintf( stderr, "  + autocrop: %d/%d/%d/%d\n", title->crop[0],
202              title->crop[1], title->crop[2], title->crop[3] );
203     fprintf( stderr, "  + chapters:\n" );
204     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
205     {
206         chapter = hb_list_item( title->list_chapter, i );
207         fprintf( stderr, "    + %d: cells %d->%d, %d blocks, duration "
208                  "%02d:%02d:%02d\n", chapter->index,
209                  chapter->cell_start, chapter->cell_end,
210                  chapter->block_count, chapter->hours, chapter->minutes,
211                  chapter->seconds );
212     }
213     fprintf( stderr, "  + audio tracks:\n" );
214     for( i = 0; i < hb_list_count( title->list_audio ); i++ )
215     {
216         audio = hb_list_item( title->list_audio, i );
217         if( audio->codec & HB_ACODEC_AC3 )
218         {
219             fprintf( stderr, "    + %x, %s, %dHz, %dbps\n", audio->id,
220                      audio->lang, audio->rate, audio->bitrate );
221         }
222         else
223         {
224             fprintf( stderr, "    + %x, %s\n", audio->id, audio->lang );
225         }
226     }
227     fprintf( stderr, "  + subtitle tracks:\n" );
228     for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
229     {
230         subtitle = hb_list_item( title->list_subtitle, i );
231         fprintf( stderr, "    + %x, %s\n", subtitle->id, subtitle->lang );
232     }
233 }
234
235 static int HandleEvents( hb_handle_t * h )
236 {
237     hb_state_t s;
238     hb_get_state( h, &s );
239     switch( s.state )
240     {
241         case HB_STATE_IDLE:
242             /* Nothing to do */
243             break;
244
245 #define p s.param.scanning
246         case HB_STATE_SCANNING:
247             /* Show what title is currently being scanned */
248             fprintf( stderr, "Scanning title %d", p.title_cur );
249             if( !titleindex )
250                 fprintf( stderr, " of %d", p.title_count );
251             fprintf( stderr, "...\n" );
252             break;
253 #undef p
254
255         case HB_STATE_SCANDONE:
256         {
257             hb_list_t  * list;
258             hb_title_t * title;
259             hb_job_t   * job;
260
261             list = hb_get_titles( h );
262
263             if( !hb_list_count( list ) )
264             {
265                 /* No valid title, stop right there */
266                 fprintf( stderr, "No title found.\n" );
267                 die = 1;
268                 break;
269             }
270             if( !titleindex )
271             {
272                 /* Scan-only mode, print infos and exit */
273                 int i;
274                 for( i = 0; i < hb_list_count( list ); i++ )
275                 {
276                     title = hb_list_item( list, i );
277                     PrintTitleInfo( title );
278                 }
279                 die = 1;
280                 break;
281             }
282
283             /* Set job settings */
284             title = hb_list_item( list, 0 );
285             job   = title->job;
286
287             PrintTitleInfo( title );
288
289             if( chapter_start && chapter_end )
290             {
291                 job->chapter_start = MAX( job->chapter_start,
292                                           chapter_start );
293                 job->chapter_end   = MIN( job->chapter_end,
294                                           chapter_end );
295                 job->chapter_end   = MAX( job->chapter_start,
296                                           job->chapter_end );
297             }
298
299             if( crop[0] >= 0 && crop[1] >= 0 &&
300                 crop[2] >= 0 && crop[3] >= 0 )
301             {
302                 memcpy( job->crop, crop, 4 * sizeof( int ) );
303             }
304
305             job->deinterlace = deinterlace;
306             job->grayscale   = grayscale;
307
308             if( width && height )
309             {
310                 job->width  = width;
311                 job->height = height;
312             }
313             else if( width )
314             {
315                 job->width = width;
316                 hb_fix_aspect( job, HB_KEEP_WIDTH );
317             }
318             else if( height )
319             {
320                 job->height = height;
321                 hb_fix_aspect( job, HB_KEEP_HEIGHT );
322             }
323             else
324             {
325                 hb_fix_aspect( job, HB_KEEP_WIDTH );
326             }
327
328             if( vquality >= 0.0 && vquality <= 1.0 )
329             {
330                 job->vquality = vquality;
331                 job->vbitrate = 0;
332             }
333             else if( vbitrate )
334             {
335                 job->vquality = -1.0;
336                 job->vbitrate = vbitrate;
337             }
338             if( vcodec )
339             {
340                 job->vcodec = vcodec;
341             }
342             if( h264_13 ) 
343             { 
344                 job->h264_13 = h264_13; 
345             } 
346             if( vrate )
347             {
348                 job->vrate = 27000000;
349                 job->vrate_base = vrate;
350             }
351             if( arate )
352             {
353                 job->arate = arate;
354             }
355
356             if( audios )
357             {
358                 if( strcasecmp( audios, "none" ) )
359                 {
360                     int    audio_count = 0;
361                     char * tmp         = audios;
362                     while( *tmp )
363                     {
364                         if( *tmp < '0' || *tmp > '9' )
365                         {
366                             /* Skip non numeric char */
367                             tmp++;
368                             continue;
369                         }
370                         job->audios[audio_count++] =
371                             strtol( tmp, &tmp, 0 ) - 1;
372                     }
373                     job->audios[audio_count] = -1;
374                 }
375                 else
376                 {
377                     job->audios[0] = -1;
378                 }
379             }
380             if( abitrate )
381             {
382                 job->abitrate = abitrate;
383             }
384             if( acodec )
385             {
386                 job->acodec = acodec;
387             }
388
389             if( size )
390             {
391                 job->vbitrate = hb_calc_bitrate( job, size );
392                 fprintf( stderr, "Calculated bitrate: %d kbps\n",
393                          job->vbitrate );
394             }
395             
396             if( sub )
397             {
398                 job->subtitle = sub - 1;
399             }
400
401             if( job->mux )
402             {
403                 job->mux = mux;
404             }
405             job->file = strdup( output );
406
407             if( twoPass )
408             {
409                 job->pass = 1;
410                 hb_add( h, job );
411                 job->pass = 2;
412                 hb_add( h, job );
413             }
414             else
415             {
416                 job->pass = 0;
417                 hb_add( h, job );
418             }
419             hb_start( h );
420             break;
421         }
422
423 #define p s.param.working
424         case HB_STATE_WORKING:
425             fprintf( stderr, "\rEncoding: task %d of %d, %.2f %%",
426                      p.job_cur, p.job_count, 100.0 * p.progress );
427             if( p.seconds > -1 )
428             {
429                 fprintf( stderr, " (%.2f fps, avg %.2f fps, ETA "
430                          "%02dh%02dm%02ds)", p.rate_cur, p.rate_avg,
431                          p.hours, p.minutes, p.seconds );
432             }
433             break;
434 #undef p
435
436 #define p s.param.workdone
437         case HB_STATE_WORKDONE:
438             /* Print error if any, then exit */
439             switch( p.error )
440             {
441                 case HB_ERROR_NONE:
442                     fprintf( stderr, "\nRip done!\n" );
443                     break;
444                 case HB_ERROR_CANCELED:
445                     fprintf( stderr, "\nRip canceled.\n" );
446                     break;
447                 default:
448                     fprintf( stderr, "\nRip failed (error %x).\n",
449                              p.error );
450             }
451             die = 1;
452             break;
453 #undef p
454     }
455     return 0;
456 }
457
458 /****************************************************************************
459  * SigHandler:
460  ****************************************************************************/
461 static volatile int64_t i_die_date = 0;
462 void SigHandler( int i_signal )
463 {
464     if( die == 0 )
465     {
466         die = 1;
467         i_die_date = hb_get_date();
468         fprintf( stderr, "Signal %d received, terminating - do it "
469                  "again in case it gets stuck\n", i_signal );
470     }
471     else if( i_die_date + 500 < hb_get_date() )
472     {
473         fprintf( stderr, "Dying badly, files might remain in your /tmp\n" );
474         exit( 1 );
475     }
476 }
477
478 /****************************************************************************
479  * ShowHelp:
480  ****************************************************************************/
481 static void ShowHelp()
482 {
483     int i;
484     
485     fprintf( stderr,
486     "Syntax: HBTest [options] -i <device> -o <file>\n"
487     "\n"
488     "    -h, --help              Print help\n"
489     "    -u, --update            Check for updates and exit\n"
490     "    -v, --verbose           Be verbose\n"
491     "    -C, --cpu               Set CPU count (default: autodetected)\n"
492     "\n"
493     "    -f, --format <string>   Set output format (avi/mp4/ogm, default:\n"
494     "                            autodetected from file name)\n"
495     "    -i, --input <string>    Set input device\n"
496     "    -o, --output <string>   Set output file name\n"
497     "\n"
498     "    -t, --title <number>    Select a title to encode (0 to scan only,\n"
499     "                            default: 1)\n"
500     "    -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n"
501     "                            1 to 3, or \"3\" for chapter 3 only,\n"
502     "                            default: all chapters)\n"
503     "    -a, --audio <string>    Select audio channel(s) (\"none\" for no \n"
504     "                            audio, default: first one)\n"
505     "\n"
506     "    -s, --subtitle <number> Select subtitle (default: none)\n"
507     "    -e, --encoder <string>  Set video library encoder (ffmpeg,xvid,\n"
508     "                            x264,x264b13, default: ffmpeg)\n"
509     "    -E, --aencoder <string> Set audio encoder (faac/lame/vorbis/ac3, ac3\n"
510     "                            meaning passthrough, default: guessed)\n"
511     "    -2, --two-pass          Use two-pass mode\n"
512     "    -d, --deinterlace       Deinterlace video\n"
513     "    -g, --grayscale         Grayscale encoding\n"
514     "\n"
515     "    -r, --rate              Set video framerate (" );
516     for( i = 0; i < hb_video_rates_count; i++ )
517     {
518         fprintf( stderr, hb_video_rates[i].string );
519         if( i != hb_video_rates_count - 1 )
520             fprintf( stderr, "/" );
521     }
522     fprintf( stderr, ")\n"
523     "    -R, --arate             Set audio samplerate (" );
524     for( i = 0; i < hb_audio_rates_count; i++ )
525     {
526         fprintf( stderr, hb_audio_rates[i].string );
527         if( i != hb_audio_rates_count - 1 )
528             fprintf( stderr, "/" );
529     }
530     fprintf( stderr, ")\n"
531     "    -b, --vb <kb/s>         Set video bitrate (default: 1000)\n"
532     "    -q, --quality <float>   Set video quality (0.0..1.0)\n"
533     "    -S, --size <MB>         Set target size\n"
534     "    -B, --ab <kb/s>         Set audio bitrate (default: 128)\n"
535     "    -w, --width <number>    Set picture width\n"
536     "    -l, --height <number>   Set picture height\n"
537     "        --crop <T:B:L:R>    Set cropping values (default: autocrop)\n" );
538 }
539
540 /****************************************************************************
541  * ParseOptions:
542  ****************************************************************************/
543 static int ParseOptions( int argc, char ** argv )
544 {
545     for( ;; )
546     {
547         static struct option long_options[] =
548           {
549             { "help",        no_argument,       NULL,    'h' },
550             { "update",      no_argument,       NULL,    'u' },
551             { "verbose",     no_argument,       NULL,    'v' },
552             { "cpu",         required_argument, NULL,    'C' },
553
554             { "format",      required_argument, NULL,    'f' },
555             { "input",       required_argument, NULL,    'i' },
556             { "output",      required_argument, NULL,    'o' },
557
558             { "title",       required_argument, NULL,    't' },
559             { "chapters",    required_argument, NULL,    'c' },
560             { "audio",       required_argument, NULL,    'a' },
561             { "subtitle",    required_argument, NULL,    's' },
562
563             { "encoder",     required_argument, NULL,    'e' },
564             { "aencoder",    required_argument, NULL,    'E' },
565             { "two-pass",    no_argument,       NULL,    '2' },
566             { "deinterlace", no_argument,       NULL,    'd' },
567             { "grayscale",   no_argument,       NULL,    'g' },
568             { "width",       required_argument, NULL,    'w' },
569             { "height",      required_argument, NULL,    'l' },
570             { "crop",        required_argument, NULL,    'n' },
571
572             { "vb",          required_argument, NULL,    'b' },
573             { "quality",     required_argument, NULL,    'q' },
574             { "size",        required_argument, NULL,    'S' },
575             { "ab",          required_argument, NULL,    'B' },
576             { "rate",        required_argument, NULL,    'r' },
577             { "arate",       required_argument, NULL,    'R' },
578
579             { 0, 0, 0, 0 }
580           };
581
582         int option_index = 0;
583         int c;
584
585         c = getopt_long( argc, argv,
586                          "hvuC:f:i:o:t:c:a:s:e:E:2dgw:l:n:b:q:S:B:r:R:",
587                          long_options, &option_index );
588         if( c < 0 )
589         {
590             break;
591         }
592
593         switch( c )
594         {
595             case 'h':
596                 ShowHelp();
597                 exit( 0 );
598             case 'u':
599                 update = 1;
600                 break;
601             case 'v':
602                 debug = HB_DEBUG_ALL;
603                 break;
604             case 'C':
605                 cpu = atoi( optarg );
606                 break;
607
608             case 'f':
609                 format = strdup( optarg );
610                 break;
611             case 'i':
612                 input = strdup( optarg );
613                 break;
614             case 'o':
615                 output = strdup( optarg );
616                 break;
617
618             case 't':
619                 titleindex = atoi( optarg );
620                 break;
621             case 'c':
622             {
623                 int start, end;
624                 if( sscanf( optarg, "%d-%d", &start, &end ) == 2 )
625                 {
626                     chapter_start = start;
627                     chapter_end   = end;
628                 }
629                 else if( sscanf( optarg, "%d", &start ) == 1 )
630                 {
631                     chapter_start = start;
632                     chapter_end   = chapter_start;
633                 }
634                 else
635                 {
636                     fprintf( stderr, "chapters: invalid syntax (%s)\n",
637                              optarg );
638                     return -1;
639                 }
640                 break;
641             }
642             case 'a':
643                 audios = strdup( optarg );
644                 break;
645             case 's':
646                 sub = atoi( optarg );
647                 break;
648
649             case '2':
650                 twoPass = 1;
651                 break;
652             case 'd':
653                 deinterlace = 1;
654                 break;
655             case 'g':
656                 grayscale = 1;
657                 break;
658             case 'e':
659                 if( !strcasecmp( optarg, "ffmpeg" ) )
660                 {
661                     vcodec = HB_VCODEC_FFMPEG;
662                 }
663                 else if( !strcasecmp( optarg, "xvid" ) )
664                 {
665                     vcodec = HB_VCODEC_XVID;
666                 }
667                 else if( !strcasecmp( optarg, "x264" ) )
668                 {
669                     vcodec = HB_VCODEC_X264;
670                 }
671                 else if( !strcasecmp( optarg, "x264b13" ) )
672                 {
673                     vcodec = HB_VCODEC_X264;
674                     h264_13 = 1;
675                 }
676                 else
677                 {
678                     fprintf( stderr, "invalid codec (%s)\n", optarg );
679                     return -1;
680                 }
681                 break;
682             case 'E':
683                 if( !strcasecmp( optarg, "ac3" ) )
684                 {
685                     acodec = HB_ACODEC_AC3;
686                 }
687                 else if( !strcasecmp( optarg, "lame" ) )
688                 {
689                     acodec = HB_ACODEC_LAME;
690                 }
691                 break;
692             case 'w':
693                 width = atoi( optarg );
694                 break;
695             case 'l':
696                 height = atoi( optarg );
697                 break;
698             case 'n':
699             {
700                 int    i;
701                 char * tmp = optarg;
702                 for( i = 0; i < 4; i++ )
703                 {
704                     if( !*tmp )
705                         break;
706                     crop[i] = strtol( tmp, &tmp, 0 );
707                     tmp++;
708                 }
709                 break;
710             }
711             case 'r':
712             {
713                 int i;
714                 vrate = 0;
715                 for( i = 0; i < hb_video_rates_count; i++ )
716                 {
717                     if( !strcmp( optarg, hb_video_rates[i].string ) )
718                     {
719                         vrate = hb_video_rates[i].rate;
720                         break;
721                     }
722                 }
723                 if( !vrate )
724                 {
725                     fprintf( stderr, "invalid framerate %s\n", optarg );
726                 }
727                 break;
728             }
729             case 'R':
730             {
731                 int i;
732                 arate = 0;
733                 for( i = 0; i < hb_audio_rates_count; i++ )
734                 {
735                     if( !strcmp( optarg, hb_audio_rates[i].string ) )
736                     {
737                         arate = hb_audio_rates[i].rate;
738                         break;
739                     }
740                 }
741                 if( !arate )
742                 {
743                     fprintf( stderr, "invalid framerate %s\n", optarg );
744                 }
745                 break;
746             }
747             case 'b':
748                 vbitrate = atoi( optarg );
749                 break;
750             case 'q':
751                 vquality = atof( optarg );
752                 break;
753             case 'S':
754                 size = atoi( optarg );
755                 break;
756             case 'B':
757                 abitrate = atoi( optarg );
758                 break;
759
760             default:
761                 fprintf( stderr, "unknown option (%s)\n", argv[optind] );
762                 return -1;
763         }
764     }
765
766     return 0;
767 }
768
769 static int CheckOptions( int argc, char ** argv )
770 {
771     if( update )
772     {
773         return 0;
774     }
775
776     if( input == NULL || *input == '\0' )
777     {
778         fprintf( stderr, "Missing input device. Run %s --help for "
779                  "syntax.\n", argv[0] );
780         return 1;
781     }
782
783     /* Parse format */
784     if( titleindex > 0 )
785     {
786         if( output == NULL || *output == '\0' )
787         {
788             fprintf( stderr, "Missing output file name. Run %s --help "
789                      "for syntax.\n", argv[0] );
790             return 1;
791         }
792
793         if( !format )
794         {
795             char * p = strrchr( output, '.' );
796
797             /* autodetect */
798             if( p && !strcasecmp( p, ".avi" ) )
799             {
800                 mux = HB_MUX_AVI;
801             }
802             else if( p && !strcasecmp( p, ".mp4" ) )
803             {
804                 mux = HB_MUX_MP4;
805             }
806             else if( p && ( !strcasecmp( p, ".ogm" ) ||
807                             !strcasecmp( p, ".ogg" ) ) )
808             {
809                 mux = HB_MUX_OGM;
810             }
811             else
812             {
813                 fprintf( stderr, "Output format couldn't be guessed "
814                          "from file name, using default.\n" );
815                 return 0;
816             }
817         }
818         else if( !strcasecmp( format, "avi" ) )
819         {
820             mux = HB_MUX_AVI;
821         }
822         else if( !strcasecmp( format, "mp4" ) )
823         {
824             mux = HB_MUX_MP4;
825         }
826         else if( !strcasecmp( format, "ogm" ) ||
827                  !strcasecmp( format, "ogg" ) )
828         {
829             mux = HB_MUX_OGM;
830         }
831         else
832         {
833             fprintf( stderr, "Invalid output format (%s). Possible "
834                      "choices are avi, mp4 and ogm\n.", format );
835             return 1;
836         }
837
838         if( !acodec )
839         {
840             if( mux == HB_MUX_MP4 )
841             {
842                 acodec = HB_ACODEC_FAAC;
843             }
844             else if( mux == HB_MUX_AVI )
845             {
846                 acodec = HB_ACODEC_LAME;
847             }
848             else if( mux == HB_MUX_OGM )
849             {
850                 acodec = HB_ACODEC_VORBIS;
851             }
852         }
853     }
854
855     return 0;
856 }
857