Find Max Volume of Audio Stream Using FFmpeg
This article explains how to quickly determine the maximum volume level (peak amplitude) of an audio stream using FFmpeg without performing any file conversion or re-encoding. By utilizing a specific audio filter alongside a null output format, you can analyze your media files instantly and efficiently.
To find the maximum volume of an audio stream, you should use
FFmpeg’s volumedetect filter. Running this filter with a
null output tells FFmpeg to analyze the file and print the volume
statistics to the console without writing a new output file.
The Command
Run the following command in your terminal:
ffmpeg -i input.mp3 -filter:a volumedetect -f null -(Note: Replace input.mp3 with your actual audio or
video file path.)
How It Works
-i input.mp3: Specifies the input file. This can be an audio file (like MP3, WAV, AAC) or a video file containing an audio track.-filter:a volumedetect(or shorthand-af volumedetect): Applies the audio filter that analyzes the volume levels of the stream.-f null -: Directs the output to a virtual “null” muxer. This forces FFmpeg to process the file as fast as possible to extract the data without actually saving or converting anything.
Interpreting the Output
After running the command, look at the terminal output. Near the end of the text block, you will see lines that look like this:
[parsed_volumedetect_0 @ 0x7f9a1bc04100] n_samples: 441000
[parsed_volumedetect_0 @ 0x7f9a1bc04100] mean_volume: -16.5 dB
[parsed_volumedetect_0 @ 0x7f9a1bc04100] max_volume: -1.2 dB
[parsed_volumedetect_0 @ 0x7f9a1bc04100] histogram_1db: 1
The line containing max_volume shows
the peak volume of the audio stream:
0.0 dBmeans the audio reaches the absolute maximum digital volume level (the clipping threshold).- Negative values (e.g.,
-1.2 dB) indicate how far below the digital limit the loudest part of the audio is. In this case, the peak volume is 1.2 decibels below clipping.