Generate a waveform image from audio
A waveform image is a horizontal line graph showing the amplitude of an audio signal over time. Podcasts, DAWs, and audio editors all show one; you can generate one as a static image with FFmpeg, which is useful for embedding in a blog post or a report.
The command
ffmpeg -i in.wav -filter_complex "[0:a]showwaves=s=1920x200:mode=line:colors=white,format=yuv420p[out]" -map "[out]" -frames:v 1 waveform.pngWhat it does
The `showwaves` filter reads the audio stream and renders a single image with the waveform. The `s` parameter is the output size, `mode` is the visualization style (`line`, `point`, `cline`, `p2p`), and `colors` is a CSS-style color list. With `-frames:v 1`, the output is a single image; drop that flag to get a video of the waveform building up over the file.
Requirements
Any audio input. The filter is in libavfilter. CPU-only, single-pass. The output image size is independent of the audio duration; a 1920x200 PNG can represent a 3-minute podcast or a 3-hour lecture.
Things to avoid
- Rendering at a very wide size with `mode=line` and expecting a sharp image. The line is anti-aliased, so widths above 3840 may show stair-stepping.
- Forgetting the `format=yuv420p` filter. PNG output expects RGB, so the format conversion prevents a 'specified pixel format is not supported' error.
- Using the waveform for loudness analysis. The image shows peak amplitude, not LUFS or perceived loudness. For broadcast loudness, use the `ebur128` filter.
- Re-encoding the audio. There is no audio output here; the `-frames:v 1` flag limits the video output to one image.