History

avfilter/af_silenceremove: fix the any/all confusion and change default

'any' stop mode is now correctly implemented for end trimming and is of limited usage. Extend examples and other documentation of this filter.

Paul B Mahol committed 3 years ago

Commit e8e48631 parent 8d662ad3 files · +50 −18Browse files

Unified · Split

3 files
  1. doc/filters.texi +48 −14
  2. libavfilter/af_silenceremove.c +1 −1
  3. libavfilter/silenceremove_template.c +1 −3
doc/filters.texi+48−14
@@ -6419,15 +6419,16 @@ trimming. Default is 0, which is equal to trimming all samples detected · 6418 unmodified lines
6419as silence.6419as silence.
6420 6420
6421@item start_mode6421@item start_mode
6422Specify mode of detection of silence end in start of multi-channel audio.6422Specify mode of detection of silence end at start of multi-channel audio.
6423Can be @var{any} or @var{all}. Default is @var{any}.6423Can be @var{any} or @var{all}. Default is @var{any}.
6424With @var{any}, any sample that is detected as non-silence will cause6424With @var{any}, any sample from any channel that is detected as non-silence
6425stopped trimming of silence.6425will trigger end of silence trimming at start of audio stream.
6426With @var{all}, only if all channels are detected as non-silence will cause6426With @var{all}, only if every sample from every channel is detected as non-silence
6427stopped trimming of silence.6427will trigger end of silence trimming at start of audio stream, limited usage.
6428 6428
6429@item stop_periods6429@item stop_periods
6430Set the count for trimming silence from the end of audio.6430Set the count for trimming silence from the end of audio. When specifying a
6431positive value, it trims audio after it finds specified silence period.
6431To remove silence from the middle of a file, specify a @var{stop_periods}6432To remove silence from the middle of a file, specify a @var{stop_periods}
6432that is negative. This value is then treated as a positive value and is6433that is negative. This value is then treated as a positive value and is
6433used to indicate the effect should restart processing as specified by6434used to indicate the effect should restart processing as specified by
@@ -6453,20 +6454,34 @@ trimming. Default is 0, which is equal to trimming all samples detected · 19 unmodified lines
6453as silence.6454as silence.
6454 6455
6455@item stop_mode6456@item stop_mode
6456Specify mode of detection of silence start in end of multi-channel audio.6457Specify mode of detection of silence start after start of multi-channel audio.
6457Can be @var{any} or @var{all}. Default is @var{any}.6458Can be @var{any} or @var{all}. Default is @var{all}.
6458With @var{any}, any sample that is detected as non-silence will cause6459With @var{any}, any sample from any channel that is detected as silence
6459stopped trimming of silence.6460will trigger start of silence trimming after start of audio stream, limited usage.
6460With @var{all}, only if all channels are detected as non-silence will cause6461With @var{all}, only if every sample from every channel is detected as silence
6461stopped trimming of silence.6462will trigger start of silence trimming after start of audio stream.
6462 6463
6463@item detection6464@item detection
6464Set how is silence detected. Can be @code{avg}, @code{rms}, @code{median} or @code{peak}.6465Set how is silence detected.
6466@table @option
6467@item avg
6468Mean of absolute values of samples in moving window.
6469@item rms
6470Root squared mean of absolute values of samples in moving window.
6471@item peak
6472Maximum of absolute values of samples in moving window.
6473@item median
6474Median of absolute values of samples in moving window.
6475@end table
6465Default value is @code{rms}.6476Default value is @code{rms}.
6466 6477
6467@item window6478@item window
6468Set duration in number of seconds used to calculate size of window in number6479Set duration in number of seconds used to calculate size of window in number
6469of samples for detecting silence.6480of samples for detecting silence. Using @code{0} will effectively disable
6481any windowing and use only single sample per channel for silence detection.
6482In that case it may be needed to also set @option{start_silence} and/or
6483@option{stop_silence} to nonzero values with also @option{start_duration} and/or
6484@option{stop_duration} to nonzero values.
6470Default value is @code{0.02}. Allowed range is from @code{0} to @code{10}.6485Default value is @code{0.02}. Allowed range is from @code{0} to @code{10}.
6471@end table6486@end table
6472 6487
@@ -6495,6 +6510,25 @@ silence is detected in all channels at same positions in stream: · 22 unmodified lines
6495@example6510@example
6496silenceremove=window=0:detection=peak:stop_mode=all:start_mode=all:stop_periods=-1:stop_threshold=06511silenceremove=window=0:detection=peak:stop_mode=all:start_mode=all:stop_periods=-1:stop_threshold=0
6497@end example6512@end example
6513
6514@item
6515Trim every 2nd encountered silence period from beginning to end where there is
6516more than 1 second of silence per silence period in audio:
6517@example
6518silenceremove=stop_periods=-2:stop_duration=1:stop_threshold=-90dB
6519@end example
6520
6521@item
6522Similar as above, but keep maximum of 0.5 seconds of silence from each trimmed period:
6523@example
6524silenceremove=stop_periods=-2:stop_duration=1:stop_threshold=-90dB:stop_silence=0.5
6525@end example
6526
6527@item
6528Similar as above, but keep maximum of 1.5 seconds of silence from start of audio:
6529@example
6530silenceremove=stop_periods=-2:stop_duration=1:stop_threshold=-90dB:stop_silence=0.5:start_periods=1:start_duration=1:start_silence=1.5:stop_threshold=-90dB
6531@end example
6498@end itemize6532@end itemize
6499 6533
6500@subsection Commands6534@subsection Commands
libavfilter/af_silenceremove.c+1−1
@@ -129,7 +129,7 @@ static const AVOption silenceremove_options[] = { · 128 unmodified lines
129 { "stop_duration", "set stop duration of silence part", OFFSET(stop_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },129 { "stop_duration", "set stop duration of silence part", OFFSET(stop_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
130 { "stop_threshold", "set threshold for stop silence detection", OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AFR },130 { "stop_threshold", "set threshold for stop silence detection", OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AFR },
131 { "stop_silence", "set stop duration of silence part to keep", OFFSET(stop_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },131 { "stop_silence", "set stop duration of silence part to keep", OFFSET(stop_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
132 { "stop_mode", "set which channel will trigger trimming from end", OFFSET(stop_mode), AV_OPT_TYPE_INT, {.i64=T_ANY}, T_ANY, T_ALL, AFR, "mode" },132 { "stop_mode", "set which channel will trigger trimming from end", OFFSET(stop_mode), AV_OPT_TYPE_INT, {.i64=T_ALL}, T_ANY, T_ALL, AFR, "mode" },
133 { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, 0, D_NB-1, AF, "detection" },133 { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, 0, D_NB-1, AF, "detection" },
134 { "avg", "use mean absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_AVG}, 0, 0, AF, "detection" },134 { "avg", "use mean absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_AVG}, 0, 0, AF, "detection" },
135 { "rms", "use root mean squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" },135 { "rms", "use root mean squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" },
libavfilter/silenceremove_template.c+1−3
@@ -403,10 +403,8 @@ static void fn(filter_stop)(AVFilterContext *ctx, · 402 unmodified lines
403 s->stop_found_periods = 0;403 s->stop_found_periods = 0;
404 404
405 if (s->stop_found_periods >= 0 || ctx->is_disabled) {405 if (s->stop_found_periods >= 0 || ctx->is_disabled) {
406 if (s->found_nonsilence) {406 if (s->found_nonsilence)
407 s->stop_sample_count += stop_thres;407 s->stop_sample_count += stop_thres;
408 s->stop_sample_count *= stop_thres;
409 }
410 } else if (s->stop_silence_count > 0) {408 } else if (s->stop_silence_count > 0) {
411 const int dst_pos = out_nb_samples * nb_channels;409 const int dst_pos = out_nb_samples * nb_channels;
412 for (int ch = 0; ch < nb_channels; ch++)410 for (int ch = 0; ch < nb_channels; ch++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t