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 1/8] lavfi/vf_scale: allow passing options to swscale directly
@ 2023-01-08 12:58 Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 2/8] lavfi: remove AVFilter.init_dict() Anton Khirnov
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

Avoid using the dictionary mechanism, which is non-introspectable. As
this is the only user of AVFilter.init_dict(), this callback can now be
removed.
---
 libavfilter/vf_scale.c | 95 +++++++++++++++++++++++++++++-------------
 1 file changed, 66 insertions(+), 29 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index b95e2e6c66..85047e3524 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -23,6 +23,7 @@
  * scale video filter
  */
 
+#include <float.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -107,7 +108,8 @@ typedef struct ScaleContext {
     const AVClass *class;
     struct SwsContext *sws;     ///< software scaler context
     struct SwsContext *isws[2]; ///< software scaler context for interlaced material
-    AVDictionary *opts;
+    // context used for forwarding options to sws
+    struct SwsContext *sws_opts;
 
     /**
      * New dimensions. Special values are:
@@ -117,7 +119,6 @@ typedef struct ScaleContext {
      */
     int w, h;
     char *size_str;
-    unsigned int flags;         ///sws flags
     double param[2];            // sws params
 
     int hsub, vsub;             ///< chroma subsampling
@@ -268,11 +269,29 @@ revert:
     return ret;
 }
 
-static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
+static av_cold int preinit(AVFilterContext *ctx)
 {
     ScaleContext *scale = ctx->priv;
     int ret;
 
+    scale->sws_opts = sws_alloc_context();
+    if (!scale->sws_opts)
+        return AVERROR(ENOMEM);
+
+    // set threads=0, so we can later check whether the user modified it
+    ret = av_opt_set_int(scale->sws_opts, "threads", 0, 0);
+    if (ret < 0)
+        return ret;
+
+    return 0;
+}
+
+static av_cold int init(AVFilterContext *ctx)
+{
+    ScaleContext *scale = ctx->priv;
+    int64_t threads;
+    int ret;
+
     if (scale->size_str && (scale->w_expr || scale->h_expr)) {
         av_log(ctx, AV_LOG_ERROR,
                "Size and width/height expressions cannot be set at the same time.\n");
@@ -310,18 +329,26 @@ static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
     av_log(ctx, AV_LOG_VERBOSE, "w:%s h:%s flags:'%s' interl:%d\n",
            scale->w_expr, scale->h_expr, (char *)av_x_if_null(scale->flags_str, ""), scale->interlaced);
 
-    scale->flags = 0;
-
     if (scale->flags_str && *scale->flags_str) {
-        const AVClass *class = sws_get_class();
-        const AVOption    *o = av_opt_find(&class, "sws_flags", NULL, 0,
-                                           AV_OPT_SEARCH_FAKE_OBJ);
-        int ret = av_opt_eval_flags(&class, o, scale->flags_str, &scale->flags);
+        ret = av_opt_set(scale->sws_opts, "sws_flags", scale->flags_str, 0);
         if (ret < 0)
             return ret;
     }
-    scale->opts = *opts;
-    *opts = NULL;
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(scale->param); i++)
+        if (scale->param[i] != DBL_MAX) {
+            ret = av_opt_set_double(scale->sws_opts, i ? "param1" : "param0",
+                                    scale->param[i], 0);
+            if (ret < 0)
+                return ret;
+        }
+
+    // use generic thread-count if the user did not set it explicitly
+    ret = av_opt_get_int(scale->sws_opts, "threads", 0, &threads);
+    if (ret < 0)
+        return ret;
+    if (!threads)
+        av_opt_set_int(scale->sws_opts, "threads", ff_filter_get_nb_threads(ctx), 0);
 
     scale->in_frame_range = AVCOL_RANGE_UNSPECIFIED;
 
@@ -334,11 +361,11 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_expr_free(scale->w_pexpr);
     av_expr_free(scale->h_pexpr);
     scale->w_pexpr = scale->h_pexpr = NULL;
+    sws_freeContext(scale->sws_opts);
     sws_freeContext(scale->sws);
     sws_freeContext(scale->isws[0]);
     sws_freeContext(scale->isws[1]);
     scale->sws = NULL;
-    av_dict_free(&scale->opts);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -486,6 +513,7 @@ static int config_props(AVFilterLink *outlink)
     enum AVPixelFormat outfmt = outlink->format;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     ScaleContext *scale = ctx->priv;
+    uint8_t *flags_val = NULL;
     int ret;
 
     if ((ret = scale_eval_dimensions(ctx)) < 0)
@@ -534,16 +562,16 @@ static int config_props(AVFilterLink *outlink)
                 return AVERROR(ENOMEM);
             *swscs[i] = s;
 
+            ret = av_opt_copy(s, scale->sws_opts);
+            if (ret < 0)
+                return ret;
+
             av_opt_set_int(s, "srcw", inlink0 ->w, 0);
             av_opt_set_int(s, "srch", inlink0 ->h >> !!i, 0);
             av_opt_set_int(s, "src_format", inlink0->format, 0);
             av_opt_set_int(s, "dstw", outlink->w, 0);
             av_opt_set_int(s, "dsth", outlink->h >> !!i, 0);
             av_opt_set_int(s, "dst_format", outfmt, 0);
-            av_opt_set_int(s, "sws_flags", scale->flags, 0);
-            av_opt_set_int(s, "param0", scale->param[0], 0);
-            av_opt_set_int(s, "param1", scale->param[1], 0);
-            av_opt_set_int(s, "threads", ff_filter_get_nb_threads(ctx), 0);
             if (scale->in_range != AVCOL_RANGE_UNSPECIFIED)
                 av_opt_set_int(s, "src_range",
                                scale->in_range == AVCOL_RANGE_JPEG, 0);
@@ -554,13 +582,6 @@ static int config_props(AVFilterLink *outlink)
                 av_opt_set_int(s, "dst_range",
                                scale->out_range == AVCOL_RANGE_JPEG, 0);
 
-            if (scale->opts) {
-                const AVDictionaryEntry *e = NULL;
-                while ((e = av_dict_iterate(scale->opts, e))) {
-                    if ((ret = av_opt_set(s, e->key, e->value, 0)) < 0)
-                        return ret;
-                }
-            }
             /* Override YUV420P default settings to have the correct (MPEG-2) chroma positions
              * MPEG-2 chroma positions are used by convention
              * XXX: support other 4:2:0 pixel formats */
@@ -589,12 +610,17 @@ static int config_props(AVFilterLink *outlink)
     } else
         outlink->sample_aspect_ratio = inlink0->sample_aspect_ratio;
 
