How to Use the FFmpeg showvolume Filter
This article provides a quick guide on how to use the FFmpeg
showvolume filter to convert your audio signals into a
visual volume meter. You will learn the basic syntax of the filter, its
key customization parameters, and how to overlay the volume visualizer
directly onto an existing video file.
What is the showvolume Filter?
The showvolume filter in FFmpeg is an audio
visualization filter. It takes an input audio stream and generates a
video stream showing a volume bar (or meter) that updates in real-time
based on the volume levels of the audio.
Basic Syntax and Parameters
The basic structure of the filter is
showvolume=key=value:key2=value2. Here are the most
commonly used parameters to customize the visualizer:
rate/r: Set the video frame rate (default is 25).w/h: Define the width and height of the generated volume visualization.f: Set the volume representation format.0represents Peak, and1represents RMS (Root Mean Square). RMS is generally preferred for a smoother representation of perceived loudness.o: Set the orientation of the volume bar. Usehfor horizontal (default) orvfor vertical.c: Define the color scheme. You can specify custom colors for different volume thresholds (e.g., green for quiet, yellow for mid-range, red for clipping).
Practical Examples
Example 1: Convert Audio into a Volume Meter Video
If you have an audio file (like an MP3) and want to generate a video showing just its volume meter, use the following command:
ffmpeg -i input.mp3 -filter_complex "[0:a]showvolume=f=1:w=800:h=40:r=30[v]" -map "[v]" -map 0:a output.mp4Explanation of this command: *
-i input.mp3: Loads your input audio file. *
[0:a]showvolume=...[v]: Processes the audio stream
([0:a]) through the filter. f=1 sets it to RMS
mode, w=800:h=40 sets the dimensions, and r=30
targets 30 frames per second. The resulting video stream is named
[v]. * -map "[v]" and -map 0:a:
Maps both the newly generated video stream and the original audio stream
into the output file output.mp4.
Example 2: Overlay a Volume Meter on an Existing Video
To overlay a transparent volume meter on top of a video, you must
combine showvolume with the overlay filter
inside a filtergraph:
ffmpeg -i input.mp4 -filter_complex "[0:a]showvolume=f=1:w=400:h=30:o=h[volume];[0:v][volume]overlay=x=20:y=20[outv]" -map "[outv]" -map 0:a output.mp4Explanation of this command: *
[0:a]showvolume=...[volume]: Creates a horizontal volume
meter stream called [volume]. *
[0:v][volume]overlay=x=20:y=20[outv]: Takes the original
video input [0:v] and overlays the [volume]
video stream on top of it, positioned 20 pixels from the left
(x=20) and 20 pixels from the top (y=20). *
-map "[outv]" and -map 0:a: Outputs the
combined video and original audio to the destination file.