From patchwork Mon Sep 30 13:36:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15415 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 532C5447DB9 for ; Mon, 30 Sep 2019 16:37:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3E9B16898C0; Mon, 30 Sep 2019 16:37:04 +0300 (EEST) 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 5FAE36881FE for ; Mon, 30 Sep 2019 16:36:58 +0300 (EEST) Received: by mail-pf1-f193.google.com with SMTP id 205so5647726pfw.2 for ; Mon, 30 Sep 2019 06:36:58 -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=cPCpyCitR4N2XVqKK2tK751MG59+9SJANskmv5mHaSg=; b=tbrP7am98VJacXyVl5JbkLlTvnEOMEDCQfb3+V70yMCbXlb9+LpFMf0QPBhn4nKbzG MZPQeM05WrM4jHSibZq7kJtMpMmHIWZZsPZFL+9gJYTTrpZr/kmOdwMavqtt/DCtl7se 7N9ur+lwYbS4aVMzCT/4RR+KZs5CEwNQvtk6N+VqyEDldL+MB9MQJC0cnl7HsQ0535nS vdoeTklAW9XDzJMr2mVd2k8oCbq5PSib94Q4P8SWV3VYBP5Tg/9bDwAa/CwktDPBhH5z 0rca+Puw8IbftAZc5YoDvAWy423cOT5v9hslKQY2eVRI8rHnGcOd5rHWUFTaS1RpikA9 JDXA== 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=cPCpyCitR4N2XVqKK2tK751MG59+9SJANskmv5mHaSg=; b=NopsyBofVmXuqOcZf0J0RtkhShXpdz21pdDrXcgYh7cfoDPOo/TAr8i2z3enuRCfcK JucM6FMUonMjuJBu1JTMp5ZMMfFzYvQ+cNuOMl4hPe3qFg7XW+R6lvXIGMwF56vCqJbk W8+8oKgFw4BOcgt+l6d5S2yuWeHVI/7JdQWrDjEkXfwJhyXXA3Oiw8SA4tw2sm7lbY5W Vc1rNQn1Yiki5EdiPjbUY5V0YjzvIda+urSxz8u7JGd0lgsrJQndaDjQMttZMGRORrhI iH2bueItdWusANnCDEDZ9o5QIFvAg/1BiapU7bFpQObtgJ7ZldqugJluP5Mnm6v+SaNv qt2g== X-Gm-Message-State: APjAAAXGS/yapnUlHCiXuCSIAgXGPTE1qoneS0zfHfOqvTc2pUG+e45i tCps5Dpr/voeOIUBhRB2SKfYdTca X-Google-Smtp-Source: APXvYqxy/NPSjBoITtpTKjkxYyDabOG0j2F4ZVjc971MFLtIXAFO4VNQM4N3Xro6Zyhn8QpTQIzMrg== X-Received: by 2002:a62:d101:: with SMTP id z1mr22240678pfg.151.1569850616705; Mon, 30 Sep 2019 06:36:56 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id x6sm20188809pfd.53.2019.09.30.06.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Sep 2019 06:36:56 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Sep 2019 21:36:44 +0800 Message-Id: <20190930133647.6290-3-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20190930133647.6290-1-lance.lmwang@gmail.com> References: <20190930133647.6290-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v1 3/6] 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 | 9 +++++---- tests/fate/filter-video.mak | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 697ec21..cc6225c 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..0fce244 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) @@ -55,8 +55,8 @@ typedef struct SilenceDetectContext { 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, INT64_MAX,FLAGS }, + { "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, INT64_MAX,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 +143,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 +175,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