[FFmpeg-cvslog] avfilter/vf_mix: improve speed of processing

Paul B Mahol git at videolan.org
Tue Feb 15 00:57:07 EET 2022


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Feb 14 23:54:24 2022 +0100| [0da255dd10fe8ca424291da583b32d9f1afeb3f9] | committer: Paul B Mahol

avfilter/vf_mix: improve speed of processing

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

 libavfilter/vf_mix.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_mix.c b/libavfilter/vf_mix.c
index b701b44faa..c97c09daef 100644
--- a/libavfilter/vf_mix.c
+++ b/libavfilter/vf_mix.c
@@ -138,6 +138,7 @@ static int mix_frames(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
     ThreadData *td = arg;
     AVFrame **in = td->in;
     AVFrame *out = td->out;
+    const float *weights = s->weights;
     int i, p, x, y;
 
     if (s->depth <= 8) {
@@ -148,15 +149,15 @@ static int mix_frames(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
             for (y = slice_start; y < slice_end; y++) {
                 for (x = 0; x < s->linesize[p]; x++) {
-                    int val = 0;
+                    float val = 0.f;
 
                     for (i = 0; i < s->nb_inputs; i++) {
                         uint8_t src = in[i]->data[p][y * in[i]->linesize[p] + x];
 
-                        val += src * s->weights[i];
+                        val += src * weights[i];
                     }
 
-                    dst[x] = av_clip_uint8(val * s->wfactor);
+                    dst[x] = av_clip_uint8(lrintf(val * s->wfactor));
                 }
 
                 dst += out->linesize[p];
@@ -170,15 +171,15 @@ static int mix_frames(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
             for (y = slice_start; y < slice_end; y++) {
                 for (x = 0; x < s->linesize[p] / 2; x++) {
-                    int val = 0;
+                    float val = 0.f;
 
                     for (i = 0; i < s->nb_inputs; i++) {
                         uint16_t src = AV_RN16(in[i]->data[p] + y * in[i]->linesize[p] + x * 2);
 
-                        val += src * s->weights[i];
+                        val += src * weights[i];
                     }
 
-                    dst[x] = av_clip(val * s->wfactor, 0, s->max);
+                    dst[x] = av_clip(lrintf(val * s->wfactor), 0, s->max);
                 }
 
                 dst += out->linesize[p] / 2;



More information about the ffmpeg-cvslog mailing list