From patchwork Fri Jul 19 11:18:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13989 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 5683B446FCF for ; Fri, 19 Jul 2019 14:19:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3766068AC95; Fri, 19 Jul 2019 14:19:08 +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 1D06268AC7E for ; Fri, 19 Jul 2019 14:19:01 +0300 (EEST) Received: by mail-pf1-f196.google.com with SMTP id r1so14038448pfq.12 for ; Fri, 19 Jul 2019 04:19:01 -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=+LT13bEBdQini64461Qk2gIP9nXHmWW1TTJYsuM0lIs=; b=j+Gvnr529RNYmxemPriT3bGmCMVYnwfs9I7k4EedMOKaT6ZC+8rokZftcPmfP9Zi3u apNQUo6YEbwufGrya0zN35c1CkDTDW3ovMrqovqdPRPvcTdm1P5p3O7dQWGUFWyuSCAi YlQjv27kmLAAAVvE4vGyzmWblGptJKqxAlEfZT83jdkdCLQ5CT3xP0riJWqG0S48HFS/ knbiPJfVeABWv9hx8wVZmEI3sd8L7hVr8njbxezbe/w7y8opOfcjt/qn38qy8mnfUfNY +hbhY8SlaSeiNRWx5tR0p6SW5Gh41MmzyLn8eO+2tHCAEsXCTutVa/6pBk6pV7U3GslK v8fQ== 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=+LT13bEBdQini64461Qk2gIP9nXHmWW1TTJYsuM0lIs=; b=Yhh6Qz4ByZJZ/rY/DZrOV9XUuiTuRVyKyCQoEoMMT/wPVu9ZUKj/rIws3VeJS+qJyb uGAzlUi50BT7b4kiWuqLLBmnyCcTUUEGRtmWBui68vz7KdVP4xBGSmz3E5CIbQi9QXeF Z4+S8oIi3jPmaLLpms6GMD4SOPTX8yOzRJOZDKtJp85E7ENF1+XiNCO9igVa25lWu+Vu /uOewiuJaNjL4od5mV+wo/tUqxJn1YTjky1WPhQczlj2D9XxsoVpDAzQQMeIF0itb27D yAdEgtW0LKwscr5r9o5H5qUokl/totTNKfzxRZDil+VNtOK9BBhni4ZI7yNY2FR0XR1K aFMw== X-Gm-Message-State: APjAAAUCeucV3MuFyRX6tN7sQaLPI/jhP3Z9bY9V2sHPux/nsPWQ8eXm xZEy1fLLBFwNCZEo+1wT+IU+SOVB X-Google-Smtp-Source: APXvYqyIYLl2qwh60KDq/JuOusmISEwLdVBmsC0Oygn5nzx5VZSoBdgmVJdZsspoWkra1026csmSuw== X-Received: by 2002:a17:90a:24ac:: with SMTP id i41mr56602116pje.124.1563535138793; Fri, 19 Jul 2019 04:18:58 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id m4sm58989760pff.108.2019.07.19.04.18.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jul 2019 04:18:57 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Jul 2019 19:18:46 +0800 Message-Id: <20190719111848.9009-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 v2 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. 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 1132375758..eed8df34cb 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;