From: ombhandankar <[email protected]> Add a new global option -ignore_unknown_options that downgrades the "Unrecognized option" fatal error to a non-fatal warning, allowing processing to continue.
This enables scripts and programs that invoke FFmpeg to include options from newer versions while maintaining compatibility with older ones. The option must appear before any unrecognized options on the command line. Both option parsing paths are handled: split_commandline() used by ffmpeg, and parse_options() used by ffplay/ffprobe. The option is defined in CMDUTILS_COMMON_OPTIONS so all tools support it. When an unrecognized option is skipped, its potential argument is not consumed, as there is no reliable way to determine whether an unknown option expects an argument. Ref: https://trac.ffmpeg.org/ticket/11626 Signed-off-by: Om Bhandankar <[email protected]> Co-authored-by: Cursor <[email protected]> --- Changelog | 1 + doc/fftools-common-opts.texi | 14 ++++++++++++++ fftools/cmdutils.c | 15 ++++++++++++++- fftools/cmdutils.h | 1 + fftools/opt_common.h | 1 + 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index a09dcd82c2..017bb4940f 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. version <next>: +- -ignore_unknown_options global option for forward-compatible CLI usage - yasm support dropped, users need to use nasm - VVC VAAPI decoder - RealVideo 6.0 decoder diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index f6d452c40e..586736829e 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -318,6 +318,20 @@ All FFmpeg tools will normally show a copyright notice, build options and library versions. This option can be used to suppress printing this information. +@item -ignore_unknown_options +Ignore unrecognized options instead of exiting with an error. + +When this option is set, any unrecognized command-line option will produce +a warning message instead of a fatal error, and processing will continue. +This is useful for scripts and programs that invoke FFmpeg with options +that may not be available in all versions, allowing forward-compatible +command lines. + +Note that this option must appear before any unrecognized options on the +command line. Also note that if an unrecognized option would normally +expect an argument, the argument will not be consumed and may be +misinterpreted as a subsequent option or filename. + @item -cpuflags flags (@emph{global}) Allows setting and clearing cpu flags. This option is intended for testing. Do not use it unless you know what you're doing. diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 8ac20bf049..459651c522 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -58,6 +58,7 @@ AVDictionary *swr_opts; AVDictionary *format_opts, *codec_opts; int hide_banner = 0; +int ignore_unknown_options = 0; void uninit_opts(void) { @@ -435,8 +436,13 @@ int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, } opt++; - if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) + if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) { + if (ignore_unknown_options && ret == AVERROR_OPTION_NOT_FOUND) { + av_log(NULL, AV_LOG_WARNING, "Ignoring unrecognized option '%s'.\n", opt); + continue; + } return ret; + } optindex += ret; } else { if (parse_arg_function) { @@ -581,6 +587,9 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options) idx = locate_option(argc, argv, options, "hide_banner"); if (idx) hide_banner = 1; + idx = locate_option(argc, argv, options, "ignore_unknown_options"); + if (idx) + ignore_unknown_options = 1; } static const AVOption *opt_find(void *obj, const char *name, const char *unit, @@ -894,6 +903,10 @@ do { \ continue; } + if (ignore_unknown_options) { + av_log(NULL, AV_LOG_WARNING, "Ignoring unrecognized option '%s'.\n", opt); + continue; + } av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt); return AVERROR_OPTION_NOT_FOUND; } diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index ad020f893a..baa6dcee0f 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -48,6 +48,7 @@ extern AVDictionary *sws_dict; extern AVDictionary *swr_opts; extern AVDictionary *format_opts, *codec_opts; extern int hide_banner; +extern int ignore_unknown_options; /** * Initialize dynamic library loading diff --git a/fftools/opt_common.h b/fftools/opt_common.h index 9bb5268472..e8625dbe19 100644 --- a/fftools/opt_common.h +++ b/fftools/opt_common.h @@ -226,6 +226,7 @@ int opt_cpucount(void *optctx, const char *opt, const char *arg); { "cpuflags", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \ { "cpucount", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT, { .func_arg = opt_cpucount }, "force specific cpu count", "count" }, \ { "hide_banner", OPT_TYPE_BOOL, OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \ + { "ignore_unknown_options", OPT_TYPE_BOOL, OPT_EXPERT, {&ignore_unknown_options}, "ignore unrecognized options instead of failing" }, \ CMDUTILS_COMMON_OPTIONS_AVDEVICE \ #endif /* FFTOOLS_OPT_COMMON_H */ -- 2.50.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
