[FFmpeg-cvslog] avfilter/af_silenceremove: add standard deviation detector
Paul B Mahol
git at videolan.org
Mon May 29 12:41:52 EEST 2023
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun May 28 17:37:55 2023 +0200| [f02964aee1ed06ac4a67103904d5fae2862fa45e] | committer: Paul B Mahol
avfilter/af_silenceremove: add standard deviation detector
Useful in cases audio samples DC offset is not ~0.0, where
other detectors will fail to detect silence.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f02964aee1ed06ac4a67103904d5fae2862fa45e
---
doc/filters.texi | 2 ++
libavfilter/af_silenceremove.c | 9 +++++++++
libavfilter/silenceremove_template.c | 17 +++++++++++++++++
3 files changed, 28 insertions(+)
diff --git a/doc/filters.texi b/doc/filters.texi
index 2333cfaf7a..c47e88e5d4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6474,6 +6474,8 @@ Maximum of absolute values of samples in moving window.
Median of absolute values of samples in moving window.
@item ptp
Absolute of max peak to min peak difference of samples in moving window.
+ at item dev
+Standard deviation of values of samples in moving window.
@end table
Default value is @code{rms}.
diff --git a/libavfilter/af_silenceremove.c b/libavfilter/af_silenceremove.c
index c7975a9365..4cb662080b 100644
--- a/libavfilter/af_silenceremove.c
+++ b/libavfilter/af_silenceremove.c
@@ -38,6 +38,7 @@ enum SilenceDetect {
D_PEAK,
D_MEDIAN,
D_PTP,
+ D_DEV,
D_NB
};
@@ -146,6 +147,7 @@ static const AVOption silenceremove_options[] = {
{ "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" },
{ "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" },
{ "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" },
+ { "dev", "use standard deviation from values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_DEV}, 0, 0, AF, "detection" },
{ "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
{ "timestamp", "set how every output frame timestamp is processed", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, {.i64=TS_WRITE}, 0, TS_NB-1, AF, "timestamp" },
{ "write", "full timestamps rewrite, keep only the start time", 0, AV_OPT_TYPE_CONST, {.i64=TS_WRITE}, 0, 0, AF, "timestamp" },
@@ -230,6 +232,9 @@ static int config_output(AVFilterLink *outlink)
case D_RMS:
s->cache_size = 1;
break;
+ case D_DEV:
+ s->cache_size = 2;
+ break;
case D_MEDIAN:
case D_PEAK:
case D_PTP:
@@ -263,6 +268,10 @@ static int config_output(AVFilterLink *outlink)
s->compute_flt = compute_avg_flt;
s->compute_dbl = compute_avg_dbl;
break;
+ case D_DEV:
+ s->compute_flt = compute_dev_flt;
+ s->compute_dbl = compute_dev_dbl;
+ break;
case D_PTP:
s->compute_flt = compute_ptp_flt;
s->compute_dbl = compute_ptp_dbl;
diff --git a/libavfilter/silenceremove_template.c b/libavfilter/silenceremove_template.c
index 8536d5e723..009ed52f89 100644
--- a/libavfilter/silenceremove_template.c
+++ b/libavfilter/silenceremove_template.c
@@ -307,6 +307,23 @@ static ftype fn(compute_rms)(ftype *cache, ftype sample, ftype wsample,
return SQRT(r / window_size);
}
+static ftype fn(compute_dev)(ftype *ss, ftype x, ftype px,
+ int n, int *unused, int *unused2)
+{
+ ftype r;
+
+ ss[0] += x;
+ ss[0] -= px;
+
+ ss[1] += x * x;
+ ss[1] -= px * px;
+ ss[1] = FMAX(ss[1], ZERO);
+
+ r = FMAX(ss[1] - ss[0] * ss[0] / n, ZERO) / n;
+
+ return SQRT(r);
+}
+
static void fn(filter_start)(AVFilterContext *ctx,
const ftype *src, ftype *dst,
int *nb_out_samples,
More information about the ffmpeg-cvslog
mailing list