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.mp4

Parameter Breakdown:


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.mp4

2. 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.mp4

3. 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.mp4

Overlaying 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.mp4

Key Additions: