Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] fftools: add -ignore_unknown_options for forward-compatible CLI usage
@ 2026-02-08  4:56 Om Bhandankar via ffmpeg-devel
  2026-02-08 23:02 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
  0 siblings, 1 reply; 2+ messages in thread
From: Om Bhandankar via ffmpeg-devel @ 2026-02-08  4:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: ombhandankar, Cursor

From: ombhandankar <om.bhandankar@gmail.com>

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 <om.bhandankar@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
---
 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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [FFmpeg-devel] Re: [PATCH] fftools: add -ignore_unknown_options for forward-compatible CLI usage
  2026-02-08  4:56 [FFmpeg-devel] [PATCH] fftools: add -ignore_unknown_options for forward-compatible CLI usage Om Bhandankar via ffmpeg-devel
@ 2026-02-08 23:02 ` Michael Niedermayer via ffmpeg-devel
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-02-08 23:02 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer


[-- Attachment #1.1: Type: text/plain, Size: 2104 bytes --]

Hi

On Sun, Feb 08, 2026 at 10:26:21AM +0530, Om Bhandankar via ffmpeg-devel wrote:
> From: ombhandankar <om.bhandankar@gmail.com>
> 
> 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 <om.bhandankar@gmail.com>
> Co-authored-by: Cursor <cursoragent@cursor.com>
> ---
>  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(-)

instead of a bool, it may be better to list the specific options for which
their failure should be ignored.

-ignore_unknown_options "fancynewoption,anotherfancynewoption" -fancynewoption 123

in principle this would allow also to specify if the option takes an argument
that should be skipped

But before accepting an implemenattion of that idea above, id like to see how this looks.
This is a feature which is ok if its simple, clean and easy maintainable.

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 163 bytes --]

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-08 23:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-08  4:56 [FFmpeg-devel] [PATCH] fftools: add -ignore_unknown_options for forward-compatible CLI usage Om Bhandankar via ffmpeg-devel
2026-02-08 23:02 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git