From patchwork Mon Jul 15 22:53:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13957 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 B797A447349 for ; Tue, 16 Jul 2019 01:54:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7DD1C68ABF8; Tue, 16 Jul 2019 01:54:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA89E68AA1F for ; Tue, 16 Jul 2019 01:54:13 +0300 (EEST) Received: by mail-pg1-f196.google.com with SMTP id o13so8391915pgp.12 for ; Mon, 15 Jul 2019 15:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=NuoexUH7kaNAH1QuvDlRqrlXBKIt3CjJ8Z8OgBlbCpA=; b=Mq726nrShC/RbMGNvPoiXIn851nEVEFSVDq+2GU6ez9r7LlHQ3s2MbUf0n8sNn1Nes lCMSZBB1qgsizjgAwm3Tsz7ahjPPdlXw7YNhC4gI85ko0ESQUvBbWEjUzxqhKTiXG3xN Xc4opQssDH2pSE+G4uufgmnroFfWtKgvR5e+aeQQrONcoV/ydOPE/fNlwUmR4AD9saTK cMPdHg7/NWakHk0hsN94H4FTjN//3G6ZudnitIXtxHts2HdzurYMUe7+cUjYkixHLGo9 jyhW0Adv7asE5nKHG0OQ/D+HTThG6yFjdDARVurp192O6d+VjiGfIddsdaazAk0/ESY0 zyAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NuoexUH7kaNAH1QuvDlRqrlXBKIt3CjJ8Z8OgBlbCpA=; b=ZA96hiorvfEPJoMwvfhoYs9Mgf3tepZC3uB2P5TJ0G+MAgwAzODlwJow+aLOuSqzFW lI5mpnJVxK9C64MgBkH8JmdkHs8vpnHZKl9oRrLzukr9eSsID7Xhd4opVToIbUiEt7YC xkBQ3+MGAZaEOq73XfgGkvls1NSu83bEqjXhYJ2l3DkhtMkMCqrVIGhixhfq4s2qUQfG Dj5ZChkrEKCzr2rXp3wLR5MZNIiM857RuzqzeSnDu8WMjJ3z6jMKhJUBfBMlPYGkD+vl eATliObCaAtiGG8kiukqCZ/1E86W59Z6aG/tVqG7Z3RqqM97/uUNK8TPhq5TL81UbQtB lPPA== X-Gm-Message-State: APjAAAVpfqcUGiSWUdS1Uc9a91IG5kRKG1W76f23rt9i08ZK4BY5SxPL rLQXLT82BF7ExAlaRXGQAgGc/fYB X-Google-Smtp-Source: APXvYqw52/tuGHu1ddWdX0Y9HwxytOrbYRJDkncfUFxirvHdqQU9f6xd/NCFqVB7Ml1j3lEuYKfRlA== X-Received: by 2002:a63:3f48:: with SMTP id m69mr28940448pga.17.1563231251711; Mon, 15 Jul 2019 15:54:11 -0700 (PDT) Received: from izj6c97garwn1o4y2zidq0z.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id d6sm16402909pgf.55.2019.07.15.15.54.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jul 2019 15:54:11 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2019 06:53:56 +0800 Message-Id: <1563231238-20966-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH 1/3] lavf/f_select: support scenecut with more pixel formats 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang This patch haven't make other pixel format usable yet to make sure the test result is same with rgb format. Signed-off-by: Limin Wang --- libavfilter/f_select.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c index 1132375..eed8df3 100644 --- a/libavfilter/f_select.c +++ b/libavfilter/f_select.c @@ -28,6 +28,8 @@ #include "libavutil/fifo.h" #include "libavutil/internal.h" #include "libavutil/opt.h" +#include "libavutil/imgutils.h" +#include "libavutil/pixdesc.h" #include "avfilter.h" #include "audio.h" #include "formats.h" @@ -144,6 +146,10 @@ typedef struct SelectContext { char *expr_str; AVExpr *expr; double var_values[VAR_VARS_NB]; + int bitdepth; + int nb_planes; + ptrdiff_t width[4]; + ptrdiff_t height[4]; int do_scene_detect; ///< 1 if the expression requires scene detection variables, 0 otherwise ff_scene_sad_fn sad; ///< Sum of the absolute difference function (scene detect only) double prev_mafd; ///< previous MAFD (scene detect only) @@ -202,6 +208,17 @@ static av_cold int init(AVFilterContext *ctx) static int config_input(AVFilterLink *inlink) { SelectContext *select = inlink->dst->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); + + select->bitdepth = desc->comp[0].depth; + select->nb_planes = av_pix_fmt_count_planes(inlink->format); + for (int plane = 0; plane < select->nb_planes; plane++) { + ptrdiff_t line_size = av_image_get_linesize(inlink->format, inlink->w, plane); + int vsub = desc->log2_chroma_h; + + select->width[plane] = line_size >> (select->bitdepth > 8); + select->height[plane] = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(inlink->h, vsub) : inlink->h; + } select->var_values[VAR_N] = 0.0; select->var_values[VAR_SELECTED_N] = 0.0; @@ -242,7 +259,7 @@ static int config_input(AVFilterLink *inlink) inlink->type == AVMEDIA_TYPE_AUDIO ? inlink->sample_rate : NAN; if (CONFIG_SELECT_FILTER && select->do_scene_detect) { - select->sad = ff_scene_sad_get_fn(8); + select->sad = ff_scene_sad_get_fn(select->bitdepth == 8 ? 8 : 16); if (!select->sad) return AVERROR(EINVAL); } @@ -258,12 +275,21 @@ static double get_scene_score(AVFilterContext *ctx, AVFrame *frame) if (prev_picref && frame->height == prev_picref->height && frame->width == prev_picref->width) { - uint64_t sad; + uint64_t sad = 0; double mafd, diff; + int count = 0; + + for (int plane = 0; plane < select->nb_planes; plane++) { + uint64_t plane_sad; + select->sad(prev_picref->data[plane], prev_picref->linesize[plane], + frame->data[plane], frame->linesize[plane], + select->width[plane], select->height[plane], &plane_sad); + sad += plane_sad; + count += select->width[plane] * select->height[plane]; + } - 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 = (double)sad / (frame->width * 3 * frame->height); + mafd = (double)sad / count; diff = fabs(mafd - select->prev_mafd); ret = av_clipf(FFMIN(mafd, diff) / 100., 0, 1); select->prev_mafd = mafd;