Extract Audio Segments by Volume Using FFmpeg
This guide explains how to use the FFmpeg aselect filter
to automatically detect and extract audio segments based on their volume
levels. You will learn how to combine the ebur128 loudness
analysis filter with aselect to target specific decibel
thresholds, allowing you to discard silence and export only the loud or
active portions of an audio file.
The Methodology
The aselect filter decides whether to keep or discard
audio frames based on a specified boolean expression. Because
aselect cannot measure audio volume on its own, it must be
paired with a filter that detects volume and injects metadata into the
audio stream.
The most effective tool for this is the ebur128 filter,
which performs high-precision loudness measurement. By enabling metadata
injection in ebur128, the aselect filter can
read the momentary volume of each frame and filter out anything below
your target threshold.
The Command Syntax
To extract audio segments where the volume is louder than a specific threshold, use the following command template:
ffmpeg -i input.wav -af "ebur128=metadata=1,aselect='gt(metadata(lavfi.r128.M),-20)',asetpts=N/SR/TB" output.wavHow the Filters Work
ebur128=metadata=1: This analyzes the audio stream according to the EBU R128 loudness standard and injects loudness metrics into each frame’s metadata. The keylavfi.r128.Mrepresents the “Momentary” loudness (measured over a 400ms window) in LUFS (Loudness Units Full Scale), which roughly corresponds to decibels (dB).aselect='gt(metadata(lavfi.r128.M),-20)': This is the decision maker. Thegt(greater than) function compares the momentary loudness of the frame against the threshold of-20LUFS. If the loudness is greater than-20LUFS, the frame is kept; otherwise, it is dropped.asetpts=N/SR/TB: Dropping quiet frames creates gaps in the timeline. This filter regenerates continuous presentation timestamps (PTS) for the selected frames, stitching the loud segments together into a seamless output file without dead air.
Adjusting the Threshold
You can customize the volume threshold by changing the numeric value
inside the aselect expression:
To extract only very loud sounds (e.g., clipping, shouting, or music peaks), raise the threshold closer to zero:
aselect='gt(metadata(lavfi.r128.M),-10)'To preserve normal speech while removing background hiss or silent pauses, lower the threshold:
aselect='gt(metadata(lavfi.r128.M),-35)'