From patchwork Wed Jan 30 10:56:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 11911 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 4290A44E33A for ; Wed, 30 Jan 2019 13:27:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5592368ADDD; Wed, 30 Jan 2019 13:26:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E86268AD87 for ; Wed, 30 Jan 2019 13:26:44 +0200 (EET) Received: by mail-pf1-f193.google.com with SMTP id b85so11288969pfc.3 for ; Wed, 30 Jan 2019 03:27:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wknMyoSkvJAhINp9vIxT17y6XyjUc7CGM51hPt7LQ9Q=; b=C5fJn3aP8g8cxmuxLieHSTx4sIU21/pX5N6l6Fw6fv2MIgkrVLhVvsHj8LUo+ZpjHL SNocjcOymnY2o8s5mWFayZoe1xsuD2kSbi1Uhs2QswYog9Y14M4qMhRG7YHAFeMT9YIn NvYjQsh1zyGj8YETewSqyKMt5MMgWC03LaWngvhXrvmRa+gnYoBsuMJoLq99S0cvjkxM 5gxVwTZ4nc+wMxCu19jobF/5kP5jpYAMO7tNcpFjoO+VaGwBxgOvyN5Ty+BWceU+Wr3D eCUsfJmApr/VtNfXbk+au/Ah5cNtWlEtSb5FY5+N10reEXT00McbLjq6qulIAjjpdsYy U6Jg== 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=wknMyoSkvJAhINp9vIxT17y6XyjUc7CGM51hPt7LQ9Q=; b=IlKC5YjvYMVBRLHgQJ7ZgW6d9ZcEVFC/cXg82+37OMW5/rrNCExFbQSPpHOPQ67bPx 0P4ofaWBjq6ARDgF+IAEEjPWVq9db0LZZChj7KcIgGRYDneiPrQkacHsTPtElGT9q0gw 43WV2f85WG13YNQQ0QF0b8iWL3AOSSU3fEKJLI1OUhx/X/SRCyRw2BKCZ1WS2yX+cxAs sB0SZ0MifXeyTBIak3ioHmPrVqIb1ctZ4fEOkSe8xkikWDeRYHvOpjD0dpjFqrZja2aB BJG+GqhCYVoCdPNv6AwBLnx7jzFleAdc8X5D1Xk+00SgF/LALupv1znRhRSTwfLyo4qD ap0A== X-Gm-Message-State: AJcUukfqzal1gl3AM9Ty7MuBZhREjESdiIORk39IyThzzEvp72iMh4pt 7k0yRSAyV7H4nAECA48QGHAkecDU X-Google-Smtp-Source: ALg8bN6sLky/lsW11h+OnXtLoJosc4FI64/kWJkAOhkigTzV9VQpGRbuAT1hR9jVNqhLVcix3H79kQ== X-Received: by 2002:a63:c00b:: with SMTP id h11mr27647063pgg.429.1548845770519; Wed, 30 Jan 2019 02:56:10 -0800 (PST) Received: from localhost.localdomain ([47.90.47.25]) by smtp.gmail.com with ESMTPSA id 184sm1967498pfe.106.2019.01.30.02.56.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 02:56:09 -0800 (PST) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Jan 2019 18:56:04 +0800 Message-Id: <1548845764-32527-1-git-send-email-mypopydev@gmail.com> X-Mailer: git-send-email 1.7.1 Subject: [FFmpeg-devel] [PATCH] lavfi/vf_nlmeans: Remove the pdiff_lut_scale to improve the performance 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: Jun Zhao MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Remove the pdiff_lut_scale in nlmeans, and this change will avoid using pdiff_lut_scale in the exp table search in nlmean_slice, it's will improve the performance about 12%. Use the profiling cmd like: perf stat -a -d -r 5 ./ffmpeg -i input -an -vf nlmeans=s=30 -vframes 10 \ -f null /dev/null without this change: when s=1.0(default value) 63s s=30.0 72s after this change: s=1.0(default value) 56s s=30.0 63s Signed-off-by: Jun Zhao --- libavfilter/vf_nlmeans.c | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-) diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c index 82e779c..72eb819 100644 --- a/libavfilter/vf_nlmeans.c +++ b/libavfilter/vf_nlmeans.c @@ -43,8 +43,7 @@ struct weighted_avg { float sum; }; -#define WEIGHT_LUT_NBITS 9 -#define WEIGHT_LUT_SIZE (1< 300 * 300 * log(255) typedef struct NLMeansContext { const AVClass *class; @@ -63,7 +62,6 @@ typedef struct NLMeansContext { struct weighted_avg *wa; // weighted average of every pixel ptrdiff_t wa_linesize; // linesize for wa in struct size unit float weight_lut[WEIGHT_LUT_SIZE]; // lookup table mapping (scaled) patch differences to their associated weights - float pdiff_lut_scale; // scale factor for patch differences before looking into the LUT uint32_t max_meaningful_diff; // maximum difference considered (if the patch difference is too high we ignore the pixel) NLMeansDSPContext dsp; } NLMeansContext; @@ -401,8 +399,7 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs const uint32_t patch_diff_sq = e - d - b + a; if (patch_diff_sq < s->max_meaningful_diff) { - const unsigned weight_lut_idx = patch_diff_sq * s->pdiff_lut_scale; - const float weight = s->weight_lut[weight_lut_idx]; // exp(-patch_diff_sq * s->pdiff_scale) + const float weight = s->weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale) wa[x].total_weight += weight; wa[x].sum += weight * src[x]; } @@ -527,10 +524,9 @@ static av_cold int init(AVFilterContext *ctx) s->pdiff_scale = 1. / (h * h); s->max_meaningful_diff = -log(1/255.) / s->pdiff_scale; - s->pdiff_lut_scale = 1./s->max_meaningful_diff * WEIGHT_LUT_SIZE; - av_assert0((s->max_meaningful_diff - 1) * s->pdiff_lut_scale < FF_ARRAY_ELEMS(s->weight_lut)); + av_assert0((s->max_meaningful_diff - 1) < FF_ARRAY_ELEMS(s->weight_lut)); for (i = 0; i < WEIGHT_LUT_SIZE; i++) - s->weight_lut[i] = exp(-i / s->pdiff_lut_scale * s->pdiff_scale); + s->weight_lut[i] = exp(-i * s->pdiff_scale); CHECK_ODD_FIELD(research_size, "Luma research window"); CHECK_ODD_FIELD(patch_size, "Luma patch");