[FFmpeg-devel,v1,3/6] avfilter/af_silencedetect: use AV_OPT_TYPE_DURATION

Submitted by lance.lmwang@gmail.com on Sept. 30, 2019, 1:36 p.m.

Details

Message ID 20190930133647.6290-3-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Sept. 30, 2019, 1:36 p.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 doc/filters.texi               | 4 +++-
 libavfilter/af_silencedetect.c | 9 +++++----
 tests/fate/filter-video.mak    | 2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

Comments

Moritz Barsnick Sept. 30, 2019, 1:49 p.m.
On Mon, Sep 30, 2019 at 21:36:44 +0800, lance.lmwang@gmail.com wrote:
> -Set silence duration until notification (default is 2 seconds).
> +Set silence duration until notification (default is 2 seconds).See

You missed a space after the period.

Moritz
lance.lmwang@gmail.com Sept. 30, 2019, 1:59 p.m.
On Mon, Sep 30, 2019 at 03:49:44PM +0200, Moritz Barsnick wrote:
> On Mon, Sep 30, 2019 at 21:36:44 +0800, lance.lmwang@gmail.com wrote:
> > -Set silence duration until notification (default is 2 seconds).
> > +Set silence duration until notification (default is 2 seconds).See
> 
> You missed a space after the period.

Thanks, I will update next time.

> 
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Patch hide | download patch | download mbox

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