[FFmpeg-devel] [PATCH 3/3] lavfi/motion_estimation: use pixelutils API for sad.

Jun Zhao mypopydev at gmail.com
Wed Jul 11 01:37:37 EEST 2018


use pixelutils API for sad in motion estimation.

Signed-off-by: Jun Zhao <mypopydev at gmail.com>
---
 libavfilter/motion_estimation.c |   12 +++++++++---
 libavfilter/motion_estimation.h |    2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavfilter/motion_estimation.c b/libavfilter/motion_estimation.c
index 0f9ba21..8ccd879 100644
--- a/libavfilter/motion_estimation.c
+++ b/libavfilter/motion_estimation.c
@@ -54,6 +54,8 @@ void ff_me_init_context(AVMotionEstContext *me_ctx, int mb_size, int search_para
     me_ctx->x_max = x_max;
     me_ctx->y_min = y_min;
     me_ctx->y_max = y_max;
+
+    me_ctx->sad = av_pixelutils_get_sad_fn(av_ceil_log2_c(mb_size), av_ceil_log2_c(mb_size), 0, NULL);
 }
 
 uint64_t ff_me_cmp_sad(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int x_mv, int y_mv)
@@ -67,9 +69,13 @@ uint64_t ff_me_cmp_sad(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int x_mv,
     data_ref += y_mv * linesize;
     data_cur += y_mb * linesize;
 
-    for (j = 0; j < me_ctx->mb_size; j++)
-        for (i = 0; i < me_ctx->mb_size; i++)
-            sad += FFABS(data_ref[x_mv + i + j * linesize] - data_cur[x_mb + i + j * linesize]);
+    if (me_ctx->sad) {
+        sad = me_ctx->sad(data_ref+x_mv, linesize, data_cur+x_mb, linesize);
+    } else {
+        for (j = 0; j < me_ctx->mb_size; j++)
+            for (i = 0; i < me_ctx->mb_size; i++)
+                sad += FFABS(data_ref[x_mv + i + j * linesize] - data_cur[x_mb + i + j * linesize]);
+    }
 
     return sad;
 }
diff --git a/libavfilter/motion_estimation.h b/libavfilter/motion_estimation.h
index 6ae29dd..9f7710b 100644
--- a/libavfilter/motion_estimation.h
+++ b/libavfilter/motion_estimation.h
@@ -22,6 +22,7 @@
 #define AVFILTER_MOTION_ESTIMATION_H
 
 #include "libavutil/avutil.h"
+#include "libavutil/pixelutils.h"
 
 #define AV_ME_METHOD_ESA        1
 #define AV_ME_METHOD_TSS        2
@@ -59,6 +60,7 @@ typedef struct AVMotionEstContext {
 
     uint64_t (*get_cost)(struct AVMotionEstContext *me_ctx, int x_mb, int y_mb,
                          int mv_x, int mv_y);
+    av_pixelutils_sad_fn sad;
 } AVMotionEstContext;
 
 void ff_me_init_context(AVMotionEstContext *me_ctx, int mb_size, int search_param,
-- 
1.7.1



More information about the ffmpeg-devel mailing list