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.wav

How the Filters Work

Adjusting the Threshold

You can customize the volume threshold by changing the numeric value inside the aselect expression: