FFmpeg astats: Get Detailed Audio Track Statistics

Analyzing audio files for peak levels, RMS amplitude, DC offset, and dynamic range is crucial for audio mastering, broadcasting, and quality control. This guide demonstrates how to use the FFmpeg astats (audio statistics) filter to extract detailed technical data from any audio track, explaining the essential command syntax, key output metrics, and practical use cases.

The Basic Command

To measure the statistics of an audio file without producing a new output file, use the astats filter with the null muxer (-f null -). This processes the audio and prints the statistical report directly to your terminal.

Run the following command in your terminal:

ffmpeg -i input.wav -af astats -f null -

Because FFmpeg outputs diagnostic information to the standard error (stderr) stream, you can redirect the statistics to a text file for easier reading:

ffmpeg -i input.wav -af astats -f null - 2> audio_stats.txt

Understanding the Output Metrics

The astats filter outputs values for each individual audio channel (e.g., Channel 1, Channel 2) as well as cumulative overall statistics. Here are the most critical parameters provided in the report:

Advanced Usage Examples

1. Measure Peak and RMS Levels Only

If you want to filter out the noise and only view specific parameters, you can use the metadata filter or parse the output. However, to configure the interval at which astats updates its measurements, use the metadata option:

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

This injects the statistical values into the frame metadata, which is useful for downstream filters or custom scripts.

2. Reset Statistics at Specific Intervals

By default, astats calculates cumulative statistics for the entire file. If you want to measure statistics for shorter windowed intervals (e.g., every 30 seconds), use the reset parameter:

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

This tells the filter to recalculate and output statistics fresh after every 30-second block of audio.