-    av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d flags:0x%0x\n",
+    if (scale->sws)
+        av_opt_get(scale->sws, "sws_flags", 0, &flags_val);
+
+    av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d flags:%s\n",
            inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
            inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den,
            outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
            outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den,
-           scale->flags);
+           flags_val);
+    av_freep(&flags_val);
+
     return 0;
 
 fail:
@@ -927,6 +953,14 @@ static const AVClass *child_class_iterate(void **iter)
     return c;
 }
 
+static void *child_next(void *obj, void *prev)
+{
+    ScaleContext *s = obj;
+    if (!prev)
+        return s->sws_opts;
+    return NULL;
+}
+
 #define OFFSET(x) offsetof(ScaleContext, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
@@ -969,8 +1003,8 @@ static const AVOption scale_options[] = {
     { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" },
     { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" },
     { "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256, FLAGS },
-    { "param0", "Scaler param 0",             OFFSET(param[0]),  AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT  }, INT_MIN, INT_MAX, FLAGS },
-    { "param1", "Scaler param 1",             OFFSET(param[1]),  AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT  }, INT_MIN, INT_MAX, FLAGS },
+    { "param0", "Scaler param 0",             OFFSET(param[0]),  AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX  }, -DBL_MAX, DBL_MAX, FLAGS },
+    { "param1", "Scaler param 1",             OFFSET(param[1]),  AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX  }, -DBL_MAX, DBL_MAX, FLAGS },
     { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
          { "init",  "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT},  .flags = FLAGS, .unit = "eval" },
          { "frame", "eval expressions during initialization and per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
@@ -984,6 +1018,7 @@ static const AVClass scale_class = {
     .version          = LIBAVUTIL_VERSION_INT,
     .category         = AV_CLASS_CATEGORY_FILTER,
     .child_class_iterate = child_class_iterate,
+    .child_next          = child_next,
 };
 
 static const AVFilterPad avfilter_vf_scale_inputs[] = {
@@ -1005,7 +1040,8 @@ static const AVFilterPad avfilter_vf_scale_outputs[] = {
 const AVFilter ff_vf_scale = {
     .name            = "scale",
     .description     = NULL_IF_CONFIG_SMALL("Scale the input video size and/or convert the image format."),
-    .init_dict       = init_dict,
+    .preinit         = preinit,
+    .init            = init,
     .uninit          = uninit,
     .priv_size       = sizeof(ScaleContext),
     .priv_class      = &scale_class,
@@ -1046,7 +1082,8 @@ static const AVFilterPad avfilter_vf_scale2ref_outputs[] = {
 const AVFilter ff_vf_scale2ref = {
     .name            = "scale2ref",
     .description     = NULL_IF_CONFIG_SMALL("Scale the input video size and/or convert the image format to the given reference."),
-    .init_dict       = init_dict,
+    .preinit         = preinit,
+    .init            = init,
     .uninit          = uninit,
     .priv_size       = sizeof(ScaleContext),
     .priv_class      = &scale_class,
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 2/8] lavfi: remove AVFilter.init_dict()
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 3/8] lavfi/avfilter: avoid a redundant av_opt_set_dict2() call Anton Khirnov
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

Nothing uses it anymore.

All options on all filters can now be set with normal AVOptions
mechanisms, such as av_opt_set*().
---
 libavfilter/avfilter.c |  2 --
 libavfilter/avfilter.h | 13 -------------
 2 files changed, 15 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index cc5505e65b..e5dd0cfdb0 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -912,8 +912,6 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
 
     if (ctx->filter->init)
         ret = ctx->filter->init(ctx);
-    else if (ctx->filter->init_dict)
-        ret = ctx->filter->init_dict(ctx, options);
     if (ret < 0)
         return ret;
 
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 6d68ebece4..c2ec7a4b5f 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -276,19 +276,6 @@ typedef struct AVFilter {
      */
     int (*init)(AVFilterContext *ctx);
 
-    /**
-     * Should be set instead of @ref AVFilter.init "init" by the filters that
-     * want to pass a dictionary of AVOptions to nested contexts that are
-     * allocated during init.
-     *
-     * On return, the options dict should be freed and replaced with one that
-     * contains all the options which could not be processed by this filter (or
-     * with NULL if all the options were processed).
-     *
-     * Otherwise the semantics is the same as for @ref AVFilter.init "init".
-     */
-    int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
-
     /**
      * Filter uninitialization function.
      *
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 3/8] lavfi/avfilter: avoid a redundant av_opt_set_dict2() call
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 2/8] lavfi: remove AVFilter.init_dict() Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 4/8] lavfi/avfilter: export a multikey dict from process_options() Anton Khirnov
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

Current code first sets AVFilterContext-level options, then aplies the
leftover on the filter's private data. This is unnecessary, applying the
options to AVFilterContext with the AV_OPT_SEARCH_CHILDREN flag
accomplishes the same effect.
---
 libavfilter/avfilter.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index e5dd0cfdb0..689c91891e 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -887,7 +887,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
 {
     int ret = 0;
 
-    ret = av_opt_set_dict(ctx, options);
+    ret = av_opt_set_dict2(ctx, options, AV_OPT_SEARCH_CHILDREN);
     if (ret < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
         return ret;
@@ -902,14 +902,6 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
         ctx->thread_type = 0;
     }
 
-    if (ctx->filter->priv_class) {
-        ret = av_opt_set_dict2(ctx->priv, options, AV_OPT_SEARCH_CHILDREN);
-        if (ret < 0) {
-            av_log(ctx, AV_LOG_ERROR, "Error applying options to the filter.\n");
-            return ret;
-        }
-    }
-
     if (ctx->filter->init)
         ret = ctx->filter->init(ctx);
     if (ret < 0)
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 4/8] lavfi/avfilter: export a multikey dict from process_options()
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 2/8] lavfi: remove AVFilter.init_dict() Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 3/8] lavfi/avfilter: avoid a redundant av_opt_set_dict2() call Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 5/8] lavfi/avfilter: simplify process_options() Anton Khirnov
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

This way the function does not need to be able to match keys to
AVOptions, which will be useful in future commits.
---
 libavfilter/avfilter.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 689c91891e..278d5868de 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -850,17 +850,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
                 return ret;
             }
         } else {
-            o = av_opt_find(ctx->priv, key, NULL, 0,
-                            AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
-            if (!o) {
-                av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
-                av_free(value);
-                av_free(parsed_key);
-                return AVERROR_OPTION_NOT_FOUND;
-            }
-            av_dict_set(options, key, value,
-                        (o->type == AV_OPT_TYPE_FLAGS &&
-                         (value[0] == '-' || value[0] == '+')) ? AV_DICT_APPEND : 0);
+            av_dict_set(options, key, value, AV_DICT_MULTIKEY);
         }
 
         av_free(value);
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 5/8] lavfi/avfilter: simplify process_options()
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
                   ` (2 preceding siblings ...)
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 4/8] lavfi/avfilter: export a multikey dict from process_options() Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 6/8] lavfi/avfilter: process options for filters without a private class Anton Khirnov
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

This function currently treats AVFilterContext options and
filter-private options differently: the former are immediately applied,
while the latter are stored in a dictionary to be applied later.

There is no good reason for having two branches - storing all options in
the dictionary is simpler and achieves the same effect (since it is
later applied with av_opt_set_dict()).

This will also be useful in future commits.
---
 libavfilter/avfilter.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 278d5868de..43dfb11bdb 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -842,16 +842,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
 
         av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
 
-        if (av_opt_find(ctx, key, NULL, 0, 0)) {
-            ret = av_opt_set(ctx, key, value, 0);
-            if (ret < 0) {
-                av_free(value);
-                av_free(parsed_key);
-                return ret;
-            }
-        } else {
-            av_dict_set(options, key, value, AV_DICT_MULTIKEY);
-        }
+        av_dict_set(options, key, value, AV_DICT_MULTIKEY);
 
         av_free(value);
         av_free(parsed_key);
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 6/8] lavfi/avfilter: process options for filters without a private class
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
                   ` (3 preceding siblings ...)
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 5/8] lavfi/avfilter: simplify process_options() Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 7/8] lavfi/graphparser: improve applying graph-level sws options Anton Khirnov
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

It still makes sense to apply AVFilterContext-level options to such
filters.
---
 libavfilter/avfilter.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 43dfb11bdb..c2ecdffa6f 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -812,7 +812,8 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
     while (*args) {
         const char *shorthand = NULL;
 
-        o = av_opt_next(ctx->priv, o);
+        if (ctx->filter->priv_class)
+            o = av_opt_next(ctx->priv, o);
         if (o) {
             if (o->type == AV_OPT_TYPE_CONST || o->offset == offset)
                 continue;
@@ -835,7 +836,10 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
             args++;
         if (parsed_key) {
             key = parsed_key;
-            while ((o = av_opt_next(ctx->priv, o))); /* discard all remaining shorthand */
+
+            /* discard all remaining shorthand */
+            if (ctx->filter->priv_class)
+                while ((o = av_opt_next(ctx->priv, o)));
         } else {
             key = shorthand;
         }
@@ -904,12 +908,6 @@ int avfilter_init_str(AVFilterContext *filter, const char *args)
     int ret = 0;
 
     if (args && *args) {
-        if (!filter->filter->priv_class) {
-            av_log(filter, AV_LOG_ERROR, "This filter does not take any "
-                   "options, but options were provided: %s.\n", args);
-            return AVERROR(EINVAL);
-        }
-
         ret = process_options(filter, &options, args);
         if (ret < 0)
             goto fail;
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 7/8] lavfi/graphparser: improve applying graph-level sws options
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
                   ` (4 preceding siblings ...)
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 6/8] lavfi/avfilter: process options for filters without a private class Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 8/8] lavfi/graphparser: drop a redundant label Anton Khirnov
  2023-01-09 12:51 ` [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Nicolas George
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

The current code will apply them if the options string does not contain
a 'flags' substring, and will do so by appending the graph-level option
string to the filter option string (with the standard ':' separator).
This is flawed in at least the following ways:
- naive substring matching without actually parsing the options string
  may lead to false positives (e.g. flags are specified by shorthand)
  and false negatives (e.g. the 'flags' substring is not actually the
  option name)
- graph-level sws options are not limited to flags, but may set
  arbitrary sws options

This commit simply applies the graph-level options with
av_set_options_string() and lets them be overridden as desired by the
user-specified filter options (if any). This is also shorter and avoids
extra string handling.
---
 libavfilter/graphparser.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index 1385c3ae71..c8b0af5aba 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -25,6 +25,8 @@
 
 #include "libavutil/avstring.h"
 #include "libavutil/mem.h"
+#include "libavutil/opt.h"
+
 #include "avfilter.h"
 
 #define WHITESPACES " \n\t\r"
@@ -101,7 +103,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
     const AVFilter *filt;
     char name2[30];
     const char *inst_name = NULL, *filt_name = NULL;
-    char *tmp_args = NULL;
     int ret, k;
 
     av_strlcpy(name2, name, sizeof(name2));
@@ -136,16 +137,10 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
         return AVERROR(ENOMEM);
     }
 
-    if (!strcmp(filt_name, "scale") && (!args || !strstr(args, "flags")) &&
-        ctx->scale_sws_opts) {
-        if (args) {
-            tmp_args = av_asprintf("%s:%s",
-                    args, ctx->scale_sws_opts);
-            if (!tmp_args)
-                return AVERROR(ENOMEM);
-            args = tmp_args;
-        } else
-            args = ctx->scale_sws_opts;
+    if (!strcmp(filt_name, "scale") && ctx->scale_sws_opts) {
+        ret = av_set_options_string(*filt_ctx, ctx->scale_sws_opts, "=", ":");
+        if (ret < 0)
+            return ret;
     }
 
     ret = avfilter_init_str(*filt_ctx, args);
@@ -159,7 +154,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
         *filt_ctx = NULL;
     }
 
-    av_free(tmp_args);
     return ret;
 }
 
-- 
2.35.1

_______________________________________________
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".

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

* [FFmpeg-devel] [PATCH 8/8] lavfi/graphparser: drop a redundant label
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
                   ` (5 preceding siblings ...)
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 7/8] lavfi/graphparser: improve applying graph-level sws options Anton Khirnov
@ 2023-01-08 12:58 ` Anton Khirnov
  2023-01-09 12:51 ` [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Nicolas George
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-01-08 12:58 UTC (permalink / raw)
  To: ffmpeg-devel

---
 libavfilter/graphparser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index c8b0af5aba..0759c39014 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -421,7 +421,7 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
     filters += strspn(filters, WHITESPACES);
 
     if ((ret = parse_sws_flags(&filters, graph)) < 0)
-        goto fail;
+        goto end;
 
     do {
         AVFilterContext *filter;
@@ -463,7 +463,7 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
     *outputs = open_outputs;
     return 0;
 
- fail:end:
+end:
     while (graph->nb_filters)
         avfilter_free(graph->filters[0]);
     av_freep(&graph->filters);
-- 
2.35.1

_______________________________________________
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".

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

* Re: [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly
  2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
                   ` (6 preceding siblings ...)
  2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 8/8] lavfi/graphparser: drop a redundant label Anton Khirnov
@ 2023-01-09 12:51 ` Nicolas George
  7 siblings, 0 replies; 9+ messages in thread
From: Nicolas George @ 2023-01-09 12:51 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Anton Khirnov (12023-01-08):
> Avoid using the dictionary mechanism, which is non-introspectable. As
> this is the only user of AVFilter.init_dict(), this callback can now be
> removed.

Series looks good to me, thanks.

Regards,

-- 
  Nicolas George
_______________________________________________
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".

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

end of thread, other threads:[~2023-01-09 12:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-08 12:58 [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 2/8] lavfi: remove AVFilter.init_dict() Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 3/8] lavfi/avfilter: avoid a redundant av_opt_set_dict2() call Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 4/8] lavfi/avfilter: export a multikey dict from process_options() Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 5/8] lavfi/avfilter: simplify process_options() Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 6/8] lavfi/avfilter: process options for filters without a private class Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 7/8] lavfi/graphparser: improve applying graph-level sws options Anton Khirnov
2023-01-08 12:58 ` [FFmpeg-devel] [PATCH 8/8] lavfi/graphparser: drop a redundant label Anton Khirnov
2023-01-09 12:51 ` [FFmpeg-devel] [PATCH 1/8] lavfi/vf_scale: allow passing options to swscale directly Nicolas George

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