From c5f5f4ed17b7f73c332c3a22f6af6d6ff580dcbd Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 27 Nov 2017 18:35:37 -0800 Subject: [PATCH] vpx{enc,dec}: add --help only output short usage to stderr on error, with --help use stdout Change-Id: I7089f3bca829817e14b14c766f4f3eaee6f54e5c --- vpxdec.c | 56 +++++++++++++++++++++++++++------------------ vpxenc.c | 69 +++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 77 insertions(+), 48 deletions(-) diff --git a/vpxdec.c b/vpxdec.c index 6db2afb4a..ff20e6a3c 100644 --- a/vpxdec.c +++ b/vpxdec.c @@ -47,6 +47,8 @@ struct VpxDecInputContext { 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 = 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"); @@ -98,17 +100,17 @@ static const arg_def_t framestatsarg = ARG_DEF(NULL, "framestats", 1, "Output per-frame stats (.csv format)"); static const arg_def_t *all_args[] = { - &codecarg, &use_yv12, &use_i420, - &flipuvarg, &rawvideo, &noblitarg, - &progressarg, &limitarg, &skiparg, - &postprocarg, &summaryarg, &outputfile, - &threadsarg, &frameparallelarg, &verbosearg, - &scalearg, &fb_arg, &md5arg, - &error_concealment, &continuearg, + &help, &codecarg, &use_yv12, + &use_i420, &flipuvarg, &rawvideo, + &noblitarg, &progressarg, &limitarg, + &skiparg, &postprocarg, &summaryarg, + &outputfile, &threadsarg, &frameparallelarg, + &verbosearg, &scalearg, &fb_arg, + &md5arg, &error_concealment, &continuearg, #if CONFIG_VP9_HIGHBITDEPTH &outbitdeptharg, #endif - &svcdecodingarg, &framestatsarg, NULL + &svcdecodingarg, &framestatsarg, NULL }; #if CONFIG_VP8_DECODER @@ -152,41 +154,47 @@ static INLINE int libyuv_scale(vpx_image_t *src, vpx_image_t *dst, dst->d_h, mode); } #endif - -void usage_exit(void) { +void show_help(FILE *fout, int shorthelp) { int i; - fprintf(stderr, - "Usage: %s filename\n\n" - "Options:\n", - exec_name); - arg_show_usage(stderr, all_args); + fprintf(fout, "Usage: %s filename\n\n", exec_name); + + if (shorthelp) { + fprintf(fout, "Use --help to see the full list of options.\n"); + return; + } + + fprintf(fout, "Options:\n"); + arg_show_usage(fout, all_args); #if CONFIG_VP8_DECODER - fprintf(stderr, "\nVP8 Postprocessing Options:\n"); - arg_show_usage(stderr, vp8_pp_args); + fprintf(fout, "\nVP8 Postprocessing Options:\n"); + arg_show_usage(fout, vp8_pp_args); #endif - fprintf(stderr, + fprintf(fout, "\nOutput File Patterns:\n\n" " The -o argument specifies the name of the file(s) to " "write to. If the\n argument does not include any escape " "characters, the output will be\n written to a single file. " "Otherwise, the filename will be calculated by\n expanding " "the following escape characters:\n"); - fprintf(stderr, + fprintf(fout, "\n\t%%w - Frame width" "\n\t%%h - Frame height" "\n\t%% - Frame number, zero padded to places (1..9)" "\n\n Pattern arguments are only supported in conjunction " "with the --yv12 and\n --i420 options. If the -o option is " "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_vpx_decoder_count(); ++i) { const VpxInterface *const decoder = get_vpx_decoder_by_index(i); - fprintf(stderr, " %-6s - %s\n", decoder->name, + fprintf(fout, " %-6s - %s\n", decoder->name, vpx_codec_iface_name(decoder->codec_interface())); } +} +void usage_exit(void) { + show_help(stderr, 1); exit(EXIT_FAILURE); } @@ -554,7 +562,10 @@ static int main_loop(int argc, const char **argv_) { memset(&arg, 0, sizeof(arg)); 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_vpx_decoder_by_name(arg.val); if (!interface) die("Error: Unrecognized argument (%s) to --codec\n", arg.val); @@ -651,6 +662,7 @@ static int main_loop(int argc, const char **argv_) { if (!fn) { free(argv); + fprintf(stderr, "No input file specified!\n"); usage_exit(); } /* Open file */ diff --git a/vpxenc.c b/vpxenc.c index 82162ff9c..4db7eccc3 100644 --- a/vpxenc.c +++ b/vpxenc.c @@ -123,6 +123,8 @@ static int fourcc_is_ivf(const char detect[4]) { return 0; } +static const arg_def_t help = + ARG_DEF(NULL, "help", 0, "Show usage options and exit"); static const arg_def_t debugmode = ARG_DEF("D", "debug", 0, "Debug mode (makes output deterministic)"); static const arg_def_t outputfile = @@ -199,7 +201,8 @@ static const arg_def_t test16bitinternalarg = ARG_DEF( NULL, "test-16bit-internal", 0, "Force use of 16 bit internal buffer"); #endif -static const arg_def_t *main_args[] = { &debugmode, +static const arg_def_t *main_args[] = { &help, + &debugmode, &outputfile, &codecarg, &passes, @@ -549,46 +552,54 @@ static const int vp9_arg_ctrl_map[] = { VP8E_SET_CPUUSED, static const arg_def_t *no_args[] = { NULL }; -void usage_exit(void) { +void show_help(FILE *fout, int shorthelp) { int i; const int num_encoder = get_vpx_encoder_count(); - fprintf(stderr, "Usage: %s -o dst_filename src_filename \n", + fprintf(fout, "Usage: %s -o dst_filename src_filename \n", exec_name); - fprintf(stderr, "\nOptions:\n"); - arg_show_usage(stderr, main_args); - fprintf(stderr, "\nEncoder Global Options:\n"); - arg_show_usage(stderr, global_args); - fprintf(stderr, "\nRate Control Options:\n"); - arg_show_usage(stderr, rc_args); - fprintf(stderr, "\nTwopass Rate Control Options:\n"); - arg_show_usage(stderr, rc_twopass_args); - fprintf(stderr, "\nKeyframe Placement Options:\n"); - arg_show_usage(stderr, kf_args); + if (shorthelp) { + fprintf(fout, "Use --help to see the full list of options.\n"); + return; + } + + fprintf(fout, "\nOptions:\n"); + arg_show_usage(fout, main_args); + fprintf(fout, "\nEncoder Global Options:\n"); + arg_show_usage(fout, global_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_VP8_ENCODER - fprintf(stderr, "\nVP8 Specific Options:\n"); - arg_show_usage(stderr, vp8_args); + fprintf(fout, "\nVP8 Specific Options:\n"); + arg_show_usage(fout, vp8_args); #endif #if CONFIG_VP9_ENCODER - fprintf(stderr, "\nVP9 Specific Options:\n"); - arg_show_usage(stderr, vp9_args); + fprintf(fout, "\nVP9 Specific Options:\n"); + arg_show_usage(fout, vp9_args); #endif - fprintf(stderr, + fprintf(fout, "\nStream timebase (--timebase):\n" " The desired precision of timestamps in the output, expressed\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 VpxInterface *const encoder = get_vpx_encoder_by_index(i); const char *defstr = (i == (num_encoder - 1)) ? "(default)" : ""; - fprintf(stderr, " %-6s - %s %s\n", encoder->name, + fprintf(fout, " %-6s - %s %s\n", encoder->name, vpx_codec_iface_name(encoder->codec_interface()), defstr); } - fprintf(stderr, "\n "); - fprintf(stderr, "Use --codec to switch to a non-default encoder.\n\n"); + fprintf(fout, "\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); } @@ -903,7 +914,10 @@ static void parse_global_config(struct VpxEncoderConfig *global, char **argv) { for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { 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_vpx_encoder_by_name(arg.val); if (!global->codec) die("Error: Unrecognized argument (%s) to --codec\n", arg.val); @@ -1905,8 +1919,6 @@ int main(int argc, const char **argv_) { memset(&input, 0, sizeof(input)); exec_name = argv_[0]; - if (argc < 3) usage_exit(); - /* Setup default input stream settings */ input.framerate.numerator = 30; input.framerate.denominator = 1; @@ -1920,6 +1932,8 @@ int main(int argc, const char **argv_) { argv = argv_dup(argc - 1, argv_ + 1); parse_global_config(&global, argv); + if (argc < 3) usage_exit(); + switch (global.color_type) { case I420: input.fmt = VPX_IMG_FMT_I420; break; case I422: input.fmt = VPX_IMG_FMT_I422; break; @@ -1953,7 +1967,10 @@ int main(int argc, const char **argv_) { /* Handle non-option arguments */ 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 */ if (global.codec->fourcc == VP9_FOURCC) input.only_i420 = 0; -- 2.40.0