From patchwork Mon Sep 30 15:20:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15421 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 7705E44A38F for ; Mon, 30 Sep 2019 18:20:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 63E3C6898C0; Mon, 30 Sep 2019 18:20:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 845086881D7 for ; Mon, 30 Sep 2019 18:20:22 +0300 (EEST) Received: by mail-pf1-f178.google.com with SMTP id q10so5819417pfl.0 for ; Mon, 30 Sep 2019 08:20:22 -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=HYy5ik7lX7NpEMoWjtQxE1YTNwlsiW7IVXD4Lu1yH90=; b=jybQLrMXCQD+SnRLWY394RrpTNLm096KBo3Yxn+DZdO2a+DF7X/WdwSalvhCFXP06C YkgDixoF9cMGTu39xzsv+OGY4Tr7JhjYMbrWPMo0Z8l3173B7smdAZ0OVpSAM+qPWK6b bCE5VY9kBo3jXDwxGCczBrrMrejM2TVtMQApMU4uVNxpkSgqUHjqqYWHyeRS3GFb1FaT qDkYHAXOf7Epff/82vSe9SXu3MHra3vTc5MHpSFO78dBm29LVCLxyn8CapkVA1kEGwM1 4fmjuZ4s3orJRA+cNOKXiehY+LJNfDqWUqgH/MQmah6tKI5YfK2BQfHiImYlxmRhDRSA 8+BQ== 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=HYy5ik7lX7NpEMoWjtQxE1YTNwlsiW7IVXD4Lu1yH90=; b=t5xp6jSq/rO5E+mmVcokXmkeXdKsISLYQ0+cMgJr8BidSLuSa1k5UfcW0GvOINJuSm u+0YMFrCZzewHrJDgkMfgSNBWIUA0uh3hilZvODs5Ob8zZWFVGuKZmvtIDnFWQVFJSMx GQc+UIQRbqOlmrj7KeSL8IYONe3KGDbL68MYDYsCrV7BfBZE/Quq0jniXEpyRGsOyBkM hLudd3pk9WEqO2Xf+9PgLttqqG2pjOLmEZ6lPuVueoJUWx9Jmkgc3uT1lYNdRQGtY9Dg SvsUBRyWxjugjSGgpWH+y1ZhXZJohOAXugxjjhvSV/8Av1NaMQpP7fxeRXz2ku4LKVF0 PCOg== X-Gm-Message-State: APjAAAX6ZDRWs1YNLUSE+FTb+JH3Ud9xDQnqy6zaP5Kl3ul1Q+BvC4yl D8mUqFVlV8Z7kscQXlgCkTfn5mAw X-Google-Smtp-Source: APXvYqyH4avptQNO7eoLD+7WKZD6sa++rI6QqXAqLLimSYMB5PsB65gf7feh16l7a9acpq6bTSqMzg== X-Received: by 2002:a17:90a:a403:: with SMTP id y3mr26689966pjp.69.1569856820664; Mon, 30 Sep 2019 08:20:20 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id o60sm14818344pje.21.2019.09.30.08.20.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Sep 2019 08:20:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Sep 2019 23:20:08 +0800 Message-Id: <20190930152009.6804-3-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20190930152009.6804-1-lance.lmwang@gmail.com> References: <20190930133647.6290-1-lance.lmwang@gmail.com> <20190930152009.6804-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 3/4] avfilter/af_silencedetect: use AV_OPT_TYPE_DURATION 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 Signed-off-by: Limin Wang --- doc/filters.texi | 4 +++- libavfilter/af_silencedetect.c | 10 ++++++---- tests/fate/filter-video.mak | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 697ec21..b892103 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -4581,7 +4581,9 @@ Set noise tolerance. Can be specified in dB (in case "dB" is appended to the specified value) or amplitude ratio. Default is -60dB, or 0.001. @item duration, d -Set silence duration until notification (default is 2 seconds). +Set silence duration until notification (default is 2 seconds). See +@ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils} +for the accepted syntax. @item mono, m Process each channel separately, instead of combined. By default is disabled. diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c index 193d0fe..f2c5dac 100644 --- a/libavfilter/af_silencedetect.c +++ b/libavfilter/af_silencedetect.c @@ -35,7 +35,7 @@ typedef struct SilenceDetectContext { const AVClass *class; double noise; ///< noise amplitude ratio - double duration; ///< minimum duration of silence until notification + int64_t duration; ///< minimum duration of silence until notification int mono; ///< mono mode : check each channel separately (default = check when ALL channels are silent) int channels; ///< number of channels int independent_channels; ///< number of entries in following arrays (always 1 in mono mode) @@ -50,13 +50,14 @@ typedef struct SilenceDetectContext { AVRational time_base); } SilenceDetectContext; +#define MAX_DURATION (24*3600*1000000) #define OFFSET(x) offsetof(SilenceDetectContext, x) #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM static const AVOption silencedetect_options[] = { { "n", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS }, { "noise", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS }, - { "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DOUBLE, {.dbl=2.}, 0, 24*60*60, FLAGS }, - { "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DOUBLE, {.dbl=2.}, 0, 24*60*60, FLAGS }, + { "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, MAX_DURATION,FLAGS }, + { "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, MAX_DURATION,FLAGS }, { "mono", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0.}, 0, 1, FLAGS }, { "m", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0.}, 0, 1, FLAGS }, { NULL } @@ -143,6 +144,7 @@ static int config_input(AVFilterLink *inlink) s->channels = inlink->channels; s->independent_channels = s->mono ? s->channels : 1; + s->duration = av_rescale(s->duration, inlink->sample_rate, AV_TIME_BASE); s->nb_null_samples = av_mallocz_array(s->independent_channels, sizeof(*s->nb_null_samples)); if (!s->nb_null_samples) return AVERROR(ENOMEM); @@ -174,7 +176,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) const int nb_channels = inlink->channels; const int srate = inlink->sample_rate; const int nb_samples = insamples->nb_samples * nb_channels; - const int64_t nb_samples_notify = srate * s->duration * (s->mono ? 1 : nb_channels); + const int64_t nb_samples_notify = s->duration * (s->mono ? 1 : nb_channels); int c; // scale number of null samples to the new sample rate diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 0c6ee72..dd57a40 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -747,7 +747,7 @@ fate-filter-metadata-cropdetect: CMD = run $(FILTER_METADATA_COMMAND) "sws_flags SILENCEDETECT_DEPS = FFPROBE AVDEVICE LAVFI_INDEV AMOVIE_FILTER TTA_DEMUXER TTA_DECODER SILENCEDETECT_FILTER FATE_METADATA_FILTER-$(call ALLYES, $(SILENCEDETECT_DEPS)) += fate-filter-metadata-silencedetect fate-filter-metadata-silencedetect: SRC = $(TARGET_SAMPLES)/lossless-audio/inside.tta -fate-filter-metadata-silencedetect: CMD = run $(FILTER_METADATA_COMMAND) "amovie='$(SRC)',silencedetect=n=-33.5dB:d=.2" +fate-filter-metadata-silencedetect: CMD = run $(FILTER_METADATA_COMMAND) "amovie='$(SRC)',silencedetect=n=-33.5dB:d=0.2" EBUR128_METADATA_DEPS = FFPROBE AVDEVICE LAVFI_INDEV AMOVIE_FILTER FLAC_DEMUXER FLAC_DECODER EBUR128_FILTER FATE_METADATA_FILTER-$(call ALLYES, $(EBUR128_METADATA_DEPS)) += fate-filter-metadata-ebur128