How to Use FFmpeg showspectrumpic

This article provides a straightforward guide on how to use the FFmpeg showspectrumpic filter to generate a visual spectrogram from an audio file. You will learn the exact commands to create static spectrogram images, customize their appearance (such as size, color, and scale), and convert the resulting image into a video file to pair with your audio.

Basic showspectrumpic Command

The showspectrumpic filter is designed to analyze an entire audio file and output a single, high-resolution static image of its frequency spectrum.

To generate a basic spectrogram image from an audio file, use the following command:

ffmpeg -i input.mp3 -lavfi showspectrumpic output.png

Customizing the Spectrogram

You can customize the output image by passing parameters to the filter. Common options include:

Example with Custom Parameters:

To create a 1920x1080 logarithmic spectrogram with a “cool” color scheme and a legend, use this command:

ffmpeg -i input.mp3 -lavfi "showspectrumpic=s=1920x1080:scale=log:color=cool:legend=1" output.png

Creating a Video from the Spectrogram Image

Because showspectrumpic only outputs a static image, you must combine that image back with your original audio file to create a video. You can do this by looping the static image for the duration of the audio:

ffmpeg -loop 1 -i output.png -i input.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest video_spectrogram.mp4

Command breakdown:

Alternative: Direct Video Spectrogram

If you prefer a dynamic, moving video spectrogram instead of a static image, use the showspectrum filter instead of showspectrumpic. This generates a real-time animated video representation of the audio frequencies:

ffmpeg -i input.mp3 -filter_complex "[0:a]showspectrum=s=1280x720:mode=combined:color=rainbow[v]" -map "[v]" -map 0:a -c:v libx264 -c:a aac output.mp4