Create Animated Spectrum Video with FFmpeg
This guide explains how to create a real-time animated spectrum
visualization from an audio file using FFmpeg. Although FFmpeg features
a filter named showspectrumpic, that specific filter is
engineered to generate a single, static summary image of the entire
audio file. To create a continuous, real-time animated spectrum video,
FFmpeg provides its dynamic counterpart: the showspectrum
filter. Below are the precise commands, configurations, and color
settings required to render a fully synchronized audio visualizer.
The Real-Time Command
To generate an animated video synced with the source audio, use the
showspectrum filter inside a -filter_complex
pipeline:
ffmpeg -i input.mp3 -filter_complex "[0:a]showspectrum=s=1920x1080:mode=combined:color=rainbow:scale=log:slide=scroll[v]" -map "[v]" -map 0:a -c:v libx264 -pix_fmt yuv420p -c:a copy output.mp4Parameter Breakdown
[0:a]: Selects the first audio stream from the input file as the visualization source.s=1920x1080: Defines the output video resolution (Width x Height).mode=combined: Sets channel visualization. Options include:combined: Merges all audio channels into one display.separate: Displays each audio channel in its own visual track.
color=rainbow: Chooses the color map. Common palettes includeintensity,rainbow,fiery,fruit,cool, andmagma.scale=log: Adjusts frequency scaling. Thelog(logarithmic) scale best matches human auditory perception. Other values includelin(linear),sqrt(square root), andcbrt(cubic root).slide=scroll: Controls animation movement.scroll: The spectrum continuously scrolls from right to left as new audio plays.replace: A sweep line moves across the screen, overwriting older visual data.
-map "[v]"and-map 0:a: Pairs the newly rendered visualization stream with the original audio stream.-pix_fmt yuv420p: Ensures standard pixel format compatibility across modern media players and web browsers.-c:a copy: Copies the original audio track without re-encoding to preserve sound quality.
Static Analysis with
showspectrumpic
If your objective is to generate a single visual representation of
the entire track's frequency profile rather than a video, use
showspectrumpic:
ffmpeg -i input.mp3 -lavfi showspectrumpic=s=1920x1080:color=fiery:scale=log output.pngThis processes the complete audio stream and outputs a static image showing the frequency distribution across the entire duration of the track.