Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Thilo Borgmann <thilo.borgmann@mail.de>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v4 3/6] fftools: Add support for dictionary options
Date: Mon, 19 Sep 2022 11:46:01 +0200
Message-ID: <20220919094604.4645-4-thilo.borgmann@mail.de> (raw)
In-Reply-To: <20220919094604.4645-1-thilo.borgmann@mail.de>

From: Jan Ekström <jeebjp@gmail.com>

---
 fftools/cmdutils.c   | 17 +++++++++++++++++
 fftools/cmdutils.h   |  2 ++
 fftools/ffmpeg_opt.c | 29 ++++++++++++++++++++++++++---
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index b6dd73902b..f918d83854 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -137,6 +137,21 @@ int64_t parse_time_or_die(const char *context, const char *timestr,
     return us;
 }
 
+static AVDictionary *parse_dict_or_die(const char *context,
+                                       const char *dict_str)
+{
+    AVDictionary *dict = NULL;
+    int ret = av_dict_parse_string(&dict, dict_str, "=", ":", 0);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_FATAL,
+               "Failed to create a dictionary from '%s': %s!\n",
+               dict_str, av_err2str(ret));
+        exit_program(1);
+    }
+
+    return dict;
+}
+
 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
                        int rej_flags, int alt_flags)
 {
@@ -299,6 +314,8 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
         *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
     } else if (po->flags & OPT_DOUBLE) {
         *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
+    } else if (po->flags & OPT_DICT) {
+        *(AVDictionary **)dst = parse_dict_or_die(opt, arg);
     } else if (po->u.func_arg) {
         int ret = po->u.func_arg(optctx, opt, arg);
         if (ret < 0) {
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 2f469f8c25..c7a4628191 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -140,6 +140,7 @@ typedef struct SpecifierOpt {
         uint64_t ui64;
         float      f;
         double   dbl;
+        AVDictionary *dict;
     } u;
 } SpecifierOpt;
 
@@ -168,6 +169,7 @@ typedef struct OptionDef {
 #define OPT_DOUBLE 0x20000
 #define OPT_INPUT  0x40000
 #define OPT_OUTPUT 0x80000
+#define OPT_DICT  0x100000
      union {
         void *dst_ptr;
         int (*func_arg)(void *, const char *, const char *);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 5febe319e4..be1cd673f6 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -62,6 +62,21 @@
 #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
 #define SPECIFIER_OPT_FMT_f    "%f"
 #define SPECIFIER_OPT_FMT_dbl  "%lf"
+#define SPECIFIER_OPT_FMT_dict "%s"
+
+static char* specifier_opt_func_dict(char **valstr, AVDictionary *val) {
+    int ret;
+    ret = av_dict_get_string(val, valstr, '=', ':');
+    return (ret < 0) ? NULL : *valstr;
+}
+
+#define SPECIFIER_OPT_FUNC_str(val)  val
+#define SPECIFIER_OPT_FUNC_i(val)    val
+#define SPECIFIER_OPT_FUNC_i64(val)  val
+#define SPECIFIER_OPT_FUNC_ui64(val) val
+#define SPECIFIER_OPT_FUNC_f(val)    val
+#define SPECIFIER_OPT_FUNC_dbl(val)  val
+#define SPECIFIER_OPT_FUNC_dict(val) specifier_opt_func_dict(&valstr, val)
 
 static const char *const opt_name_codec_names[]               = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL};
 static const char *const opt_name_audio_channels[]            = {"ac", NULL};
@@ -114,11 +129,13 @@ static const char *const opt_name_bits_per_raw_sample[]       = {"bits_per_raw_s
 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
 {\
     char namestr[128] = "";\
+    char *valstr = NULL;\
     const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
     for (i = 0; opt_name_##name[i]; i++)\
         av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\
     av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
-           namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
+           namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, SPECIFIER_OPT_FUNC_##type(so->u.type));\
+    av_freep(&valstr);\
 }
 
 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
@@ -208,11 +225,17 @@ static void uninit_options(OptionsContext *o)
                 av_freep(&(*so)[i].specifier);
                 if (po->flags & OPT_STRING)
                     av_freep(&(*so)[i].u.str);
+                else if (po->flags & OPT_DICT)
+                    av_dict_free(&(*so)[i].u.dict);
             }
             av_freep(so);
             *count = 0;
-        } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
-            av_freep(dst);
+        } else if (po->flags & OPT_OFFSET) {
+            if (po->flags & OPT_STRING)
+                av_freep(dst);
+            else if (po->flags & OPT_DICT)
+                av_dict_free((AVDictionary **)dst);
+        }
         po++;
     }
 
-- 
2.20.1 (Apple Git-117)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-09-19  9:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19  9:45 [FFmpeg-devel] [PATCH v4 0/6] Add display_matrix option Thilo Borgmann
2022-09-19  9:45 ` [FFmpeg-devel] [PATCH v4 1/6] lavu/opt: Allow options to be arguments of other options Thilo Borgmann
2022-09-19  9:46 ` [FFmpeg-devel] [PATCH v4 2/6] fftools/cmdutils: Print arguments of options Thilo Borgmann
2022-09-19  9:46 ` Thilo Borgmann [this message]
2022-09-19  9:46 ` [FFmpeg-devel] [PATCH v4 4/6] lavu/display: Add horizontal and vertical scaling to the display matrix Thilo Borgmann
2022-09-19 13:37   ` Andreas Rheinhardt
2022-09-19  9:46 ` [FFmpeg-devel] [PATCH v4 5/6] ffmpeg: Add display_matrix option Thilo Borgmann
2022-09-19  9:46 ` [FFmpeg-devel] [PATCH v4 6/6] ffmpeg: Deprecate display rotation override with a metadata key Thilo Borgmann
2022-09-20  8:36 ` [FFmpeg-devel] [PATCH v4 0/6] Add display_matrix option Anton Khirnov
2022-09-20  9:05   ` Nicolas George
2022-09-20  9:23     ` Anton Khirnov

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=20220919094604.4645-4-thilo.borgmann@mail.de \
    --to=thilo.borgmann@mail.de \
    --cc=ffmpeg-devel@ffmpeg.org \
    /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