History

avfilter/af_amix: make weights option runtime configured

Paul B Mahol committed 6 years ago

Commit d8147c41 parent a124f4e2 files · +57 −20Browse files

Unified · Split

2 files
  1. doc/filters.texi +8 −0
  2. libavfilter/af_amix.c +49 −20
doc/filters.texi+8−0
@@ -1703,6 +1703,14 @@ Specify weight of each input audio stream as sequence. · 1702 unmodified lines
17031703 Each weight is separated by space. By default all inputs have same weight.
17041704 @end table
17051705
1706+@subsection Commands
1707+
1708+This filter supports the following commands:
1709+@table @option
1710+@item weights
1711+Syntax is same as option with same name.
1712+@end table
1713+
17061714 @section amultiply
17071715
17081716 Multiply first audio stream with second audio stream and store result
libavfilter/af_amix.c+49−20
@@ -181,6 +181,7 @@ typedef struct MixContext { · 180 unmodified lines
181181 #define OFFSET(x) offsetof(MixContext, x)
182182 #define A AV_OPT_FLAG_AUDIO_PARAM
183183 #define F AV_OPT_FLAG_FILTERING_PARAM
184+#define T AV_OPT_FLAG_RUNTIME_PARAM
184185 static const AVOption amix_options[] = {
185186 { "inputs", "Number of inputs.",
186187 OFFSET(nb_inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT16_MAX, A|F },
@@ -193,7 +194,7 @@ static const AVOption amix_options[] = { · 6 unmodified lines
193194 "renormalization when an input stream ends.",
194195 OFFSET(dropout_transition), AV_OPT_TYPE_FLOAT, { .dbl = 2.0 }, 0, INT_MAX, A|F },
195196 { "weights", "Set weight for each input.",
196− OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F },
197+ OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F|T },
197198 { NULL }
198199 };
199200
@@ -504,12 +505,37 @@ static int activate(AVFilterContext *ctx) · 304 unmodified lines
504505 return 0;
505506 }
506507
507−static av_cold int init(AVFilterContext *ctx)
508+static void parse_weights(AVFilterContext *ctx)
508509 {
509510 MixContext *s = ctx->priv;
510511 float last_weight = 1.f;
511− int i, ret;
512512 char *p;
513+ int i;
514+
515+ s->weight_sum = 0.f;
516+ p = s->weights_str;
517+ for (i = 0; i < s->nb_inputs; i++) {
518+ last_weight = av_strtod(p, &p);
519+ s->weights[i] = last_weight;
520+ s->weight_sum += FFABS(last_weight);
521+ if (p && *p) {
522+ p++;
523+ } else {
524+ i++;
525+ break;
526+ }
527+ }
528+
529+ for (; i < s->nb_inputs; i++) {
530+ s->weights[i] = last_weight;
531+ s->weight_sum += FFABS(last_weight);
532+ }
533+}
534+
535+static av_cold int init(AVFilterContext *ctx)
536+{
537+ MixContext *s = ctx->priv;
538+ int i, ret;
513539
514540 for (i = 0; i < s->nb_inputs; i++) {
515541 AVFilterPad pad = { 0 };
@@ -533,23 +559,7 @@ static av_cold int init(AVFilterContext *ctx) · 17 unmodified lines
533559 if (!s->weights)
534560 return AVERROR(ENOMEM);
535561
536− p = s->weights_str;
537− for (i = 0; i < s->nb_inputs; i++) {
538− last_weight = av_strtod(p, &p);
539− s->weights[i] = last_weight;
540− s->weight_sum += FFABS(last_weight);
541− if (p && *p) {
542− p++;
543− } else {
544− i++;
545− break;
546− }
547− }
548−
549− for (; i < s->nb_inputs; i++) {
550− s->weights[i] = last_weight;
551− s->weight_sum += FFABS(last_weight);
552− }
562+ parse_weights(ctx);
553563
554564 return 0;
555565 }
@@ -604,6 +614,24 @@ fail: · 48 unmodified lines
604614 return ret;
605615 }
606616
617+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
618+ char *res, int res_len, int flags)
619+{
620+ MixContext *s = ctx->priv;
621+ int ret;
622+
623+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
624+ if (ret < 0)
625+ return ret;
626+
627+ parse_weights(ctx);
628+ for (int i = 0; i < s->nb_inputs; i++)
629+ s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]);
630+ calculate_scales(s, 0);
631+
632+ return 0;
633+}
634+
607635 static const AVFilterPad avfilter_af_amix_outputs[] = {
608636 {
609637 .name = "default",
@@ -624,5 +652,6 @@ AVFilter ff_af_amix = { · 14 unmodified lines
624652 .query_formats = query_formats,
625653 .inputs = NULL,
626654 .outputs = avfilter_af_amix_outputs,
655+ .process_command = process_command,
627656 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
628657 };

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