From patchwork Sun Nov 4 12:06:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 10917 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2FC1E44CB0E for ; Sun, 4 Nov 2018 14:06:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F61B68A899; Sun, 4 Nov 2018 14:05:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7922F68A884 for ; Sun, 4 Nov 2018 14:05:42 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EFD11E15BA; Sun, 4 Nov 2018 13:06:15 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OGGs-ze8NBRw; Sun, 4 Nov 2018 13:06:14 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7234DE06C3; Sun, 4 Nov 2018 13:06:14 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Nov 2018 13:06:05 +0100 Message-Id: <20181104120606.4177-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181104120606.4177-1-cus@passwd.hu> References: <20181104120606.4177-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/vf_select: use common scene sad functions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- configure | 2 +- libavfilter/f_select.c | 26 +++++++------------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/configure b/configure index f5bec9fd62..f352ea121c 100755 --- a/configure +++ b/configure @@ -3440,7 +3440,7 @@ sab_filter_deps="gpl swscale" scale2ref_filter_deps="swscale" scale_filter_deps="swscale" scale_qsv_filter_deps="libmfx" -select_filter_select="pixelutils" +select_filter_select="scene_sad" sharpness_vaapi_filter_deps="vaapi" showcqt_filter_deps="avcodec avformat swscale" showcqt_filter_suggest="libfontconfig libfreetype" diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c index b1b2cbc21a..d67849bf26 100644 --- a/libavfilter/f_select.c +++ b/libavfilter/f_select.c @@ -28,12 +28,12 @@ #include "libavutil/fifo.h" #include "libavutil/internal.h" #include "libavutil/opt.h" -#include "libavutil/pixelutils.h" #include "avfilter.h" #include "audio.h" #include "formats.h" #include "internal.h" #include "video.h" +#include "scene_sad.h" static const char *const var_names[] = { "TB", ///< timebase @@ -145,7 +145,7 @@ typedef struct SelectContext { AVExpr *expr; double var_values[VAR_VARS_NB]; int do_scene_detect; ///< 1 if the expression requires scene detection variables, 0 otherwise - av_pixelutils_sad_fn sad; ///< Sum of the absolute difference function (scene detect only) + ff_scene_sad_fn sad; ///< Sum of the absolute difference function (scene detect only) double prev_mafd; ///< previous MAFD (scene detect only) AVFrame *prev_picref; ///< previous frame (scene detect only) double select; @@ -242,7 +242,7 @@ static int config_input(AVFilterLink *inlink) inlink->type == AVMEDIA_TYPE_AUDIO ? inlink->sample_rate : NAN; if (select->do_scene_detect) { - select->sad = av_pixelutils_get_sad_fn(3, 3, 2, select); // 8x8 both sources aligned + select->sad = ff_scene_sad_get_fn(8); if (!select->sad) return AVERROR(EINVAL); } @@ -258,24 +258,12 @@ static double get_scene_score(AVFilterContext *ctx, AVFrame *frame) if (prev_picref && frame->height == prev_picref->height && frame->width == prev_picref->width) { - int x, y, nb_sad = 0; - int64_t sad = 0; + uint64_t sad; double mafd, diff; - uint8_t *p1 = frame->data[0]; - uint8_t *p2 = prev_picref->data[0]; - const int p1_linesize = frame->linesize[0]; - const int p2_linesize = prev_picref->linesize[0]; - - for (y = 0; y < frame->height - 7; y += 8) { - for (x = 0; x < frame->width*3 - 7; x += 8) { - sad += select->sad(p1 + x, p1_linesize, p2 + x, p2_linesize); - nb_sad += 8 * 8; - } - p1 += 8 * p1_linesize; - p2 += 8 * p2_linesize; - } + + select->sad(prev_picref->data[0], prev_picref->linesize[0], frame->data[0], frame->linesize[0], frame->width * 3, frame->height, &sad); emms_c(); - mafd = nb_sad ? (double)sad / nb_sad : 0; + mafd = (double)sad / (frame->width * 3 * frame->height); diff = fabs(mafd - select->prev_mafd); ret = av_clipf(FFMIN(mafd, diff) / 100., 0, 1); select->prev_mafd = mafd;