[FFmpeg-devel] [PATCH] fftools: Accept more negative prefixes

Mark Thompson sw at jkqxz.net
Fri Aug 21 00:49:16 EEST 2020


In addition to "no", also allow "no_", "disable" and "disable_".
---
On 20/08/2020 18:49, Nicolas George wrote:
> Alexander Strasser (12020-08-17):
>> Here are some suggestions in no particular order:
>>
>> * auto_conversion_filters (from Marton)
> 
> I can be ok with this one. I really dislike boolean options that default
> to yes and have to be disabled with no, because it requires remembering
> what the default is, but if that is what everybody else prefers.

But we can fix that to be nicer!

With this patch, -disable_auto_conversion_filters does what you want.

(The duplication below is because one part is used for ffmpeg and the other for ffplay/ffprobe.)

- Mark


  fftools/cmdutils.c | 42 +++++++++++++++++++++++++++++++++---------
  1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 88fdbeaf1e..1a1740b46e 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -345,6 +345,13 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
      return 0;
  }

+static const char *negative_prefixes[] = {
+    "no_",
+    "no",
+    "disable_",
+    "disable",
+};
+
  int parse_option(void *optctx, const char *opt, const char *arg,
                   const OptionDef *options)
  {
@@ -352,11 +359,18 @@ int parse_option(void *optctx, const char *opt, const char *arg,
      int ret;

      po = find_option(options, opt);
-    if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
-        /* handle 'no' bool option */
-        po = find_option(options, opt + 2);
-        if ((po->name && (po->flags & OPT_BOOL)))
-            arg = "0";
+    if (!po->name) {
+        /* Try to match a boolean option with a negative prefix. */
+        for (int i = 0; i < FF_ARRAY_ELEMS(negative_prefixes); i++) {
+            size_t len = strlen(negative_prefixes[i]);
+            if (!strncmp(opt, negative_prefixes[i], len)) {
+                po = find_option(options, opt + len);
+                if (po->name && (po->flags & OPT_BOOL)) {
+                    arg = "0";
+                    break;
+                }
+            }
+        }
      } else if (po->flags & OPT_BOOL)
          arg = "1";

@@ -764,6 +778,7 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[],
      while (optindex < argc) {
          const char *opt = argv[optindex++], *arg;
          const OptionDef *po;
+        int negative_match;
          int ret;

          av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
@@ -831,10 +846,19 @@ do {                                                                           \
              }
          }

-        /* boolean -nofoo options */
-        if (opt[0] == 'n' && opt[1] == 'o' &&
-            (po = find_option(options, opt + 2)) &&
-            po->name && po->flags & OPT_BOOL) {
+        /* Boolean options with a negative prefix. */
+        negative_match = 0;
+        for (int i = 0; i < FF_ARRAY_ELEMS(negative_prefixes); i++) {
+            size_t len = strlen(negative_prefixes[i]);
+            if (!strncmp(opt, negative_prefixes[i], len)) {
+                po = find_option(options, opt + len);
+                if (po->name && (po->flags & OPT_BOOL)) {
+                    negative_match = 1;
+                    break;
+                }
+            }
+        }
+        if (negative_match) {
              add_opt(octx, po, opt, "0");
              av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
                     "argument 0.\n", po->name, po->help);
-- 
2.28.0



More information about the ffmpeg-devel mailing list