[FFmpeg-devel] [DEVEL][PATCH 1/2] ffmpeg: parse duplicate option

pkv.stream pkv.stream at gmail.com
Wed Nov 22 15:32:07 EET 2017


Le 19/11/2017 à 8:28 PM, Michael Niedermayer a écrit :
> On Sun, Nov 19, 2017 at 11:01:37AM +0100, pkv.stream wrote:
> [...]
>
>> @@ -3674,6 +3697,10 @@ const OptionDef options[] = {
>>       { "channel_layout", OPT_AUDIO | HAS_ARG  | OPT_EXPERT | OPT_PERFILE |
>>                           OPT_INPUT | OPT_OUTPUT,                                    { .func_arg = opt_channel_layout },
>>           "set channel layout", "layout" },
>> +    { "channel_layout_uint64", OPT_AUDIO | HAS_ARG | OPT_INT64 | OPT_SPEC |
> i mean as "channel_layout"
> does it work with both using the same name so the option is routed
> to both the field and callback or am i missing something why this is
> not intended?

Hi Michael,
I've modified previous patch per your remark, so that channel_layout 
option is now routed both as func_arg and OPT_SPEC with same option name.

patch 1/2:  parse duplicate option. Allows two entries carrying same 
name in OptionDef table, the main one (the first) calls a func_arg while 
the second writes an offset in a SpecifierOpt. The duplicate option can 
never be set directly and should be set when the main option is parsed 
(in func_arg).

patch 2/2: fix channel_layout bug (ticket 6706) by retrieving 
channel_layout from stream output options and passing to filters.

Hope it will be OK.
Thanks.

-------------- next part --------------
From 7b53b8a6487173c62fcab2761289340b35bd171a Mon Sep 17 00:00:00 2001
From: pkviet <pkv.stream at gmail.com>
Date: Wed, 22 Nov 2017 13:44:37 +0100
Subject: [PATCH 1/2] ffmpeg: parse duplicate option

Allows parsing of a duplicate option in an OptionDef table, with same
name as main option.
This is useful for example for channel_layout which can be parsed with
func_arg (opt_channel_layout) and also stored as an offset in a
SpecifierOpt.

Signed-off-by: pkviet <pkv.stream at gmail.com>
---
 fftools/cmdutils.c | 18 ++++++++++++++++++
 fftools/cmdutils.h | 13 +++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 6920ca0..00802cf 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -380,6 +380,24 @@ int parse_option(void *optctx, const char *opt, const char *arg,
     return !!(po->flags & HAS_ARG);
 }
 
+int parse_duplicate_option(void *optctx, const char *opt, const char *arg,
+    const OptionDef *options)
+{
+    const OptionDef *po;
+    int ret;
+
+    po = find_option(options, opt) + 1;
+    if (po->name != (po - 1)->name) {
+        av_log(NULL, AV_LOG_ERROR, "Option '%s' has no duplicate.\n", opt);
+        return AVERROR(EINVAL);
+    }
+    ret = write_option(optctx, po, opt, arg);
+    if (ret < 0)
+        return ret;
+
+    return !!(po->flags & HAS_ARG);
+}
+
 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
                    void (*parse_arg_function)(void *, const char*))
 {
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index fa2b255..a2f74b5 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -301,6 +301,19 @@ int parse_option(void *optctx, const char *opt, const char *arg,
                  const OptionDef *options);
 
 /**
+* Parse the duplicate of one given option (carrying same name). Some options may
+* need to be dealt with func_arg as well as OPT_SPEC.
+* Ex: channel_layout is parsed with func_arg (allowing strings as well as numerals
+* as arguments); but it can be needed also as an OPT_SPEC.
+* The duplicate option should be defined in an OptionDef table right after the main
+* option and carries the same name.
+*
+* @return on success 1 if arg was consumed, 0 otherwise; negative number on error
+*/
+int parse_duplicate_option(void *optctx, const char *opt, const char *arg,
+    const OptionDef *options);
+
+/**
  * An option extracted from the commandline.
  * Cannot use AVDictionary because of options like -map which can be
  * used multiple times.
-- 
2.10.1.windows.1



More information about the ffmpeg-devel mailing list