+static int select_output( const char *muxer, char *filename, x264_param_t *param )
+{
+ const char *ext = get_filename_extension( filename );
+ if( !strcmp( filename, "-" ) || strcasecmp( muxer, "auto" ) )
+ ext = muxer;
+
+ if( !strcasecmp( ext, "mp4" ) )
+ {
+#ifdef MP4_OUTPUT
+ output = mp4_output;
+ param->b_annexb = 0;
+ param->b_aud = 0;
+ param->b_repeat_headers = 0;
+#else
+ fprintf( stderr, "x264 [error]: not compiled with MP4 output support\n" );
+ return -1;
+#endif
+ }
+ else if( !strcasecmp( ext, "mkv" ) )
+ {
+ output = mkv_output;
+ param->b_annexb = 0;
+ param->b_aud = 0;
+ param->b_repeat_headers = 0;
+ }
+ else if( !strcasecmp( ext, "flv" ) )
+ {
+ output = flv_output;
+ param->b_annexb = 0;
+ param->b_aud = 0;
+ param->b_repeat_headers = 0;
+ }
+ else
+ output = raw_output;
+ return 0;
+}
+
+static int select_input( const char *demuxer, char *used_demuxer, char *filename,
+ hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
+{
+ const char *ext = get_filename_extension( filename );
+ int b_regular = strcmp( filename, "-" );
+ int b_auto = !strcasecmp( demuxer, "auto" );
+ if( !b_regular && b_auto )
+ ext = "yuv";
+ if( b_regular )
+ {
+ FILE *f = fopen( filename, "r" );
+ if( !f )
+ {
+ fprintf( stderr, "x264 [error]: could not open input file `%s'\n", filename );
+ return -1;
+ }
+ b_regular = x264_is_regular_file( f );
+ fclose( f );
+ }
+ const char *module = b_auto ? ext : demuxer;
+
+ if( !strcasecmp( module, "avs" ) || !strcasecmp( ext, "d2v" ) || !strcasecmp( ext, "dga" ) )
+ {
+#ifdef AVS_INPUT
+ input = avs_input;
+ module = "avs";
+#else
+ fprintf( stderr, "x264 [error]: not compiled with AVS input support\n" );
+ return -1;
+#endif
+ }
+ else if( !strcasecmp( module, "y4m" ) )
+ input = y4m_input;
+ else if( !strcasecmp( module, "yuv" ) )
+ input = yuv_input;
+ else
+ {
+#ifdef FFMS_INPUT
+ if( b_regular && (b_auto || !strcasecmp( demuxer, "ffms" )) &&
+ !ffms_input.open_file( filename, p_handle, info, opt ) )
+ {
+ module = "ffms";
+ b_auto = 0;
+ input = ffms_input;
+ }
+#endif
+#ifdef LAVF_INPUT
+ if( (b_auto || !strcasecmp( demuxer, "lavf" )) &&
+ (!b_regular || !lavf_input.open_file( filename, p_handle, info, opt )) )
+ {
+ module = "lavf";
+ b_auto = 0;
+ input = lavf_input;
+ }
+#endif
+#ifdef AVS_INPUT
+ if( b_regular && (b_auto || !strcasecmp( demuxer, "avs" )) &&
+ !avs_input.open_file( filename, p_handle, info, opt ) )
+ {
+ module = "avs";
+ b_auto = 0;
+ input = avs_input;
+ }
+#endif
+ if( b_auto && !yuv_input.open_file( filename, p_handle, info, opt ) )
+ {
+ module = "yuv";
+ b_auto = 0;
+ input = yuv_input;
+ }
+
+ if( !(*p_handle) )
+ {
+ fprintf( stderr, "x264 [error]: could not open input file `%s' via any method!\n", filename );
+ return -1;
+ }
+ }
+ strcpy( used_demuxer, module );
+
+ return 0;
+}
+