From patchwork Sun Nov 3 10:50:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leozhang X-Patchwork-Id: 16088 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 38382448873 for ; Sun, 3 Nov 2019 12:50:22 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 13FC468AF61; Sun, 3 Nov 2019 12:50:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smg-bj-02.qiyi.com (mx1.qiyi.com [202.108.14.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6290568A0A1 for ; Sun, 3 Nov 2019 12:50:14 +0200 (EET) X-AuditID: ca6c0e64-ac1ff70000007f7f-b4-5dbeb0e3aab5 Received: from mail.iqiyi.com (Unknown_Domain [10.11.69.96]) by smg-bj-02.qiyi.com (Qiyi mail Gateway) with SMTP id B0.6C.32639.3E0BEBD5; Sun, 3 Nov 2019 18:50:12 +0800 (HKT) From: leozhang To: Date: Sun, 3 Nov 2019 18:50:04 +0800 Message-ID: <1572778204-165552-1-git-send-email-leozhang@qiyi.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571834065-74094-1-git-send-email-leozhang@qiyi.com> References: <1571834065-74094-1-git-send-email-leozhang@qiyi.com> MIME-Version: 1.0 X-Originating-IP: [10.13.40.213] X-ClientProxiedBy: BJ-CAS24.iqiyi.pps (10.15.221.33) To EXCH20.iqiyi.pps (10.16.148.50) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsXCxe2aoPtkw75Yg+cZFt8+nWF2YPT4s2gz SwBjFLdNUmJJWXBmep6+XQJ3RufVBewFvyUqnj9dzNbA+Ey4i5GTQ0LAROLfqvusXYxcHEIC GxklLm6exwaSYBNQkli/YioriC0iICux+t8UsLiwQJTEhllb2EFsFgEViUuT5oPV8Ao4SXzf 8pUZYqiCxJSH78FsTpB41xqwGiEBR4kJuy4zQtQLSpyc+YQFxGYWkJA4+OIFM0SNnMTTX79Y YOY8nDqJHcKOlLiy8gH7BEb+WUjaZyFpX8DItIpRqDg3XTcpS9fASK8wszJTLzk/dxMjMJhO 5fCl7GA8ON/5EKMAB6MSD6/D1L2xQqyJZcWVuYcYJTiYlUR4L84ACvGmJFZWpRblxxeV5qQW H2KU5mBREuflZt0TKySQnliSmp2aWpBaBJNl4uAE6eaSEilOzUtJLUosLcmIB4V6fDEw2KUa GLOPxxY6BTo+UBHt8YjaVfI85tBLhY2nfcsNfi1g+L1l14YJ++RPC/J6iJ58GtXxS/CE6epS WeW6rStFXric/P5d+6nWuimZBQ8lHnacvKm4c9G0MuNmvmieeWt9j6ocn2zKwNv/V2XiVl+O 6TVc6m812AzFr5Vqn57M1tH0dPnGb7zvV/6fFK/EUpyRaKjFXFScCACZ3mORPQIAAA== Subject: [FFmpeg-devel] [PATCH V4] avfilter/vf_bilateral: process command to set the parameter at runtime 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Reviewed-by: Paul B Mahol Reviewed-by: Jun Zhao Signed-off-by: leozhang --- libavfilter/vf_bilateral.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_bilateral.c b/libavfilter/vf_bilateral.c index 3c9d800..ba3631c 100644 --- a/libavfilter/vf_bilateral.c +++ b/libavfilter/vf_bilateral.c @@ -29,6 +29,8 @@ #include "internal.h" #include "video.h" +#include + typedef struct BilateralContext { const AVClass *class; @@ -54,7 +56,7 @@ typedef struct BilateralContext { } BilateralContext; #define OFFSET(x) offsetof(BilateralContext, x) -#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption bilateral_options[] = { { "sigmaS", "set spatial sigma", OFFSET(sigmaS), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 10, FLAGS }, @@ -91,19 +93,27 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); } -static int config_input(AVFilterLink *inlink) +static int init_lut(BilateralContext *s) { - BilateralContext *s = inlink->dst->priv; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); float inv_sigma_range; - s->depth = desc->comp[0].depth; inv_sigma_range = 1.0f / (s->sigmaR * ((1 << s->depth) - 1)); //compute a lookup table for (int i = 0; i < (1 << s->depth); i++) s->range_table[i] = expf(-i * inv_sigma_range); + return 0; +} + +static int config_input(AVFilterLink *inlink) +{ + BilateralContext *s = inlink->dst->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); + + s->depth = desc->comp[0].depth; + init_lut(s); + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); s->planewidth[0] = s->planewidth[3] = inlink->w; s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); @@ -325,6 +335,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(outlink, out); } +static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + BilateralContext *s = ctx->priv; + int ret; + float old_sigmaR = s->sigmaR; + + if ((ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags)) < 0) { + return ret; + } + + if (fabs(old_sigmaR - s->sigmaR) > FLT_EPSILON && (ret = init_lut(s)) < 0) { + s->sigmaR = old_sigmaR; + } + + return ret; +} + static av_cold void uninit(AVFilterContext *ctx) { BilateralContext *s = ctx->priv; @@ -367,4 +395,5 @@ AVFilter ff_vf_bilateral = { .inputs = bilateral_inputs, .outputs = bilateral_outputs, .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, + .process_command = process_command, };