+#define OPT_FRAMES 256
+#define OPT_SEEK 257
+#define OPT_QPFILE 258
+#define OPT_THREAD_INPUT 259
+#define OPT_QUIET 260
+#define OPT_NOPROGRESS 261
+#define OPT_VISUALIZE 262
+#define OPT_LONGHELP 263
+#define OPT_PROFILE 264
+#define OPT_PRESET 265
+#define OPT_TUNE 266
+#define OPT_SLOWFIRSTPASS 267
+#define OPT_FULLHELP 268
+#define OPT_FPS 269
+#define OPT_STDOUT_FORMAT 270
+#define OPT_STDIN_FORMAT 271
+
+static char short_options[] = "8A:B:b:f:hI:i:m:o:p:q:r:t:Vvw";
+static struct option long_options[] =
+{
+ { "help", no_argument, NULL, 'h' },
+ { "longhelp", no_argument, NULL, OPT_LONGHELP },
+ { "fullhelp", no_argument, NULL, OPT_FULLHELP },
+ { "version", no_argument, NULL, 'V' },
+ { "profile", required_argument, NULL, OPT_PROFILE },
+ { "preset", required_argument, NULL, OPT_PRESET },
+ { "tune", required_argument, NULL, OPT_TUNE },
+ { "slow-firstpass", no_argument, NULL, OPT_SLOWFIRSTPASS },
+ { "bitrate", required_argument, NULL, 'B' },
+ { "bframes", required_argument, NULL, 'b' },
+ { "b-adapt", required_argument, NULL, 0 },
+ { "no-b-adapt", no_argument, NULL, 0 },
+ { "b-bias", required_argument, NULL, 0 },
+ { "b-pyramid", required_argument, NULL, 0 },
+ { "min-keyint", required_argument, NULL, 'i' },
+ { "keyint", required_argument, NULL, 'I' },
+ { "scenecut", required_argument, NULL, 0 },
+ { "no-scenecut", no_argument, NULL, 0 },
+ { "nf", no_argument, NULL, 0 },
+ { "no-deblock", no_argument, NULL, 0 },
+ { "filter", required_argument, NULL, 0 },
+ { "deblock", required_argument, NULL, 'f' },
+ { "interlaced", no_argument, NULL, 0 },
+ { "constrained-intra", no_argument, NULL, 0 },
+ { "cabac", no_argument, NULL, 0 },
+ { "no-cabac", no_argument, NULL, 0 },
+ { "qp", required_argument, NULL, 'q' },
+ { "qpmin", required_argument, NULL, 0 },
+ { "qpmax", required_argument, NULL, 0 },
+ { "qpstep", required_argument, NULL, 0 },
+ { "crf", required_argument, NULL, 0 },
+ { "rc-lookahead",required_argument, NULL, 0 },
+ { "ref", required_argument, NULL, 'r' },
+ { "asm", required_argument, NULL, 0 },
+ { "no-asm", no_argument, NULL, 0 },
+ { "sar", required_argument, NULL, 0 },
+ { "fps", required_argument, NULL, OPT_FPS },
+ { "frames", required_argument, NULL, OPT_FRAMES },
+ { "seek", required_argument, NULL, OPT_SEEK },
+ { "output", required_argument, NULL, 'o' },
+ { "stdout", required_argument, NULL, OPT_STDOUT_FORMAT },
+ { "stdin", required_argument, NULL, OPT_STDIN_FORMAT },
+ { "analyse", required_argument, NULL, 0 },
+ { "partitions", required_argument, NULL, 'A' },
+ { "direct", required_argument, NULL, 0 },
+ { "weightb", no_argument, NULL, 'w' },
+ { "no-weightb", no_argument, NULL, 0 },
+ { "weightp", required_argument, NULL, 0 },
+ { "me", required_argument, NULL, 0 },
+ { "merange", required_argument, NULL, 0 },
+ { "mvrange", required_argument, NULL, 0 },
+ { "mvrange-thread", required_argument, NULL, 0 },
+ { "subme", required_argument, NULL, 'm' },
+ { "psy-rd", required_argument, NULL, 0 },
+ { "no-psy", no_argument, NULL, 0 },
+ { "psy", no_argument, NULL, 0 },
+ { "mixed-refs", no_argument, NULL, 0 },
+ { "no-mixed-refs", no_argument, NULL, 0 },
+ { "no-chroma-me", no_argument, NULL, 0 },
+ { "8x8dct", no_argument, NULL, 0 },
+ { "no-8x8dct", no_argument, NULL, 0 },
+ { "trellis", required_argument, NULL, 't' },
+ { "fast-pskip", no_argument, NULL, 0 },
+ { "no-fast-pskip", no_argument, NULL, 0 },
+ { "no-dct-decimate", no_argument, NULL, 0 },
+ { "aq-strength", required_argument, NULL, 0 },
+ { "aq-mode", required_argument, NULL, 0 },
+ { "deadzone-inter", required_argument, NULL, '0' },
+ { "deadzone-intra", required_argument, NULL, '0' },
+ { "level", required_argument, NULL, 0 },
+ { "ratetol", required_argument, NULL, 0 },
+ { "vbv-maxrate", required_argument, NULL, 0 },
+ { "vbv-bufsize", required_argument, NULL, 0 },
+ { "vbv-init", required_argument, NULL, 0 },
+ { "ipratio", required_argument, NULL, 0 },
+ { "pbratio", required_argument, NULL, 0 },
+ { "chroma-qp-offset", required_argument, NULL, 0 },
+ { "pass", required_argument, NULL, 'p' },
+ { "stats", required_argument, NULL, 0 },
+ { "qcomp", required_argument, NULL, 0 },
+ { "mbtree", no_argument, NULL, 0 },
+ { "no-mbtree", no_argument, NULL, 0 },
+ { "qblur", required_argument, NULL, 0 },
+ { "cplxblur", required_argument, NULL, 0 },
+ { "zones", required_argument, NULL, 0 },
+ { "qpfile", required_argument, NULL, OPT_QPFILE },
+ { "threads", required_argument, NULL, 0 },
+ { "sliced-threads", no_argument, NULL, 0 },
+ { "no-sliced-threads", no_argument, NULL, 0 },
+ { "slice-max-size", required_argument, NULL, 0 },
+ { "slice-max-mbs", required_argument, NULL, 0 },
+ { "slices", required_argument, NULL, 0 },
+ { "thread-input", no_argument, NULL, OPT_THREAD_INPUT },
+ { "sync-lookahead", required_argument, NULL, 0 },
+ { "non-deterministic", no_argument, NULL, 0 },
+ { "psnr", no_argument, NULL, 0 },
+ { "ssim", no_argument, NULL, 0 },
+ { "quiet", no_argument, NULL, OPT_QUIET },
+ { "verbose", no_argument, NULL, 'v' },
+ { "no-progress", no_argument, NULL, OPT_NOPROGRESS },
+ { "visualize", no_argument, NULL, OPT_VISUALIZE },
+ { "dump-yuv", required_argument, NULL, 0 },
+ { "sps-id", required_argument, NULL, 0 },
+ { "aud", no_argument, NULL, 0 },
+ { "nr", required_argument, NULL, 0 },
+ { "cqm", required_argument, NULL, 0 },
+ { "cqmfile", required_argument, NULL, 0 },
+ { "cqm4", required_argument, NULL, 0 },
+ { "cqm4i", required_argument, NULL, 0 },
+ { "cqm4iy", required_argument, NULL, 0 },
+ { "cqm4ic", required_argument, NULL, 0 },
+ { "cqm4p", required_argument, NULL, 0 },
+ { "cqm4py", required_argument, NULL, 0 },
+ { "cqm4pc", required_argument, NULL, 0 },
+ { "cqm8", required_argument, NULL, 0 },
+ { "cqm8i", required_argument, NULL, 0 },
+ { "cqm8p", required_argument, NULL, 0 },
+ { "overscan", required_argument, NULL, 0 },
+ { "videoformat", required_argument, NULL, 0 },
+ { "fullrange", required_argument, NULL, 0 },
+ { "colorprim", required_argument, NULL, 0 },
+ { "transfer", required_argument, NULL, 0 },
+ { "colormatrix", required_argument, NULL, 0 },
+ { "chromaloc", required_argument, NULL, 0 },
+ {0, 0, 0, 0}
+};
+
+static int select_output( char *filename, const char *pipe_format, x264_param_t *param )
+{
+ const char *ext = get_filename_extension( filename );
+ if( !strcmp( filename, "-" ) )
+ ext = pipe_format;
+
+ if( !strcasecmp( ext, "mp4" ) )
+ {
+#ifdef MP4_OUTPUT
+ output = mp4_output; // FIXME use b_annexb=0
+#else
+ fprintf( stderr, "x264 [error]: not compiled with MP4 output support\n" );
+ return -1;
+#endif
+ }
+ else if( !strcasecmp( ext, "mkv" ) )
+ output = mkv_output; // FIXME use b_annexb=0
+ else if( !strcasecmp( ext, "flv" ) )
+ {
+ output = flv_output;
+ param->b_annexb = 0;
+ }
+ else
+ output = raw_output;
+ return 0;
+}
+
+static int select_input( char *filename, char *resolution, const char *pipe_format, x264_param_t *param )
+{
+ const char *ext = get_filename_extension( filename );
+ if( !strcmp( filename, "-" ) )
+ ext = pipe_format;
+
+ if( !strcasecmp( ext, "avi" ) || !strcasecmp( ext, "avs" ) )
+ {
+#if defined(AVS_INPUT) || defined(VFW_INPUT)
+ input = avs_input;
+#else
+ fprintf( stderr, "x264 [error]: not compiled with AVS input support\n" );
+ return -1;
+#endif
+ }
+ else if( !strcasecmp( ext, "y4m" ) )
+ input = y4m_input;
+ else if( !strcasecmp( ext, "yuv" ) )
+ {
+ if( !resolution )
+ {
+ /* try to parse the file name */
+ char *p;
+ for( p = filename; *p; p++ )
+ if( *p >= '0' && *p <= '9' &&
+ sscanf( p, "%ux%u", ¶m->i_width, ¶m->i_height ) == 2 )
+ {
+ if( param->i_log_level >= X264_LOG_INFO )
+ fprintf( stderr, "x264 [info]: %dx%d (given by file name) @ %.2f fps\n", param->i_width,
+ param->i_height, (double)param->i_fps_num / param->i_fps_den );
+ break;
+ }
+ }
+ else
+ {
+ sscanf( resolution, "%ux%u", ¶m->i_width, ¶m->i_height );
+ if( param->i_log_level >= X264_LOG_INFO )
+ fprintf( stderr, "x264 [info]: %dx%d @ %.2f fps\n", param->i_width, param->i_height,
+ (double)param->i_fps_num / param->i_fps_den );
+ }
+ if( !param->i_width || !param->i_height )
+ {
+ fprintf( stderr, "x264 [error]: Rawyuv input requires a resolution.\n" );
+ return -1;
+ }
+ input = yuv_input;
+ }
+ else
+ {
+#ifdef AVS_INPUT
+ input = avs_input;
+#else
+ input = yuv_input;
+#endif
+ }
+
+ return 0;
+}
+