FFmpeg showspectrumpic: Create Spectrogram from Audio

This article explains how to use the showspectrumpic filter in FFmpeg to convert any audio file into a static, high-resolution spectrogram image. You will learn the basic command syntax, how to customize the image dimensions, adjust the color scales, and configure advanced visualization settings to suit your analysis or aesthetic needs.

Understanding showspectrumpic

Unlike the showspectrum filter which outputs a video stream, showspectrumpic is specifically designed to analyze an entire audio file and output a single, static image representing its frequency spectrum over time. This is highly useful for audio analysis, mastering, or simply visualizing the frequency footprint of an audio track.

The Basic Command

To generate a standard spectrogram using the default settings, use the following basic command:

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

In this command: * -i input.mp3 specifies your input audio file. * -lavfi showspectrumpic calls the filtergraph to apply the spectrogram generation filter. * output.png is the final static image file.

Customizing the Spectrogram

The showspectrumpic filter offers several parameters to customize the visual output. Parameters are passed as key-value pairs separated by colons.

1. Adjusting Image Resolution (s)

You can define the width and height of the output image using the s (size) parameter. The default resolution is 4096x2048.

ffmpeg -i input.mp3 -lavfi "showspectrumpic=s=1024x512" output.png

2. Changing the Color Scheme (color)

You can change the color palette of the intensity scale. Available options include rainbow, green, magma, cool, fiery, and intensity.

ffmpeg -i input.mp3 -lavfi "showspectrumpic=color=fiery" output.png

3. Modifying Frequency Scale (scale)

To change how frequencies are scaled visually, use the scale parameter. Options include: * lin: Linear scale * log: Logarithmic scale (default, recommended for human hearing perception) * sqrt: Square root scale * 4thrt: 4th root scale * 8thrt: 8th root scale

ffmpeg -i input.mp3 -lavfi "showspectrumpic=scale=log" output.png

4. Displaying the Legend and Axes (legend)

By default, FFmpeg includes a legend displaying the decibel (dB) color scale and frequency/time axes. You can disable this by setting legend=0.

ffmpeg -i input.mp3 -lavfi "showspectrumpic=legend=0" output.png

Advanced Configuration Example

You can combine multiple parameters to create a highly customized, professional spectrogram. The following command creates a 1920x1080 image, uses a logarithmic scale, applies the “magma” color theme, and displays the legend:

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