Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Om Bhandankar via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: ombhandankar <om.bhandankar@gmail.com>, Cursor <cursoragent@cursor.com>
Subject: [FFmpeg-devel] [PATCH] fftools: add -ignore_unknown_options for forward-compatible CLI usage
Date: Sun,  8 Feb 2026 10:26:21 +0530
Message-ID: <20260208045621.46911-1-om.bhandankar@gmail.com> (raw)

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

             reply	other threads:[~2026-02-08 19:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-08  4:56 Om Bhandankar via ffmpeg-devel [this message]
2026-02-08 23:02 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260208045621.46911-1-om.bhandankar@gmail.com \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=cursoragent@cursor.com \
    --cc=om.bhandankar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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