Useful in cases audio samples DC offset is not ~0.0, where other detectors will fail to detect silence.
Showing the changes to libavfilter (2 of 3 files). Show all
Unified · Split
| @@ -38,6 +38,7 @@ enum SilenceDetect { · 37 unmodified lines | |||
| 38 | D_PEAK, | 38 | D_PEAK, |
| 39 | D_MEDIAN, | 39 | D_MEDIAN, |
| 40 | D_PTP, | 40 | D_PTP, |
| 41 | D_DEV, | ||
| 41 | D_NB | 42 | D_NB |
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| @@ -146,6 +147,7 @@ static const AVOption silenceremove_options[] = { · 102 unmodified lines | |||
| 146 | { "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" }, | 147 | { "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" }, |
| 147 | { "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" }, | 148 | { "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" }, |
| 148 | { "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" }, | 149 | { "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" }, |
| 150 | { "dev", "use standard deviation from values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_DEV}, 0, 0, AF, "detection" }, | ||
| 149 | { "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF }, | 151 | { "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF }, |
| 150 | { "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" }, | 152 | { "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" }, |
| 151 | { "write", "full timestamps rewrite, keep only the start time", 0, AV_OPT_TYPE_CONST, {.i64=TS_WRITE}, 0, 0, AF, "timestamp" }, | 153 | { "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) · 78 unmodified lines | |||
| 230 | case D_RMS: | 232 | case D_RMS: |
| 231 | s->cache_size = 1; | 233 | s->cache_size = 1; |
| 232 | break; | 234 | break; |
| 235 | case D_DEV: | ||
| 236 | s->cache_size = 2; | ||
| 237 | break; | ||
| 233 | case D_MEDIAN: | 238 | case D_MEDIAN: |
| 234 | case D_PEAK: | 239 | case D_PEAK: |
| 235 | case D_PTP: | 240 | case D_PTP: |
| @@ -263,6 +268,10 @@ static int config_output(AVFilterLink *outlink) · 27 unmodified lines | |||
| 263 | s->compute_flt = compute_avg_flt; | 268 | s->compute_flt = compute_avg_flt; |
| 264 | s->compute_dbl = compute_avg_dbl; | 269 | s->compute_dbl = compute_avg_dbl; |
| 265 | break; | 270 | break; |
| 271 | case D_DEV: | ||
| 272 | s->compute_flt = compute_dev_flt; | ||
| 273 | s->compute_dbl = compute_dev_dbl; | ||
| 274 | break; | ||
| 266 | case D_PTP: | 275 | case D_PTP: |
| 267 | s->compute_flt = compute_ptp_flt; | 276 | s->compute_flt = compute_ptp_flt; |
| 268 | s->compute_dbl = compute_ptp_dbl; | 277 | s->compute_dbl = compute_ptp_dbl; |
| @@ -307,6 +307,23 @@ static ftype fn(compute_rms)(ftype *cache, ftype sample, ftype wsample, · 306 unmodified lines | |||
| 307 | return SQRT(r / window_size); | 307 | return SQRT(r / window_size); |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | static ftype fn(compute_dev)(ftype *ss, ftype x, ftype px, | ||
| 311 | int n, int *unused, int *unused2) | ||
| 312 | { | ||
| 313 | ftype r; | ||
| 314 | |||
| 315 | ss[0] += x; | ||
| 316 | ss[0] -= px; | ||
| 317 | |||
| 318 | ss[1] += x * x; | ||
| 319 | ss[1] -= px * px; | ||
| 320 | ss[1] = FMAX(ss[1], ZERO); | ||
| 321 | |||
| 322 | r = FMAX(ss[1] - ss[0] * ss[0] / n, ZERO) / n; | ||
| 323 | |||
| 324 | return SQRT(r); | ||
| 325 | } | ||
| 326 | |||
| 310 | static void fn(filter_start)(AVFilterContext *ctx, | 327 | static void fn(filter_start)(AVFilterContext *ctx, |
| 311 | const ftype *src, ftype *dst, | 328 | const ftype *src, ftype *dst, |
| 312 | int *nb_out_samples, | 329 | int *nb_out_samples, |