How to Use FFmpeg Showwaves for Audio Waveform Videos
This guide provides a straightforward walkthrough on how to use the
FFmpeg showwaves filter to convert audio files into dynamic
waveform videos. You will learn the basic command structures, how to
customize the visual appearance of the waveform using different modes
and colors, and how to overlay the visualization onto a background image
for a professional finish.
The Basic Waveform Command
To generate a simple video with a waveform on a black background, you
can use the showwaves filter inside a
-filter_complex graph. This filter takes the input audio
and converts it into a video stream.
Run the following command in your terminal:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:mode=line:colors=cyan[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p -c:a copy output.mp4Here is what each part of this command does: *
-i input.mp3: Specifies your source audio
file. * [0:a]showwaves=...[v]: Takes the
audio stream from the first input ([0:a]), applies the
showwaves filter, and outputs it as a video stream named
[v]. * s=1280x720: Sets the
resolution of the output video. *
mode=line: Draws the waveform as
continuous lines. * colors=cyan: Sets the
color of the waveform. *
-map "[v]" -map 0:a: Maps both the newly
created video stream and the original audio stream to the output file. *
-c:v libx264 -pix_fmt yuv420p: Encodes the
video using the H.264 codec with a widely compatible pixel format. *
-c:a copy: Copies the audio stream without
re-encoding to preserve quality.
Customizing Waveform Appearance
The showwaves filter offers several parameters to alter
how the waveform is rendered:
1. Visualization Modes
(mode)
You can change how the audio waves are drawn by modifying the
mode parameter: * point:
Draws a simple point for each sample. *
line: Connects the samples with lines
(default). * p2p: Draws point-to-point
lines (creates a filled effect). * cline:
Draws centered lines.
Example utilizing the p2p mode:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:mode=p2p:colors=red[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp42. Changing Colors
You can specify colors by name (e.g., red,
blue, green, white) or by using
hexadecimal values (e.g., 0xffaa00). You can also separate
multiple colors with a | symbol to color different audio
channels separately:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:colors=red|yellow[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp4Overlaying the Waveform on a Background Image
To make your video more engaging, you can overlay the transparent waveform onto a static background image.
Use the following command to merge a background image and an audio file:
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=shortest=1[outv]" -map "[outv]" -map 1:a -c:v libx264 -pix_fmt yuv420p output.mp4How this overlay command works: *
-loop 1 -i background.jpg: Loops the
background image continuously. *
format=rgba: Forces the
showwaves filter to output an alpha channel (transparency),
making the waveform background transparent instead of black. *
[0:v][wave]overlay=shortest=1[outv]:
Overlays the transparent waveform ([wave]) on top of the
background image ([0:v]). The shortest=1
parameter stops the video encoding as soon as the audio file ends.