How to Use the FFmpeg showspectrumpic Filter

This article provides a practical guide on how to use the showspectrumpic filter in FFmpeg to convert audio files into visual spectrogram images. You will learn the basic command structure, essential configuration parameters like size and color, and real-world examples to help you generate detailed audio frequency visualizations.

Unlike the showspectrum filter which outputs a continuous video stream, the showspectrumpic filter is designed specifically to generate a single, static high-resolution image representing the entire audio file’s frequency spectrum. This is ideal for analyzing audio characteristics, mastering, or creating visual assets for music.

Basic Syntax

The most basic command to generate a spectrogram from an audio file requires an input audio file, the showspectrumpic filter, and an output image file (typically PNG or JPEG):

ffmpeg -i input.wav -filter_complex showspectrumpic output.png

Key Parameters and Customization

You can customize the output image by passing options to the filter, separated by colons.

1. Image Resolution (s)

Define the width and height of the output image in pixels. The default size is 4096x2048.

ffmpeg -i input.wav -filter_complex "showspectrumpic=s=1920x1080" output.png

2. Color Mode (color)

Change the color map used to represent intensity. Available options include rainbow, cool, fire, magma, green, and intensity.

ffmpeg -i input.wav -filter_complex "showspectrumpic=color=fire" output.png

3. Amplitude Scale (scale)

Adjust how the audio amplitude is scaled. Options include: * lin (linear) * log (logarithmic - highly recommended for musical analysis) * sqrt (square root) * cbrt (cubic root)

ffmpeg -i input.wav -filter_complex "showspectrumpic=scale=log" output.png

4. Display Legend (legend)

By default, FFmpeg draws a legend on the right side of the image showing the frequency and decibel scale. You can disable this by setting legend=0.

ffmpeg -i input.wav -filter_complex "showspectrumpic=legend=0" output.png

Advanced Examples

To combine multiple options for a professional, high-resolution “magma” styled spectrogram with a log scale and dimensions of 2560x1440, use the following command:

ffmpeg -i input.mp3 -filter_complex "showspectrumpic=s=2560x1440:color=magma:scale=log:legend=1" output.png

If you are dealing with multi-channel audio (like 5.1 surround sound) and want to combine all channels into a single visualization, you can use the channel_layout option:

ffmpeg -i input.wav -filter_complex "showspectrumpic=channel_layout=mono" output.png