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.
This commit is contained in:
wm4 2018-04-27 15:55:53 +02:00 committed by Jan Ekström
parent fff5fda74b
commit 2a28712b44
3 changed files with 12 additions and 3 deletions

View File

@ -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);

View File

@ -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

View File

@ -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) {