How to Create a Spectrogram Video with FFmpeg

This article provides a straightforward guide on how to use FFmpeg’s showspectrum filter to convert any audio file into a visually dynamic, animated spectrogram video. You will learn the basic command structure, understand the key parameters for customizing the visualization, and see practical examples to help you generate high-quality audio visualizers.

The showspectrum filter in FFmpeg converts input audio into a video stream that represents the audio frequency spectrum over time. To generate a basic animated spectrogram video from an audio file, use the following command:

ffmpeg -i input.mp3 -filter_complex "showspectrum=s=1280x720:mode=combined:color=rainbow:scale=sqrt" -c:a copy output.mp4

Parameter Breakdown

To customize the look and feel of your spectrogram, you can adjust several parameters inside the -filter_complex flag:

Advanced Example with Custom Styling

For a more detailed, high-resolution visualization with a logarithmic scale and a scrolling effect, you can run:

ffmpeg -i input.wav -filter_complex "showspectrum=s=1920x1080:mode=separate:color=fire:scale=log:slide=scroll" -c:v libx264 -pix_fmt yuv420p -b:a 320k output.mp4

In this command: * The video resolution is set to 1080p (1920x1080). * The audio channels are visualised separately (mode=separate) using a hot color palette (color=fire). * The spectrum scrolls continuously (slide=scroll). * -pix_fmt yuv420p is added to ensure the output video is compatible with standard media players and web browsers. * The audio is re-encoded to AAC at 320 kbps (-b:a 320k) to maintain high audio fidelity.