History

avfilter/vf_mix: add support for commands

Paul B Mahol committed 5 years ago

Commit d0a24bf1 parent 3583d2a2 files · +74 −31Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_mix.c+56−31
@@ -67,11 +67,44 @@ static int query_formats(AVFilterContext *ctx) · 66 unmodified lines
6767 return ff_set_common_formats(ctx, formats);
6868 }
6969
70−static av_cold int init(AVFilterContext *ctx)
70+static int parse_weights(AVFilterContext *ctx)
7171 {
7272 MixContext *s = ctx->priv;
7373 char *p, *arg, *saveptr = NULL;
74− int i, ret, last = 0;
74+ int i, last = 0;
75+
76+ s->wfactor = 0.f;
77+ p = s->weights_str;
78+ for (i = 0; i < s->nb_inputs; i++) {
79+ if (!(arg = av_strtok(p, " |", &saveptr)))
80+ break;
81+
82+ p = NULL;
83+ if (av_sscanf(arg, "%f", &s->weights[i]) != 1) {
84+ av_log(ctx, AV_LOG_ERROR, "Invalid syntax for weights[%d].\n", i);
85+ return AVERROR(EINVAL);
86+ }
87+ s->wfactor += s->weights[i];
88+ last = i;
89+ }
90+
91+ for (; i < s->nb_inputs; i++) {
92+ s->weights[i] = s->weights[last];
93+ s->wfactor += s->weights[i];
94+ }
95+ if (s->scale == 0) {
96+ s->wfactor = 1 / s->wfactor;
97+ } else {
98+ s->wfactor = s->scale;
99+ }
100+
101+ return 0;
102+}
103+
104+static av_cold int init(AVFilterContext *ctx)
105+{
106+ MixContext *s = ctx->priv;
107+ int ret;
75108
76109 s->tmix = !strcmp(ctx->filter->name, "tmix");
77110
@@ -84,7 +117,7 @@ static av_cold int init(AVFilterContext *ctx) · 6 unmodified lines
84117 return AVERROR(ENOMEM);
85118
86119 if (!s->tmix) {
87− for (i = 0; i < s->nb_inputs; i++) {
120+ for (int i = 0; i < s->nb_inputs; i++) {
88121 AVFilterPad pad = { 0 };
89122
90123 pad.type = AVMEDIA_TYPE_VIDEO;
@@ -99,30 +132,7 @@ static av_cold int init(AVFilterContext *ctx) · 8 unmodified lines
99132 }
100133 }
101134
102− p = s->weights_str;
103− for (i = 0; i < s->nb_inputs; i++) {
104− if (!(arg = av_strtok(p, " ", &saveptr)))
105− break;
106−
107− p = NULL;
108− if (av_sscanf(arg, "%f", &s->weights[i]) != 1) {
109− av_log(ctx, AV_LOG_ERROR, "Invalid syntax for weights[%d].\n", i);
110− return AVERROR(EINVAL);
111− }
112− s->wfactor += s->weights[i];
113− last = i;
114− }
115− for (; i < s->nb_inputs; i++) {
116− s->weights[i] = s->weights[last];
117− s->wfactor += s->weights[i];
118− }
119− if (s->scale == 0) {
120− s->wfactor = 1 / s->wfactor;
121− } else {
122− s->wfactor = s->scale;
123− }
124−
125− return 0;
135+ return parse_weights(ctx);
126136 }
127137
128138 typedef struct ThreadData {
@@ -303,6 +313,18 @@ static av_cold void uninit(AVFilterContext *ctx) · 174 unmodified lines
303313 av_freep(&s->frames);
304314 }
305315
316+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
317+ char *res, int res_len, int flags)
318+{
319+ int ret;
320+
321+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
322+ if (ret < 0)
323+ return ret;
324+
325+ return parse_weights(ctx);
326+}
327+
306328 static int activate(AVFilterContext *ctx)
307329 {
308330 MixContext *s = ctx->priv;
@@ -311,11 +333,12 @@ static int activate(AVFilterContext *ctx) · 2 unmodified lines
311333
312334 #define OFFSET(x) offsetof(MixContext, x)
313335 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
336+#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
314337
315338 static const AVOption mix_options[] = {
316339 { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=2}, 2, INT16_MAX, .flags = FLAGS },
317− { "weights", "set weight for each input", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, .flags = FLAGS },
318− { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = FLAGS },
340+ { "weights", "set weight for each input", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, .flags = TFLAGS },
341+ { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = TFLAGS },
319342 { "duration", "how to determine end of stream", OFFSET(duration), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, .flags = FLAGS, "duration" },
320343 { "longest", "Duration of longest input", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "duration" },
321344 { "shortest", "Duration of shortest input", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "duration" },
@@ -347,6 +370,7 @@ AVFilter ff_vf_mix = { · 25 unmodified lines
347370 .activate = activate,
348371 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS |
349372 AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
373+ .process_command = process_command,
350374 };
351375
352376 #endif /* CONFIG_MIX_FILTER */
@@ -395,8 +419,8 @@ static int tmix_filter_frame(AVFilterLink *inlink, AVFrame *in) · 42 unmodified lines
395419
396420 static const AVOption tmix_options[] = {
397421 { "frames", "set number of successive frames to mix", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=3}, 1, 128, .flags = FLAGS },
398− { "weights", "set weight for each frame", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1 1"}, 0, 0, .flags = FLAGS },
399− { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = FLAGS },
422+ { "weights", "set weight for each frame", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1 1"}, 0, 0, .flags = TFLAGS },
423+ { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT16_MAX, .flags = TFLAGS },
400424 { NULL },
401425 };
402426
@@ -422,6 +446,7 @@ AVFilter ff_vf_tmix = { · 19 unmodified lines
422446 .init = init,
423447 .uninit = uninit,
424448 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
449+ .process_command = process_command,
425450 };
426451
427452 #endif /* CONFIG_TMIX_FILTER */

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