[FFmpeg-cvslog] avfilter/af_amix: fix filtering if specified weights are negative

Paul B Mahol git at videolan.org
Thu Oct 3 11:45:16 EEST 2019


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Oct  3 10:27:56 2019 +0200| [d492907e7817b9ba00c01476e61bf5fb7fae5f6a] | committer: Paul B Mahol

avfilter/af_amix: fix filtering if specified weights are negative

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d492907e7817b9ba00c01476e61bf5fb7fae5f6a
---

 libavfilter/af_amix.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index ec2556f920..89a1b0568f 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -212,21 +212,21 @@ static void calculate_scales(MixContext *s, int nb_samples)
 
     for (i = 0; i < s->nb_inputs; i++)
         if (s->input_state[i] & INPUT_ON)
-            weight_sum += s->weights[i];
+            weight_sum += FFABS(s->weights[i]);
 
     for (i = 0; i < s->nb_inputs; i++) {
         if (s->input_state[i] & INPUT_ON) {
-            if (s->scale_norm[i] > weight_sum / s->weights[i]) {
-                s->scale_norm[i] -= ((s->weight_sum / s->weights[i]) / s->nb_inputs) *
+            if (s->scale_norm[i] > weight_sum / FFABS(s->weights[i])) {
+                s->scale_norm[i] -= ((s->weight_sum / FFABS(s->weights[i])) / s->nb_inputs) *
                                     nb_samples / (s->dropout_transition * s->sample_rate);
-                s->scale_norm[i] = FFMAX(s->scale_norm[i], weight_sum / s->weights[i]);
+                s->scale_norm[i] = FFMAX(s->scale_norm[i], weight_sum / FFABS(s->weights[i]));
             }
         }
     }
 
     for (i = 0; i < s->nb_inputs; i++) {
         if (s->input_state[i] & INPUT_ON)
-            s->input_scale[i] = 1.0f / s->scale_norm[i];
+            s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]);
         else
             s->input_scale[i] = 0.0f;
     }
@@ -270,7 +270,7 @@ static int config_output(AVFilterLink *outlink)
     if (!s->input_scale || !s->scale_norm)
         return AVERROR(ENOMEM);
     for (i = 0; i < s->nb_inputs; i++)
-        s->scale_norm[i] = s->weight_sum / s->weights[i];
+        s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]);
     calculate_scales(s, 0);
 
     av_get_channel_layout_string(buf, sizeof(buf), -1, outlink->channel_layout);
@@ -540,12 +540,12 @@ static av_cold int init(AVFilterContext *ctx)
         p = NULL;
         sscanf(arg, "%f", &last_weight);
         s->weights[i] = last_weight;
-        s->weight_sum += last_weight;
+        s->weight_sum += FFABS(last_weight);
     }
 
     for (; i < s->nb_inputs; i++) {
         s->weights[i] = last_weight;
-        s->weight_sum += last_weight;
+        s->weight_sum += FFABS(last_weight);
     }
 
     return 0;



More information about the ffmpeg-cvslog mailing list