From patchwork Sat Jul 20 23:24:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 14011 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 314994476E2 for ; Sun, 21 Jul 2019 02:25:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 08C7F68AAE4; Sun, 21 Jul 2019 02:25:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3658968A92E for ; Sun, 21 Jul 2019 02:25:26 +0300 (EEST) Received: by mail-pf1-f196.google.com with SMTP id y15so15688831pfn.5 for ; Sat, 20 Jul 2019 16:25:26 -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:in-reply-to:references; bh=Q/dKkLfReA9Sl4mUQ49J6NRlpXzTI2zxoTgiYgQQk50=; b=eWt0AxzCe5gMwPwzyWtfaVcQpsFTsSLt5VzpBPir8SsZZO2H/BZQi4HHQY6ZI7dGPd 4T1tsjAfnLR5WZAvaS7rQqyKFiHm7tsliRbQXwfxM1cInFORlOL5nsIcdd+5hvgJB4YO wjPjU09VG0OIp9aNVvm/u7P8D6njxt8VXs/Pz4d3ijKzQW4B2VUrwgBItzjTiqDu6Lik TM8Mvvm9fLmQu14uO6Ww97PLN2ZIgTC7nlugjoo13svXLYhz0IE8UPTB2qIpW8i2AAG2 TnYow+MKsKdYuiWoabGe/IxdJ/CP4JqwlVweaigmzQ4kaltNWxOaIs/8mbQwvgcFFkdQ ntrA== 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:in-reply-to :references; bh=Q/dKkLfReA9Sl4mUQ49J6NRlpXzTI2zxoTgiYgQQk50=; b=ZvJn8U0aotlmQS1gdlEdvDL8mzsYZrmAO90B8zdg/17i4JbIM+jsOowtNsbWZWXO9s NXLPmWLaooYnGEgrAKODKsQW5pUXGIZx7NQi4WCSrskaKoP2StvtqItRx7ODVV6vtCwl YZFTYbHKdbPjQhbUCo792XlMy7UOABp6Nl7PM7j0np08Bz6C4yufbiWe8qW3arqL+UTY yMSyU8ylVh4TTh/f6iRBWsem3mytbVYnvE+L9UpR6qPTkc40s8/XG+ThIPXxRC8dQngg gKFPtDNqXyTCX+SJgm2n6PPqc984tH02SsfIGuDGoMDEsMNg34DLDkl7HgMAZIrKkzpX nWmw== X-Gm-Message-State: APjAAAWivuzR/ncftZZQ5AAxOiarxIu5T4d9LUnNOsofNNMyRfmwU5ly ReYNjNNbxCgmj0XKfRhyTpaZ79Sl X-Google-Smtp-Source: APXvYqwiX0UkUHS1P61YySJVImUV/InUmFwQ/8iZvdSFGoOmUjO7nmZTrb6vvOqF34vGoBBO39mkgA== X-Received: by 2002:a63:4404:: with SMTP id r4mr61764958pga.245.1563665123803; Sat, 20 Jul 2019 16:25:23 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id b3sm48839339pfp.65.2019.07.20.16.25.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jul 2019 16:25:23 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Jul 2019 07:24:18 +0800 Message-Id: <20190720232420.11994-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <1563231238-20966-1-git-send-email-lance.lmwang@gmail.com> References: <1563231238-20966-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v3 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 rgb32 format. Reviewed-by: Marton Balint 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..b872cee 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 / (1ULL << (select->bitdepth - 8)); diff = fabs(mafd - select->prev_mafd); ret = av_clipf(FFMIN(mafd, diff) / 100., 0, 1); select->prev_mafd = mafd;