summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2015-12-28 12:02:14 +0100
committerPaul B Mahol <onemda@gmail.com>2015-12-28 12:23:59 +0100
commit47aaebd63e408bc59dc9e35dd372c1f603be2d3a (patch)
treec8200e4483fcbc6283bf4bb4de7d2d0637716ebb
parentb841fe002a2bf67ca4381fd4dd522c2cfee22be8 (diff)
avfilter/af_silenceremove: make size of window user configurable
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--doc/filters.texi4
-rw-r--r--libavfilter/af_silenceremove.c4
2 files changed, 7 insertions, 1 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index abec3c3a84..2b1fabe20e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2973,6 +2973,10 @@ to remove the pauses completely. Default value is @code{0}.
Set how is silence detected. Can be @code{rms} or @code{peak}. Second is faster
and works better with digital silence which is exactly 0.
Default value is @code{rms}.
+
+@item window
+Set ratio used to calculate size of window for detecting silence.
+Default value is @code{0.02}. Allowed range is from @code{0} to @code{10}.
@end table
@subsection Examples
diff --git a/libavfilter/af_silenceremove.c b/libavfilter/af_silenceremove.c
index dc3f4ff91d..f156d1883d 100644
--- a/libavfilter/af_silenceremove.c
+++ b/libavfilter/af_silenceremove.c
@@ -61,6 +61,7 @@ typedef struct SilenceRemoveContext {
size_t stop_holdoff_end;
int stop_found_periods;
+ double window_ratio;
double *window;
double *window_current;
double *window_end;
@@ -89,6 +90,7 @@ static const AVOption silenceremove_options[] = {
{ "detection", NULL, OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "detection" },
{ "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "detection" },
{ "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "detection" },
+ { "window", NULL, OFFSET(window_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=0.02}, 0, 10, FLAGS },
{ NULL }
};
@@ -175,7 +177,7 @@ static int config_input(AVFilterLink *inlink)
AVFilterContext *ctx = inlink->dst;
SilenceRemoveContext *s = ctx->priv;
- s->window_size = (inlink->sample_rate / 50) * inlink->channels;
+ s->window_size = FFMAX((inlink->sample_rate * s->window_ratio), 1) * inlink->channels;
s->window = av_malloc_array(s->window_size, sizeof(*s->window));
if (!s->window)
return AVERROR(ENOMEM);