From 2a28712b44b0b462a33ee6e91c98e8e19549fede Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 27 Apr 2018 15:55:53 +0200 Subject: f_lavfi: support setting common filter options like "threads" AVFilterContext instances support some additional AVOptions over the actual filter. This includes useful options like "threads". We didn't support setting those for the "direct" wrapper (--vf=yadif:threads=1 failed). Change this. It requires setting options on the AVFilterContext directly, except the code for positional parameters still needs to access the actual filter's AVOptions. --- common/av_common.c | 11 +++++++++-- common/av_common.h | 1 + filters/f_lavfi.c | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common/av_common.c b/common/av_common.c index 2c959ffe4f..3ea1ceb872 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -313,7 +313,7 @@ void mp_avdict_print_unset(struct mp_log *log, int msgl, AVDictionary *dict) // to the name of the n-th parameter. static void resolve_positional_arg(void *avobj, char **name) { - if (!*name || (*name)[0] != '@') + if (!*name || (*name)[0] != '@' || !avobj) return; char *end = NULL; @@ -344,12 +344,19 @@ static void resolve_positional_arg(void *avobj, char **name) // Options which fail to set (error or not found) are printed to log. // Returns: >=0 success, <0 failed to set an option int mp_set_avopts(struct mp_log *log, void *avobj, char **kv) +{ + return mp_set_avopts_pos(log, avobj, avobj, kv); +} + +// Like mp_set_avopts(), but the posargs argument is used to resolve positional +// arguments. If posargs==NULL, positional args are disabled. +int mp_set_avopts_pos(struct mp_log *log, void *avobj, void *posargs, char **kv) { int success = 0; for (int n = 0; kv && kv[n * 2]; n++) { char *k = kv[n * 2 + 0]; char *v = kv[n * 2 + 1]; - resolve_positional_arg(avobj, &k); + resolve_positional_arg(posargs, &k); int r = av_opt_set(avobj, k, v, AV_OPT_SEARCH_CHILDREN); if (r == AVERROR_OPTION_NOT_FOUND) { mp_err(log, "AVOption '%s' not found.\n", k); diff --git a/common/av_common.h b/common/av_common.h index 6cbadb4a96..4037afa0ad 100644 --- a/common/av_common.h +++ b/common/av_common.h @@ -47,5 +47,6 @@ const char *mp_codec_from_av_codec_id(int codec_id); void mp_set_avdict(struct AVDictionary **dict, char **kv); void mp_avdict_print_unset(struct mp_log *log, int msgl, struct AVDictionary *d); int mp_set_avopts(struct mp_log *log, void *avobj, char **kv); +int mp_set_avopts_pos(struct mp_log *log, void *avobj, void *posargs, char **kv); #endif diff --git a/filters/f_lavfi.c b/filters/f_lavfi.c index 2c01eaf59c..66e045eb2c 100644 --- a/filters/f_lavfi.c +++ b/filters/f_lavfi.c @@ -271,7 +271,8 @@ static void precreate_graph(struct lavfi *c, bool first_init) goto error; } - if (mp_set_avopts(c->log, filter->priv, c->direct_filter_opts) < 0) + if (mp_set_avopts_pos(c->log, filter, filter->priv, + c->direct_filter_opts) < 0) goto error; if (avfilter_init_str(filter, NULL) < 0) { -- cgit v1.2.3