How to Use the FFmpeg Showwaves Filter
This guide provides a straightforward tutorial on using the FFmpeg
showwaves filter to convert audio inputs into visual
waveform videos. You will learn the fundamental command syntax, explore
key customization options like size, color, and drawing modes, and see
practical examples of how to generate high-quality audio
visualizers.
The showwaves filter in FFmpeg takes an audio input
stream and converts it into a video stream that visually represents the
audio’s amplitude over time. This is particularly useful for creating
music videos for social media, podcasts, or analyzing audio signals.
Basic Command Syntax
To generate a simple waveform video from an audio file, use the following basic command structure:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:mode=line[v]" -map "[v]" -map 0:a -c:v libx264 -c:a aac -b:a 192k output.mp4How this command works:
-i input.mp3: Specifies your input audio file.-filter_complex "[0:a]showwaves...[v]": Takes the first input’s audio stream ([0:a]), applies theshowwavesfilter with a resolution of 1280x720 using thelinedrawing mode, and outputs the video stream as[v].-map "[v]"and-map 0:a: Maps both the newly generated waveform video and the original input audio to the output file.-c:v libx264 -c:a aac: Encodes the video using H.264 and the audio using AAC for broad compatibility.
Key Customization Parameters
You can customize the appearance of the waveform by passing arguments
to the showwaves filter using the syntax
showwaves=parameter1=value1:parameter2=value2.
| Parameter | Description | Common Values |
|---|---|---|
size or s |
Sets the resolution of the output video. | 1920x1080,
1280x720, 640x480 |
mode |
Defines how the waveform is drawn. | point, line,
p2p (point-to-point), cline (centered
line) |
colors |
Specifies the color of the waveform. Can be defined by name or hex code. | red, blue,
0x00FF00, white\|yellow (for
multi-channel) |
scale |
Sets the amplitude scale. | lin (linear),
log (logarithmic), sqrt (square root) |
rate or r |
Sets the video frame rate. | 25, 30,
60 |
Practical Examples
1. Multi-Channel Colored Waveform
If you have a stereo audio file, you can assign different colors to
the left and right channels by separating the colors with a pipe
(|) character:
ffmpeg -i input.wav -filter_complex "[0:a]showwaves=s=1920x1080:mode=line:colors=red|blue[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp42. High Frame-Rate Solid Waveform (p2p mode)
For a denser, more solid-looking waveform, use the p2p
(point-to-point) mode and increase the frame rate to 60 frames per
second:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:mode=p2p:rate=60:colors=0x33FF33[v]" -map "[v]" -map 0:a -c:v libx264 output.mp43. Overlaying Waveform on a Background Image
To make a professional video, you can overlay the transparent waveform on top of a static background image:
ffmpeg -loop 1 -i background.jpg -i input.mp3 -filter_complex "[1:a]showwaves=s=1920x1080:mode=line:colors=white:format=rgba[wave];[0:v][wave]overlay=format=auto:shortest=1[outv]" -map "[outv]" -map 1:a -c:v libx264 -c:a aac output.mp4Note: In the overlay command, format=rgba is passed
to the showwaves filter to ensure the waveform background
is transparent, allowing the image underneath to be visible.