FFmpeg showwaves: Generate Video from Audio
This article provides a step-by-step guide on how to use the FFmpeg
showwaves filter to convert an audio file into a visual
waveform video. You will learn the basic syntax required to render a
waveform, how to customize the video’s appearance using different
colors, dimensions, and draw modes, and how to overlay the waveform onto
a background image alongside the original audio.
The Basic Command
To convert an audio file into a video with a simple waveform
representation, you can use the showwaves filter inside
FFmpeg’s -filter_complex flag.
The following command takes an input audio file, converts it into a 1280x720 video showing a blue waveform, and combines it with the original audio:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:mode=line:colors=blue[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp4Parameter Breakdown:
[0:a]: Selects the audio stream from the first input file (input.mp3).showwaves: Calls the waveform visualization filter.s=1280x720: Sets the output video resolution (width x height).mode=line: Draws the waveform as connected lines.colors=blue: Sets the color of the waveform.[v]: Names the resulting video stream.-map "[v]"and-map 0:a: Maps 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 widely compatible H.264 codec.
Customizing the Waveform
The showwaves filter includes several parameters to
customize how the audio levels are visualized.
1. Visualization Modes
(mode)
You can change the shape of the waveform using the mode
option: * point: Draws a single point for
each sample. * line: Draws a continuous
line (default). * p2p: Draws
point-to-point lines (creates a filled effect). *
cline: Draws a centered line.
Example using p2p:
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1920x1080:mode=p2p:colors=green[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp42. Multi-Channel Waveforms
If your audio is stereo, you can color each channel differently by
separating colors with a pipe (|) character:
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.mp43. Scaling Options
(scale)
You can adjust the amplitude scaling to make quiet parts of the audio
more visible. Options include lin (linear),
log (logarithmic), and sqrt (square root).
ffmpeg -i input.mp3 -filter_complex "[0:a]showwaves=s=1280x720:scale=log[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp4Overlaying the Waveform on a Background Image
Instead of rendering the waveform on a black background, you can overlay it on a custom image.
The command below loops a static background image, generates a transparent waveform, overlays the waveform on top of the image, and matches the video duration to the audio track:
ffmpeg -loop 1 -i background.jpg -i input.mp3 -filter_complex "[1:a]showwaves=s=1280x720:mode=line:colors=white:draw=scale[wave];[0:v][wave]overlay=x=0:y=0:shortest=1[outv]" -map "[outv]" -map 1:a -c:v libx264 -pix_fmt yuv420p output.mp4Key Additions:
-loop 1 -i background.jpg: Loops the background image continuously.draw=scale: Ensures the waveform is drawn with scale transparency so it overlays cleanly.overlay=x=0:y=0: Places the waveform at the top-left coordinate (0,0) of the background image.shortest=1: Tells FFmpeg to stop encoding as soon as the shortest input (the audio file) ends.