History

lavfi/graphparser: improve applying graph-level sws options

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.

Anton Khirnov committed 3 years ago

Commit ca67a781 parent 1c185301 file · +6 −12Browse files

Showing the changes to libavfilter/graphparser.c (1 of 1 file). Show all

Unified · Split

libavfilter/graphparser.c+6−12
@@ -25,6 +25,8 @@ · 24 unmodified lines
2525
2626 #include "libavutil/avstring.h"
2727 #include "libavutil/mem.h"
28+#include "libavutil/opt.h"
29+
2830 #include "avfilter.h"
2931
3032 #define WHITESPACES " \n\t\r"
@@ -101,7 +103,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 70 unmodified lines
101103 const AVFilter *filt;
102104 char name2[30];
103105 const char *inst_name = NULL, *filt_name = NULL;
104− char *tmp_args = NULL;
105106 int ret, k;
106107
107108 av_strlcpy(name2, name, sizeof(name2));
@@ -136,16 +137,10 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 28 unmodified lines
136137 return AVERROR(ENOMEM);
137138 }
138139
139− if (!strcmp(filt_name, "scale") && (!args || !strstr(args, "flags")) &&
140− ctx->scale_sws_opts) {
141− if (args) {
142− tmp_args = av_asprintf("%s:%s",
143− args, ctx->scale_sws_opts);
144− if (!tmp_args)
145− return AVERROR(ENOMEM);
146− args = tmp_args;
147− } else
148− args = ctx->scale_sws_opts;
140+ if (!strcmp(filt_name, "scale") && ctx->scale_sws_opts) {
141+ ret = av_set_options_string(*filt_ctx, ctx->scale_sws_opts, "=", ":");
142+ if (ret < 0)
143+ return ret;
149144 }
150145
151146 ret = avfilter_init_str(*filt_ctx, args);
@@ -159,7 +154,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 7 unmodified lines
159154 *filt_ctx = NULL;
160155 }
161156
162− av_free(tmp_args);
163157 return ret;
164158 }
165159

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t