Analyze Audio Properties with FFmpeg astats Filter

The FFmpeg astats filter is a powerful tool for measuring and displaying various statistical properties of audio streams, such as peak levels, RMS amplitude, dynamic range, and DC offset. This guide provides a straightforward explanation of how to use the astats filter to analyze audio tracks, interpret the command-line output, and apply the filter to common audio analysis workflows.

Basic Syntax for Audio Analysis

To analyze an audio file without generating a new output file, you should route the output to the “null” muxer. This process scans the audio and prints the statistics directly to your terminal window.

Use the following basic command structure:

ffmpeg -i input.mp3 -filter_complex astats -f null -

In this command: * -i input.mp3 specifies your input audio or video file. * -filter_complex astats (or -af astats) applies the audio statistics filter. * -f null - tells FFmpeg to discard the output video/audio stream, preventing the creation of an unnecessary output file while still processing the entire input to gather statistics.

Understanding the astats Output

Once the command finishes processing, FFmpeg will display a detailed report in the terminal. The output is divided into per-channel statistics (e.g., Channel 1, Channel 2) and cumulative “Overall” statistics.

Here are the key metrics provided by the filter:

Advanced astats Options

You can customize the behavior of the astats filter by passing specific parameters.

Measuring Peak and RMS over Time (Metadata)

If you want to inject the statistical results as metadata into the stream frames for further processing or custom scripting, enable the metadata option:

ffmpeg -i input.wav -af astats=metadata=1 -f null -

Resetting Measurements

For real-time streaming or extremely long files, you can configure the filter to reset its accumulated statistics after a set number of frames. For example, to reset statistics every 100 frames:

ffmpeg -i input.wav -af astats=reset=100 -f null -

Changing the Measurement Window

By default, the RMS measurement uses a specific window length. You can adjust this duration (in seconds) to change how the average loudness is calculated. To set a 0.5-second integration window:

ffmpeg -i input.wav -af astats=length=0.5 -f null -