How to Use the FFmpeg showspectrum Filter
This article provides a practical guide on how to use the
showspectrum filter in FFmpeg to convert audio files into
visual spectrogram videos. You will learn the basic command structure,
explore essential configuration parameters like resolution, color modes,
and scaling, and view ready-to-use command examples for creating
high-quality audio visualizations.
What is the showspectrum Filter?
The showspectrum filter in FFmpeg is a visualization
tool that converts incoming audio signals into a video stream
representing the audio frequency spectrum. It is highly customizable,
allowing you to control how frequencies are scaled, colored, and
displayed over time.
Basic Usage
To generate a video from an audio file using the default
showspectrum settings, use the following basic command
structure. This command takes an audio input, applies the filter, and
pairs the generated video back with the original audio.
ffmpeg -i input.mp3 -filter_complex "[0:a]showspectrum=s=1280x720[v]" -map "[v]" -map 0:a output.mp4Command Breakdown:
-i input.mp3: Specifies the input audio file.-filter_complex "[0:a]showspectrum=s=1280x720[v]": Takes the audio track ([0:a]), applies theshowspectrumfilter with a resolution of 1280x720, and outputs the video stream as[v].-map "[v]" -map 0:a: Combines the newly created video stream and the original audio stream into the final output.output.mp4: The resulting video file.
Key Parameters and Customization
You can customize the look and behavior of the spectrogram by passing
specific parameters to the showspectrum filter, separated
by colons.
1. Set Video Resolution
(size or s)
Defines the width and height of the output video. *
Example: showspectrum=s=1920x1080 (Full
HD)
2. Adjust Frequency Scale
(scale)
Determines how frequencies are spaced vertically. *
linear: Linear spacing (default). * log:
Logarithmic spacing, which better represents how human ears perceive
pitch. * sqrt: Square root spacing. *
Example: showspectrum=scale=log
3. Change Color Schemes
(color)
Specifies the color palette of the intensity levels. Available
options include rainbow, cool,
magma, intensity, and channel
(different colors per audio channel). * Example:
showspectrum=color=rainbow
4. Choose sliding mode
(slide)
Controls how the spectrum moves across the screen. *
flow: The spectrum scrolls from right to left. *
scroll: The spectrum scrolls, leaving a trail. *
replace: The drawing line wraps around the screen. *
Example: showspectrum=slide=scroll
5. Multi-channel display
(mode)
Controls how multiple audio channels are drawn. *
combined: Channels are blended together. *
separate: Each channel is drawn in its own row. *
Example: showspectrum=mode=separate
Practical Examples
High-Definition Logarithmic Spectrogram
This command creates a 1080p video using a logarithmic frequency scale, which is ideal for musical analysis.
ffmpeg -i input.wav -filter_complex "[0:a]showspectrum=s=1920x1080:scale=log:color=intensity[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p output.mp4Separate Channel Stereo Visualization
If you have a stereo track and want to visualize the left and right channels separately with a rainbow color scheme, use this configuration:
ffmpeg -i input.mp3 -filter_complex "[0:a]showspectrum=s=1280x720:mode=separate:color=rainbow:slide=flow[v]" -map "[v]" -map 0:a output.mp4