Extract Audio Above Volume Threshold with FFmpeg aselect
This article explains how to use FFmpeg’s aselect filter
in combination with audio statistics to isolate and extract audio
segments that exceed a specific volume threshold. You will learn the
exact command-line syntax, how to measure real-time volume metadata, and
how to export the resulting loud audio clips while discarding the quiet
parts.
The Command
To select audio frames based on volume, you must first generate
volume metadata for each frame and then pass that metadata to the
aselect filter. The most reliable way to do this is by
combining the astats filter (to measure volume) with
aselect (to filter it).
Use the following template command:
ffmpeg -i input.mp3 -af "astats=metadata=1,aselect='gt(metadata:lavfi.astats.Overall.RMS_level,-20)',asetpts=N/SR/TB" output.mp3How It Works
The audio filter chain (-af) performs three distinct
steps to filter the audio:
astats=metadata=1
This injects statistical metadata into each audio frame in real-time. It calculates properties like RMS (Root Mean Square) power and peak levels.aselect='gt(metadata:lavfi.astats.Overall.RMS_level,-20)'
Theaselectfilter evaluates an expression for every audio frame.metadata:lavfi.astats.Overall.RMS_levelreads the overall RMS volume (in decibels) of the current frame calculated byastats.gt(..., -20)stands for “greater than.” This tells FFmpeg to only keep audio frames where the volume is louder than -20 dB. Anything quieter than -20 dB is discarded.
asetpts=N/SR/TB
When frames are discarded, gaps are left in the audio timeline. This filter regenerates clean Presentation Timestamps (PTS) for the remaining frames, stitching them back together into a continuous, gapless audio file.
Customizing the Threshold
- To make the filter more sensitive (keep quieter
sounds): Lower the decibel limit (e.g., change
-20to-30or-35). - To make the filter less sensitive (keep only very loud
sounds): Raise the decibel limit closer to zero (e.g., change
-20to-15or-10).
Alternative: Filtering by Peak Volume
If you prefer to extract segments based on peak volume rather than
average RMS volume, change the metadata key to
Peak_level:
ffmpeg -i input.mp3 -af "astats=metadata=1,aselect='gt(metadata:lavfi.astats.Overall.Peak_level,-10)',asetpts=N/SR/TB" output.mp3