+typedef enum
+{
+ OPT_FRAMES = 256,
+ OPT_SEEK,
+ OPT_QPFILE,
+ OPT_THREAD_INPUT,
+ OPT_QUIET,
+ OPT_NOPROGRESS,
+ OPT_LONGHELP,
+ OPT_PROFILE,
+ OPT_PRESET,
+ OPT_TUNE,
+ OPT_SLOWFIRSTPASS,
+ OPT_FULLHELP,
+ OPT_FPS,
+ OPT_MUXER,
+ OPT_DEMUXER,
+ OPT_INDEX,
+ OPT_INTERLACED,
+ OPT_TCFILE_IN,
+ OPT_TCFILE_OUT,
+ OPT_TIMEBASE,
+ OPT_PULLDOWN,
+ OPT_LOG_LEVEL,
+ OPT_VIDEO_FILTER,
+ OPT_INPUT_FMT,
+ OPT_INPUT_RES,
+ OPT_INPUT_CSP,
+ OPT_INPUT_DEPTH,
+ OPT_DTS_COMPRESSION,
+ OPT_OUTPUT_CSP,
+ OPT_INPUT_RANGE,
+ OPT_RANGE
+} OptionsOPT;
+
+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 },
+ { "open-gop", no_argument, NULL, 0 },
+ { "bluray-compat", no_argument, NULL, 0 },
+ { "avcintra-class", required_argument, NULL, 0 },
+ { "min-keyint", required_argument, NULL, 'i' },
+ { "keyint", required_argument, NULL, 'I' },
+ { "intra-refresh", no_argument, NULL, 0 },
+ { "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, OPT_INTERLACED },
+ { "tff", no_argument, NULL, OPT_INTERLACED },
+ { "bff", no_argument, NULL, OPT_INTERLACED },
+ { "no-interlaced", no_argument, NULL, OPT_INTERLACED },
+ { "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 },
+ { "opencl", no_argument, NULL, 1 },
+ { "opencl-clbin",required_argument, NULL, 0 },
+ { "opencl-device",required_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' },
+ { "muxer", required_argument, NULL, OPT_MUXER },
+ { "demuxer", required_argument, NULL, OPT_DEMUXER },
+ { "stdout", required_argument, NULL, OPT_MUXER },
+ { "stdin", required_argument, NULL, OPT_DEMUXER },
+ { "index", required_argument, NULL, OPT_INDEX },
+ { "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, '8' },
+ { "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 },
+ { "crf-max", 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 },
+ { "lookahead-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 },
+ { "slice-min-mbs", required_argument, NULL, 0 },
+ { "slices", required_argument, NULL, 0 },
+ { "slices-max", required_argument, NULL, 0 },
+ { "thread-input", no_argument, NULL, OPT_THREAD_INPUT },
+ { "sync-lookahead", required_argument, NULL, 0 },
+ { "non-deterministic", no_argument, NULL, 0 },
+ { "cpu-independent", 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' },
+ { "log-level", required_argument, NULL, OPT_LOG_LEVEL },
+ { "no-progress", no_argument, NULL, OPT_NOPROGRESS },
+ { "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 },
+ { "range", required_argument, NULL, OPT_RANGE },
+ { "colorprim", required_argument, NULL, 0 },
+ { "transfer", required_argument, NULL, 0 },
+ { "colormatrix", required_argument, NULL, 0 },
+ { "chromaloc", required_argument, NULL, 0 },
+ { "force-cfr", no_argument, NULL, 0 },
+ { "tcfile-in", required_argument, NULL, OPT_TCFILE_IN },
+ { "tcfile-out", required_argument, NULL, OPT_TCFILE_OUT },
+ { "timebase", required_argument, NULL, OPT_TIMEBASE },
+ { "pic-struct", no_argument, NULL, 0 },
+ { "crop-rect", required_argument, NULL, 0 },
+ { "nal-hrd", required_argument, NULL, 0 },
+ { "pulldown", required_argument, NULL, OPT_PULLDOWN },
+ { "fake-interlaced", no_argument, NULL, 0 },
+ { "frame-packing", required_argument, NULL, 0 },
+ { "vf", required_argument, NULL, OPT_VIDEO_FILTER },
+ { "video-filter", required_argument, NULL, OPT_VIDEO_FILTER },
+ { "input-fmt", required_argument, NULL, OPT_INPUT_FMT },
+ { "input-res", required_argument, NULL, OPT_INPUT_RES },
+ { "input-csp", required_argument, NULL, OPT_INPUT_CSP },
+ { "input-depth", required_argument, NULL, OPT_INPUT_DEPTH },
+ { "dts-compress", no_argument, NULL, OPT_DTS_COMPRESSION },
+ { "output-csp", required_argument, NULL, OPT_OUTPUT_CSP },
+ { "input-range", required_argument, NULL, OPT_INPUT_RANGE },
+ { "stitchable", no_argument, NULL, 0 },
+ { "filler", no_argument, NULL, 0 },
+ {0, 0, 0, 0}
+};
+
+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;