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
64196419 as silence.
64206420
64216421 @item start_mode
6422−Specify mode of detection of silence end in start of multi-channel audio.
6422+Specify mode of detection of silence end at start of multi-channel audio.
64236423 Can be @var{any} or @var{all}. Default is @var{any}.
6424−With @var{any}, any sample that is detected as non-silence will cause
6425−stopped trimming of silence.
6426−With @var{all}, only if all channels are detected as non-silence will cause
6427−stopped trimming of silence.
6424+With @var{any}, any sample from any channel that is detected as non-silence
6425+will trigger end of silence trimming at start of audio stream.
6426+With @var{all}, only if every sample from every channel is detected as non-silence
6427+will trigger end of silence trimming at start of audio stream, limited usage.
64286428
64296429 @item stop_periods
6430−Set the count for trimming silence from the end of audio.
6430+Set the count for trimming silence from the end of audio. When specifying a
6431+positive value, it trims audio after it finds specified silence period.
64316432 To remove silence from the middle of a file, specify a @var{stop_periods}
64326433 that is negative. This value is then treated as a positive value and is
64336434 used 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
64536454 as silence.
64546455
64556456 @item stop_mode
6456−Specify mode of detection of silence start in end of multi-channel audio.
6457−Can be @var{any} or @var{all}. Default is @var{any}.
6458−With @var{any}, any sample that is detected as non-silence will cause
6459−stopped trimming of silence.
6460−With @var{all}, only if all channels are detected as non-silence will cause
6461−stopped trimming of silence.
6457+Specify mode of detection of silence start after start of multi-channel audio.
6458+Can be @var{any} or @var{all}. Default is @var{all}.
6459+With @var{any}, any sample from any channel that is detected as silence
6460+will trigger start of silence trimming after start of audio stream, limited usage.
6461+With @var{all}, only if every sample from every channel is detected as silence
6462+will trigger start of silence trimming after start of audio stream.
64626463
64636464 @item detection
6464−Set how is silence detected. Can be @code{avg}, @code{rms}, @code{median} or @code{peak}.
6465+Set how is silence detected.
6466+@table @option
6467+@item avg
6468+Mean of absolute values of samples in moving window.
6469+@item rms
6470+Root squared mean of absolute values of samples in moving window.
6471+@item peak
6472+Maximum of absolute values of samples in moving window.
6473+@item median
6474+Median of absolute values of samples in moving window.
6475+@end table
64656476 Default value is @code{rms}.
64666477
64676478 @item window
64686479 Set duration in number of seconds used to calculate size of window in number
6469−of samples for detecting silence.
6480+of samples for detecting silence. Using @code{0} will effectively disable
6481+any windowing and use only single sample per channel for silence detection.
6482+In 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.
64706485 Default value is @code{0.02}. Allowed range is from @code{0} to @code{10}.
64716486 @end table
64726487
@@ -6495,6 +6510,25 @@ silence is detected in all channels at same positions in stream: · 22 unmodified lines
64956510 @example
64966511 silenceremove=window=0:detection=peak:stop_mode=all:start_mode=all:stop_periods=-1:stop_threshold=0
64976512 @end example
6513+
6514+@item
6515+Trim every 2nd encountered silence period from beginning to end where there is
6516+more than 1 second of silence per silence period in audio:
6517+@example
6518+silenceremove=stop_periods=-2:stop_duration=1:stop_threshold=-90dB
6519+@end example
6520+
6521+@item
6522+Similar as above, but keep maximum of 0.5 seconds of silence from each trimmed period:
6523+@example
6524+silenceremove=stop_periods=-2:stop_duration=1:stop_threshold=-90dB:stop_silence=0.5
6525+@end example
6526+
6527+@item
6528+Similar as above, but keep maximum of 1.5 seconds of silence from start of audio:
6529+@example
6530+silenceremove=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
64986532 @end itemize
64996533
65006534 @subsection Commands
libavfilter/af_silenceremove.c+1−1
@@ -129,7 +129,7 @@ static const AVOption silenceremove_options[] = { · 128 unmodified lines
129129 { "stop_duration", "set stop duration of silence part", OFFSET(stop_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
130130 { "stop_threshold", "set threshold for stop silence detection", OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AFR },
131131 { "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" },
133133 { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, 0, D_NB-1, AF, "detection" },
134134 { "avg", "use mean absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_AVG}, 0, 0, AF, "detection" },
135135 { "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
403403 s->stop_found_periods = 0;
404404
405405 if (s->stop_found_periods >= 0 || ctx->is_disabled) {
406− if (s->found_nonsilence) {
406+ if (s->found_nonsilence)
407407 s->stop_sample_count += stop_thres;
408− s->stop_sample_count *= stop_thres;
409− }
410408 } else if (s->stop_silence_count > 0) {
411409 const int dst_pos = out_nb_samples * nb_channels;
412410 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