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
25 25
26#include "libavutil/avstring.h"26#include "libavutil/avstring.h"
27#include "libavutil/mem.h"27#include "libavutil/mem.h"
28#include "libavutil/opt.h"
29
28#include "avfilter.h"30#include "avfilter.h"
29 31
30#define WHITESPACES " \n\t\r"32#define WHITESPACES " \n\t\r"
@@ -101,7 +103,6 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 70 unmodified lines
101 const AVFilter *filt;103 const AVFilter *filt;
102 char name2[30];104 char name2[30];
103 const char *inst_name = NULL, *filt_name = NULL;105 const char *inst_name = NULL, *filt_name = NULL;
104 char *tmp_args = NULL;
105 int ret, k;106 int ret, k;
106 107
107 av_strlcpy(name2, name, sizeof(name2));108 av_strlcpy(name2, name, sizeof(name2));
@@ -136,16 +137,10 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 28 unmodified lines
136 return AVERROR(ENOMEM);137 return AVERROR(ENOMEM);
137 }138 }
138 139
139 if (!strcmp(filt_name, "scale") && (!args || !strstr(args, "flags")) &&140 if (!strcmp(filt_name, "scale") && ctx->scale_sws_opts) {
140 ctx->scale_sws_opts) {141 ret = av_set_options_string(*filt_ctx, ctx->scale_sws_opts, "=", ":");
141 if (args) {142 if (ret < 0)
142 tmp_args = av_asprintf("%s:%s",143 return ret;
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;
149 }144 }
150 145
151 ret = avfilter_init_str(*filt_ctx, args);146 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
159 *filt_ctx = NULL;154 *filt_ctx = NULL;
160 }155 }
161 156
162 av_free(tmp_args);
163 return ret;157 return ret;
164}158}
165 159

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