Now any combination of arguments is allowed. --- doc/examples/fffuzz.c | 64 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 13 deletions(-)
diff --git a/doc/examples/fffuzz.c b/doc/examples/fffuzz.c index 6672f42..fdf97e7 100644 --- a/doc/examples/fffuzz.c +++ b/doc/examples/fffuzz.c @@ -29,6 +29,8 @@ * @example ddcf.c */ +#include <getopt.h> + #include <libavutil/avstring.h> #include <libavutil/imgutils.h> #include <libavutil/samplefmt.h> @@ -207,27 +209,63 @@ static int open_codec_context(AVCodecContext **dec_ctx, AVFormatContext *fmt_ctx return ret; } +static void exit_with_usage_msg(char* prog_name) +{ + fprintf(stderr, "\n" + "usage: %s [options] -i input_file -o output_file\n\n" + "API example program to show how to read frames from an input file.\n" + "This program reads frames from a file, decodes them, and writes decoded\n" + "frames to a rawvideo/rawaudio file named output_file.\n" + "Optionally format and codec can be specified.\n\n" + "Options:\n" + "-i input_file, -input input_file\n" + "\tSets input_file as input\n" + "-o output_file, -output output_file\n" + "\tSets output_file as output\n" + "-f format_name, -format format_name\n" + "\tSets the decode format to format_name\n" + "-c codec_name, -codec codec_name\n" + "\tSets the decode codec to codec_name\n\n", prog_name); + exit(1); +} + int main (int argc, char **argv) { - int ret = 0; + int ret = 0, opt; const char *src_filename = NULL; const char *dst_filename = NULL; char* format = NULL; char* codec = NULL; - if (argc != 5 && argc != 3) { - fprintf(stderr, "usage: %s input_file output_file [format codec]\n" - "API example program to show how to read frames from an input file.\n" - "This program reads frames from a file, decodes them, and writes decoded\n" - "frames to a rawvideo/rawaudio file named output_file.\n" - "Optionally format and codec can be specified.\n\n", argv[0]); - exit(1); + static struct option long_options[] = + { + {"input", required_argument, NULL, 'i'}, + {"output", required_argument, NULL, 'o'}, + {"format", required_argument, NULL, 'f'}, + {"codec", required_argument, NULL, 'c'}, + {0, 0, 0, 0} + }; + + while ((opt = getopt_long_only(argc, argv, "", long_options, NULL)) != -1) { + switch (opt) { + case 'i': + src_filename = optarg; + break; + case 'o': + dst_filename = optarg; + break; + case 'f': + format = optarg; + break; + case 'c': + codec = optarg; + break; + } } - src_filename = argv[1]; - dst_filename = argv[2]; - if (argc == 5) { - format = argv[3]; - codec = argv[4]; + + if (src_filename == NULL || dst_filename == NULL) { + fprintf(stderr, "%s: No input_file and/or output_file passed\n", argv[0]); + exit_with_usage_msg(argv[0]); } /* log all debug messages */ -- 2.6.4 (Apple Git-63) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel