Commit fd8c78c4 authored by James Zern's avatar James Zern
Browse files

aom{enc,dec}: add --help

only output short usage to stderr on error, with --help use stdout

BUG=aomedia:44

Change-Id: Ia7d0316a354d2dfadb36698dd4958355f6168a60
parent 33601da7
...@@ -56,6 +56,8 @@ struct AvxDecInputContext { ...@@ -56,6 +56,8 @@ struct AvxDecInputContext {
struct WebmInputContext *webm_ctx; struct WebmInputContext *webm_ctx;
}; };
static const arg_def_t help =
ARG_DEF(NULL, "help", 0, "Show usage options and exit");
static const arg_def_t looparg = static const arg_def_t looparg =
ARG_DEF(NULL, "loops", 1, "Number of times to decode the file"); ARG_DEF(NULL, "loops", 1, "Number of times to decode the file");
static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use"); static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use");
...@@ -110,7 +112,8 @@ static const arg_def_t tilec = ARG_DEF(NULL, "tile-column", 1, ...@@ -110,7 +112,8 @@ static const arg_def_t tilec = ARG_DEF(NULL, "tile-column", 1,
"(-1 for all columns)"); "(-1 for all columns)");
#endif // CONFIG_EXT_TILE #endif // CONFIG_EXT_TILE
static const arg_def_t *all_args[] = { &codecarg, static const arg_def_t *all_args[] = { &help,
&codecarg,
&use_yv12, &use_yv12,
&use_i420, &use_i420,
&flipuvarg, &flipuvarg,
...@@ -167,36 +170,41 @@ static INLINE int libyuv_scale(aom_image_t *src, aom_image_t *dst, ...@@ -167,36 +170,41 @@ static INLINE int libyuv_scale(aom_image_t *src, aom_image_t *dst,
} }
#endif #endif
void usage_exit(void) { void show_help(FILE *fout, int shorthelp) {
int i; fprintf(fout, "Usage: %s <options> filename\n\n", exec_name);
fprintf(stderr, if (shorthelp) {
"Usage: %s <options> filename\n\n" fprintf(fout, "Use --help to see the full list of options.\n");
"Options:\n", return;
exec_name); }
arg_show_usage(stderr, all_args);
fprintf(stderr, fprintf(fout, "Options:\n");
arg_show_usage(fout, all_args);
fprintf(fout,
"\nOutput File Patterns:\n\n" "\nOutput File Patterns:\n\n"
" The -o argument specifies the name of the file(s) to " " The -o argument specifies the name of the file(s) to "
"write to. If the\n argument does not include any escape " "write to. If the\n argument does not include any escape "
"characters, the output will be\n written to a single file. " "characters, the output will be\n written to a single file. "
"Otherwise, the filename will be calculated by\n expanding " "Otherwise, the filename will be calculated by\n expanding "
"the following escape characters:\n"); "the following escape characters:\n");
fprintf(stderr, fprintf(fout,
"\n\t%%w - Frame width" "\n\t%%w - Frame width"
"\n\t%%h - Frame height" "\n\t%%h - Frame height"
"\n\t%%<n> - Frame number, zero padded to <n> places (1..9)" "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
"\n\n Pattern arguments are only supported in conjunction " "\n\n Pattern arguments are only supported in conjunction "
"with the --yv12 and\n --i420 options. If the -o option is " "with the --yv12 and\n --i420 options. If the -o option is "
"not specified, the output will be\n directed to stdout.\n"); "not specified, the output will be\n directed to stdout.\n");
fprintf(stderr, "\nIncluded decoders:\n\n"); fprintf(fout, "\nIncluded decoders:\n\n");
for (i = 0; i < get_aom_decoder_count(); ++i) { for (int i = 0; i < get_aom_decoder_count(); ++i) {
const AvxInterface *const decoder = get_aom_decoder_by_index(i); const AvxInterface *const decoder = get_aom_decoder_by_index(i);
fprintf(stderr, " %-6s - %s\n", decoder->name, fprintf(fout, " %-6s - %s\n", decoder->name,
aom_codec_iface_name(decoder->codec_interface())); aom_codec_iface_name(decoder->codec_interface()));
} }
}
void usage_exit(void) {
show_help(stderr, 1);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -560,7 +568,10 @@ static int main_loop(int argc, const char **argv_) { ...@@ -560,7 +568,10 @@ static int main_loop(int argc, const char **argv_) {
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.argv_step = 1; arg.argv_step = 1;
if (arg_match(&arg, &codecarg, argi)) { if (arg_match(&arg, &help, argi)) {
show_help(stdout, 0);
exit(EXIT_SUCCESS);
} else if (arg_match(&arg, &codecarg, argi)) {
interface = get_aom_decoder_by_name(arg.val); interface = get_aom_decoder_by_name(arg.val);
if (!interface) if (!interface)
die("Error: Unrecognized argument (%s) to --codec\n", arg.val); die("Error: Unrecognized argument (%s) to --codec\n", arg.val);
...@@ -640,6 +651,7 @@ static int main_loop(int argc, const char **argv_) { ...@@ -640,6 +651,7 @@ static int main_loop(int argc, const char **argv_) {
if (!fn) { if (!fn) {
free(argv); free(argv);
fprintf(stderr, "No input file specified!\n");
usage_exit(); usage_exit();
} }
/* Open file */ /* Open file */
......
...@@ -126,6 +126,8 @@ static int fourcc_is_ivf(const char detect[4]) { ...@@ -126,6 +126,8 @@ static int fourcc_is_ivf(const char detect[4]) {
return 0; return 0;
} }
static const arg_def_t help =
ARG_DEF(NULL, "help", 0, "Show usage options and exit");
static const arg_def_t debugmode = static const arg_def_t debugmode =
ARG_DEF("D", "debug", 0, "Debug mode (makes output deterministic)"); ARG_DEF("D", "debug", 0, "Debug mode (makes output deterministic)");
static const arg_def_t outputfile = static const arg_def_t outputfile =
...@@ -206,7 +208,8 @@ static const arg_def_t inbitdeptharg = ...@@ -206,7 +208,8 @@ static const arg_def_t inbitdeptharg =
ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input"); ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input");
#endif #endif
static const arg_def_t *main_args[] = { &debugmode, static const arg_def_t *main_args[] = { &help,
&debugmode,
&outputfile, &outputfile,
&codecarg, &codecarg,
&passes, &passes,
...@@ -671,42 +674,48 @@ static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED, ...@@ -671,42 +674,48 @@ static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED,
static const arg_def_t *no_args[] = { NULL }; static const arg_def_t *no_args[] = { NULL };
void usage_exit(void) { void show_help(FILE *fout, int shorthelp) {
int i; fprintf(fout, "Usage: %s <options> -o dst_filename src_filename \n",
const int num_encoder = get_aom_encoder_count();
fprintf(stderr, "Usage: %s <options> -o dst_filename src_filename \n",
exec_name); exec_name);
fprintf(stderr, "\nOptions:\n"); if (shorthelp) {
arg_show_usage(stderr, main_args); fprintf(fout, "Use --help to see the full list of options.\n");
fprintf(stderr, "\nEncoder Global Options:\n"); return;
arg_show_usage(stderr, global_args); }
fprintf(stderr, "\nRate Control Options:\n");
arg_show_usage(stderr, rc_args); fprintf(fout, "\nOptions:\n");
fprintf(stderr, "\nTwopass Rate Control Options:\n"); arg_show_usage(fout, main_args);
arg_show_usage(stderr, rc_twopass_args); fprintf(fout, "\nEncoder Global Options:\n");
fprintf(stderr, "\nKeyframe Placement Options:\n"); arg_show_usage(fout, global_args);
arg_show_usage(stderr, kf_args); fprintf(fout, "\nRate Control Options:\n");
arg_show_usage(fout, rc_args);
fprintf(fout, "\nTwopass Rate Control Options:\n");
arg_show_usage(fout, rc_twopass_args);
fprintf(fout, "\nKeyframe Placement Options:\n");
arg_show_usage(fout, kf_args);
#if CONFIG_AV1_ENCODER #if CONFIG_AV1_ENCODER
fprintf(stderr, "\nAV1 Specific Options:\n"); fprintf(fout, "\nAV1 Specific Options:\n");
arg_show_usage(stderr, av1_args); arg_show_usage(fout, av1_args);
#endif #endif
fprintf(stderr, fprintf(fout,
"\nStream timebase (--timebase):\n" "\nStream timebase (--timebase):\n"
" The desired precision of timestamps in the output, expressed\n" " The desired precision of timestamps in the output, expressed\n"
" in fractional seconds. Default is 1/1000.\n"); " in fractional seconds. Default is 1/1000.\n");
fprintf(stderr, "\nIncluded encoders:\n\n"); fprintf(fout, "\nIncluded encoders:\n\n");
for (i = 0; i < num_encoder; ++i) { const int num_encoder = get_aom_encoder_count();
for (int i = 0; i < num_encoder; ++i) {
const AvxInterface *const encoder = get_aom_encoder_by_index(i); const AvxInterface *const encoder = get_aom_encoder_by_index(i);
const char *defstr = (i == (num_encoder - 1)) ? "(default)" : ""; const char *defstr = (i == (num_encoder - 1)) ? "(default)" : "";
fprintf(stderr, " %-6s - %s %s\n", encoder->name, fprintf(fout, " %-6s - %s %s\n", encoder->name,
aom_codec_iface_name(encoder->codec_interface()), defstr); aom_codec_iface_name(encoder->codec_interface()), defstr);
} }
fprintf(stderr, "\n "); fprintf(fout, "\n ");
fprintf(stderr, "Use --codec to switch to a non-default encoder.\n\n"); fprintf(fout, "Use --codec to switch to a non-default encoder.\n\n");
}
void usage_exit(void) {
show_help(stderr, 1);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -792,7 +801,10 @@ static void parse_global_config(struct AvxEncoderConfig *global, char **argv) { ...@@ -792,7 +801,10 @@ static void parse_global_config(struct AvxEncoderConfig *global, char **argv) {
for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
arg.argv_step = 1; arg.argv_step = 1;
if (arg_match(&arg, &codecarg, argi)) { if (arg_match(&arg, &help, argi)) {
show_help(stdout, 0);
exit(EXIT_SUCCESS);
} else if (arg_match(&arg, &codecarg, argi)) {
global->codec = get_aom_encoder_by_name(arg.val); global->codec = get_aom_encoder_by_name(arg.val);
if (!global->codec) if (!global->codec)
die("Error: Unrecognized argument (%s) to --codec\n", arg.val); die("Error: Unrecognized argument (%s) to --codec\n", arg.val);
...@@ -1782,8 +1794,6 @@ int main(int argc, const char **argv_) { ...@@ -1782,8 +1794,6 @@ int main(int argc, const char **argv_) {
memset(&input, 0, sizeof(input)); memset(&input, 0, sizeof(input));
exec_name = argv_[0]; exec_name = argv_[0];
if (argc < 3) usage_exit();
/* Setup default input stream settings */ /* Setup default input stream settings */
input.framerate.numerator = 30; input.framerate.numerator = 30;
input.framerate.denominator = 1; input.framerate.denominator = 1;
...@@ -1797,6 +1807,8 @@ int main(int argc, const char **argv_) { ...@@ -1797,6 +1807,8 @@ int main(int argc, const char **argv_) {
argv = argv_dup(argc - 1, argv_ + 1); argv = argv_dup(argc - 1, argv_ + 1);
parse_global_config(&global, argv); parse_global_config(&global, argv);
if (argc < 3) usage_exit();
switch (global.color_type) { switch (global.color_type) {
case I420: input.fmt = AOM_IMG_FMT_I420; break; case I420: input.fmt = AOM_IMG_FMT_I420; break;
case I422: input.fmt = AOM_IMG_FMT_I422; break; case I422: input.fmt = AOM_IMG_FMT_I422; break;
...@@ -1832,7 +1844,10 @@ int main(int argc, const char **argv_) { ...@@ -1832,7 +1844,10 @@ int main(int argc, const char **argv_) {
/* Handle non-option arguments */ /* Handle non-option arguments */
input.filename = argv[0]; input.filename = argv[0];
if (!input.filename) usage_exit(); if (!input.filename) {
fprintf(stderr, "No input file specified!\n");
usage_exit();
}
/* Decide if other chroma subsamplings than 4:2:0 are supported */ /* Decide if other chroma subsamplings than 4:2:0 are supported */
if (global.codec->fourcc == AV1_FOURCC) input.only_i420 = 0; if (global.codec->fourcc == AV1_FOURCC) input.only_i420 = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment