How to Export Audio Peak Levels to Text with FFmpeg
This article provides a quick and direct guide on how to analyze an audio file’s peak levels using FFmpeg and export that metadata into a text file. By utilizing FFmpeg’s built-in audio filters and command-line redirection, you can quickly extract volume statistics without needing to render a new audio file.
The Standard Method: Using the volumedetect Filter
FFmpeg does not write metadata directly to a text file via standard
output options, as volume statistics are printed to the system’s
standard error stream (stderr). To capture this data, you
must run the volume detection filter and redirect the stream output to a
.txt file.
Run the following command in your terminal or command prompt:
ffmpeg -i input.wav -filter:a volumedetect -f null - 2> peak_levels.txtCommand Breakdown:
-i input.wav: Specifies your input audio or video file.-filter:a volumedetect: Calls the audio filter that analyzes the volume levels of the stream.-f null -: Instructs FFmpeg to discard the output video/audio stream so that no new media file is created, making the process incredibly fast.2> peak_levels.txt: Redirects the standard error stream (where the volume information is printed) into a text file namedpeak_levels.txt.
Reading the Output File
Once the process finishes, open the generated
peak_levels.txt file. Near the bottom of the file, you will
find the volume metadata, which looks similar to this:
[parsed_volumedetect_0 @ 0x55bf30bc7ec0] n_samples: 441000
[parsed_volumedetect_0 @ 0x55bf30bc7ec0] max_volume: -1.2 dB
[parsed_volumedetect_0 @ 0x55bf30bc7ec0] mean_volume: -18.5 dB
[parsed_volumedetect_0 @ 0x55bf30bc7ec0] histogram_1db: 124
The max_volume value represents the
peak level of your audio file (in this case, -1.2 dB).
Advanced Method: Using the astats Filter for Multi-Channel Peaks
If you need precise peak measurements for individual channels (such
as Left and Right in a stereo file), use the astats filter
instead:
ffmpeg -i input.wav -filter:a astats=metadata=1 -f null - 2> channel_peaks.txtInside the resulting channel_peaks.txt file, search for
the Peak level dB values to get the exact peak levels for
each individual audio channel.