Generate a showcqt spectrogram
Constant-Q transform (CQT) is a variant of the FFT where the frequency bins are spaced logarithmically, matching the way humans perceive pitch. The `showcqt` filter renders a CQT spectrogram as a video, which is the look of audio visualizers and music identification apps.
The command
ffmpeg -i in.wav -filter_complex "[0:a]showcqt=s=1920x1080,format=yuv420p[out]" -map "[out]" -t 30 -c:v libx264 -crf 20 cqt.mp4What it does
The filter computes a CQT of the audio, then renders the magnitude as a color-coded image. The result looks like a piano roll that scrolls vertically, with brighter colors for louder frequency components. The output is a video that updates as the audio plays; for a still image, drop the `-t` and add `-frames:v 1`.
Requirements
Any audio input. The filter is in libavfilter. CPU-only — the CQT is more expensive than the FFT, so a 1-hour file can take several minutes to render. The output resolution and color are configurable.
Things to avoid
- Using a very high resolution on a long file. The CQT is O(N log N) per frame; a 4K render of a 10-minute track can take 30 minutes.
- Confusing showcqt with showspectrum. showspectrum uses a linear FFT (good for technical analysis); showcqt uses a logarithmic CQT (good for music). Choose by the source material.
- Expecting the output to play at real time. The filter renders as fast as the CPU allows; a 30-second clip can take 5 seconds or 50 seconds depending on the resolution and the machine.
- Re-encoding the audio. There is no audio output here; the `-map "[out]"` flag selects only the video.