FFmpeg aselect Audio Segments by Volume Threshold
This guide explains how to extract audio segments that exceed a
specific volume threshold using FFmpeg's aselect filter.
Because aselect cannot measure audio levels on its own, it
must be paired with an audio analysis filter like ebur128
or astats to inject volume metadata into each frame. By
combining metadata generation, frame selection, and timestamp
correction, you can cut out quiet sections and output only the portions
of audio that meet your target volume level.
The Basic Command
To extract audio exceeding a momentary loudness threshold (in LUFS),
use the ebur128 filter alongside aselect:
ffmpeg -i input.mp3 -af "ebur128=metadata=1,aselect='gt(lavfi.r128.M\,-20)',asetpts=N/SR/TB" output.mp3How the Filterchain Works
The filtergraph processes audio in three sequential stages:
ebur128=metadata=1: Analyzes the incoming audio according to the EBU R128 loudness standard and attaches the measured values to each audio frame as metadata. The parameterlavfi.r128.Mrepresents the momentary loudness measured over a 400ms sliding window.aselect='gt(lavfi.r128.M\,-20)': Evaluates the metadata for every frame. The expressiongt(lavfi.r128.M\,-20)tells FFmpeg to select only audio frames where the momentary loudness is greater than-20LUFS. Any frame measuring-20LUFS or quieter is discarded.asetpts=N/SR/TB: Resets the presentation timestamps (PTS) of the preserved audio frames. Without this filter, the output file will retain the original timestamps, resulting in long stretches of dead silence where audio was dropped.
Using RMS Volume Instead of LUFS
If you prefer measuring pure signal level (dBFS RMS) instead of
perceptual loudness (LUFS), replace ebur128 with
astats:
ffmpeg -i input.wav -af "astats=metadata=1:reset=1,aselect='gt(lavfi.astats.Overall.RMS_level\,-25)',asetpts=N/SR/TB" output.wavastats=metadata=1:reset=1recalculates audio statistics per frame and outputslavfi.astats.Overall.RMS_level.gt(lavfi.astats.Overall.RMS_level\,-25)retains frames with an overall RMS level higher than-25dBFS.
Tuning the Threshold
- Raising the threshold (e.g.,
-14dB / LUFS): Selects only the loudest peaks, discarding normal speech and background noise. - Lowering the threshold (e.g.,
-35dB / LUFS): Retains most audio while filtering out faint background hums or near-silent pauses. - Syntax Note: When using negative values inside
filter expressions, always escape the comma before the minus sign
(
\,-20) to prevent FFmpeg from interpreting it as a filter separator.