[FFmpeg-devel,V1,3/3] lavf/minterpolate: use av_global_blend_row for blend performance.

Submitted by Jun Zhao on Sept. 25, 2018, 3:27 p.m.

Details

Message ID 1537889235-17619-3-git-send-email-mypopydev@gmail.com
State New
Headers show

Commit Message

Jun Zhao Sept. 25, 2018, 3:27 p.m.
Use the av_global_blend_row for blend mode performance.
About 9x (43fps -> 415fps) in 1080P, use the command like:
ffmpeg -i skyfall2-trailer.mp4 -vf minterpolate=mi_mode=blend \
-an -f null /dev/nul

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
---
 libavfilter/vf_minterpolate.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c
index c6a5e63..c9fd418 100644
--- a/libavfilter/vf_minterpolate.c
+++ b/libavfilter/vf_minterpolate.c
@@ -27,6 +27,7 @@ 
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixelutils.h"
+#include "libavutil/blend.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
@@ -1113,6 +1114,10 @@  static void interpolate(AVFilterLink *inlink, AVFrame *avf_out)
             for (plane = 0; plane < mi_ctx->nb_planes; plane++) {
                 int width = avf_out->width;
                 int height = avf_out->height;
+                uint8_t *src0 = NULL;
+                uint8_t *src1 = NULL;
+                uint8_t *dst = NULL;
+                uint8_t alpha1 = (uint8_t)(alpha*256/1024);
 
                 if (plane == 1 || plane == 2) {
                     width = AV_CEIL_RSHIFT(width, mi_ctx->log2_chroma_w);
@@ -1120,11 +1125,12 @@  static void interpolate(AVFilterLink *inlink, AVFrame *avf_out)
                 }
 
                 for (y = 0; y < height; y++) {
-                    for (x = 0; x < width; x++) {
-                        avf_out->data[plane][x + y * avf_out->linesize[plane]] =
-                            (alpha  * mi_ctx->frames[2].avf->data[plane][x + y * mi_ctx->frames[2].avf->linesize[plane]] +
-                             (ALPHA_MAX - alpha) * mi_ctx->frames[1].avf->data[plane][x + y * mi_ctx->frames[1].avf->linesize[plane]] + 512) >> 10;
-                    }
+                    src0 = &mi_ctx->frames[2].avf->data[plane][y * mi_ctx->frames[2].avf->linesize[plane]];
+                    src1 = &mi_ctx->frames[1].avf->data[plane][y * mi_ctx->frames[1].avf->linesize[plane]];
+                    dst = &avf_out->data[plane][y * avf_out->linesize[plane]];
+
+                    av_global_blend_row(src0, src1, (const uint8_t *)&alpha1, dst, width);
+
                 }
             }