How to Create a Spectrogram Image from Audio with FFmpeg
The showspectrumpic filter in FFmpeg writes a spectrogram of an entire audio file as a single PNG image. A spectrogram is a chart where the horizontal axis is time, the vertical axis is frequency, and color shows how loud each frequency is at each moment. It is useful for finding where noise or hum (a low "buzzing" sound) sits in a recording, or for checking which frequencies are present in an audio file.
In my test environment, I made a 10-second audio file containing a constant-pitch tone and a rising tone (a sweep), and exported it with different options. The following command produces the image below.
ffmpeg -i tone.wav -lavfi showspectrumpic=s=400x400:stop=10000 -frames:v 1 -update 1 spectrogram.png

The test environment was Ubuntu 24.04.5, FFmpeg 6.1.1 (Ubuntu package 6.1.1-3ubuntu5), and a virtual machine with a 4-core CPU (with AVX-512) and 16 GB of memory. The audio was synthetic: sine waves and pink noise generated with FFmpeg. I tested with WAV (16-bit) and AAC. I did not test recorded speech or music, MP3 or FLAC input, other FFmpeg versions, CPUs without AVX-512, orientation=horizontal (which puts time on the vertical axis), or different window functions (win_func).
- 1. Audio used for the test
- 2. Without options, the image is large, 4378×2176
- 3. s is the size of the chart without the legend
- 4. Vertically, rows are evenly spaced from 0 Hz to the upper limit
- 5. start and stop draw only the frequency range you want
- 6. For a wider view of low sounds, use fscale=log
- 7. Quiet sounds are visible when the brightness scale is log
- 8. For stereo, draw both channels together or separately
- 9. You can also export directly from video files
- 10. Long audio uses a lot of memory
Audio used for the test
I made a 44.1 kHz stereo WAV split into the following sections. Amplitude is given relative to 1 for the loudest possible sound.
| Section | Left | Right |
|---|---|---|
| 0 to 3 s | 1000 Hz (amplitude 0.5) | 3000 Hz (amplitude 0.5) |
| 3 to 6 s | A tone rising at a constant rate from 100 Hz to 8000 Hz (amplitude 0.5) | Same as left |
| 6 to 8 s | 440 Hz (amplitude 0.5) and 5000 Hz (amplitude 0.005) mixed together | Same as left |
| 8 to 10 s | Silence | Silence |
The 5000 Hz tone has 1/100 the amplitude of the 440 Hz tone, which is 40 dB quieter. I included it to see how a quiet sound appears in the image.
Without options, the image is large, 4378×2176
The shortest form of the command is:
ffmpeg -i tone.wav -lavfi showspectrumpic default.png
The image produced was a 4378×2176 PNG (625,581 bytes). As described in the showspectrumpic section of the official documentation, the default size (s) is 4096×2048. Margins for the axis labels and the legend are added around it, which gives this size.
With this command, FFmpeg 6.1.1 printed a warning that the output filename does not contain an image sequence pattern (0x… is a value that changes on every run, so I have omitted it).
[image2 @ 0x…] The specified filename 'default.png' does not contain an image sequence pattern or a pattern is invalid.
[image2 @ 0x…] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
Adding -frames:v 1 -update 1 removed the warning, and the output image was byte-for-byte identical. All other commands in this article include these two options.
s is the size of the chart without the legend
With s=800x400, the image was 1082×528. Turning off the legend with legend=0 gives exactly 800×400.
The width of the legend margin changed with the audio's sampling rate. The height was 64 px above and below in every case. The widths were as follows.
| Sampling rate | Image size with s=800x400 |
Width added on each side |
|---|---|---|
| 8 kHz | 1044×528 | 122 px each |
| 44.1 kHz | 1082×528 | 141 px each |
| 48 kHz | 1084×528 | 142 px each |
In the FFmpeg 6.1.1 source code, the left and right legend width is set by (log10(sampling rate) + 1) × 25. At 44.1 kHz, this is 141. If you want a fixed overall width, subtract this width when choosing s, or use legend=0. The image at the top of this article uses s=400x400 and came out at 682×528.
According to the source code, the axis labels on the legend appear every 80 px horizontally and every 40 px vertically. Whether the numbers land on round values depends on the size. In the image at the top, the 10-second audio was drawn 400 px wide, so 80 px equals 2 seconds, and 0 to 10000 Hz was drawn in 400 px height, so 40 px equals 1000 Hz. The labels therefore read "2.00s" and "1000.00". When I used 518 px for the width, the labels were uneven values such as "1.54s" and "3.09s".
Vertically, rows are evenly spaced from 0 Hz to the upper limit
If you specify nothing, the vertical axis runs from 0 Hz at the bottom to half the sampling rate at the top (22050 Hz at 44.1 kHz). The values in between are evenly spaced, so pitch is proportional to row position.
To check this, I looked at an s=800x512, legend=0 image. For each chosen time column, I found the brightest row. The results are below.
| Time and sound | Calculated position (from bottom) | Actual position (from bottom) |
|---|---|---|
| 1.5 s, left 1000 Hz | row 23.2 | row 23 |
| 1.5 s, right 3000 Hz | row 69.7 | row 70 |
| 3.75 s, sweep (2075 Hz) | row 48.2 | row 48 |
| 4.5 s, sweep (4050 Hz) | row 94.0 | row 94 |
| 5.25 s, sweep (6025 Hz) | row 139.9 | row 140 |
| 7.0 s, 440 Hz | row 10.2 | row 10 |
The calculated position is "frequency ÷ 22050 × 512". Every value matched within one row.
In the source code, when the spectrogram is vertical, the FFT size used for the frequency calculation is twice the height. At a height of 512 px, one row corresponds to about 43 Hz (22050 ÷ 512).
start and stop draw only the frequency range you want
For audio with no sound at high frequencies, the upper part of the image stays black. The audio used in this test has no sound above 8000 Hz. Without options, the upper part of the image above 8000 Hz (about 64% of the height) was 97% black pixels, not counting the vertical lines at the section boundaries. Setting stop to the upper frequency limit and start to the lower limit draws only that range across the full height of the image. With stop=8000 at a height of 400 px, the 1000 Hz tone appeared at rows 49 to 50 from the bottom (calculated as row 50), and the 440 Hz tone at rows 21 to 23 (calculated as row 22).
With start=500:stop=8000, the 1000 Hz tone was at rows 26 to 27 from the bottom, which matches the calculated 26.7 from "(1000 − 500) ÷ 7500 × 400". When start and stop had the same value, FFmpeg printed Stop frequency should be greater than start. and no image was created.
With stop, a height that is a multiple of 16 drew correctly
When I used stop, depending on the height, lines were drawn at the wrong positions and the background turned a reddish color. At heights of 296 and 300, background pixels away from the lines were (236, 0, 4) and (204, 0, 35). At height 304 they were black (0, 0, 0). The table shows where the 1000 Hz line landed for stop=10000 at various heights. If correct, it should be at "height × 0.1" rows.
| Height | Calculated position (from bottom) | Actual position (from bottom) | Background |
|---|---|---|---|
| 288 | row 28.8 | rows 28 to 29 | Black |
| 296 | row 29.6 | spread across rows 2 to 62 | Colored |
| 300 | row 30.0 | row 46 | Colored |
| 304 | row 30.4 | rows 30 to 31 | Black |
| 360 | row 36.0 | row 68 | Colored |
| 400 | row 40.0 | row 40 | Black |
| 408 | row 40.8 | rows 72 to 73 | Colored |
Among the heights I tried, 288, 304, 320, 384, 400, and 512 drew correctly. All of them are multiples of 16. Without stop, the 1000 Hz line was at the correct position (row 14 from the bottom) even at height 300.
This result changed with the CPU's features. When I disabled AVX-512 with -cpuflags, an FFmpeg option for turning off CPU features that the official documentation describes as intended for testing, heights 296, 312, and 360 also drew correctly (300 still did not). With -cpuflags 0, which disables all features, every height I tried (296, 300, 312, and 360) drew correctly. In my test environment, which has AVX-512, using stop drew correctly as long as the height was a multiple of 16.
For a wider view of low sounds, use fscale=log
With fscale=log, the vertical axis becomes logarithmic, and more of the image height is used for low frequencies. At a height of 400 px, the positions of the left-channel lines changed as follows.
| Sound | Position with fscale=lin (default), from bottom |
Position with fscale=log, from bottom |
|---|---|---|
| 440 Hz | row 8 | rows 173 to 174 |
| 1000 Hz | row 18 | row 222 |
| 4050 Hz | rows 73 to 74 | row 303 |
| 6025 Hz | row 109 | row 326 |

A sweep that rises at a constant rate becomes a curve with fscale=log. Use fscale=log to see differences between low frequencies in detail. Use the default linear scale, with its evenly spaced grid, if you want to read frequency differences from the axis.
Quiet sounds are visible when the brightness scale is log
The default brightness scale (scale) is log. With lin, the difference between loud and quiet sounds is shown directly as a difference in brightness, and quiet sounds became almost invisible. Below are the brightness values (converted to grayscale, where 0 is black and 255 is white) for the column at 7.0 seconds.
| scale | 440 Hz (amplitude 0.5) | 5000 Hz (amplitude 0.005) |
|---|---|---|
log (default) |
244 | 71 |
sqrt |
255 | 37 |
lin |
255 | 5 |

When looking for noise or hum that is much quieter than the main sound, keep the default log. The default legend's color bar has dBFS labels (decibels relative to the loudest possible sound, which is 0) running from 0 to −120. The 120 comes from the default value of drange.
For stereo, draw both channels together or separately
By default (mode=combined), both channels are drawn overlaid in a single chart. In this case, a sound present in only one channel appears darker. The 1000 Hz line on the left only was (255, 255, 160), a bright yellow, when only the left channel was drawn. When drawn in stereo, it became the muted (127, 129, 80). The sweep section, where both channels have the same sound, was (255, 255, 162) either way.
To compare the channels, there are two options.

mode=separate draws each channel in its own panel. In my test, the upper panel was the right channel (the 3000 Hz line) and the lower panel was the left channel (the 1000 Hz line). The upper panel is not the left channel, so be careful not to misread it. The height is divided by the number of panels, so with s=800x512, each panel is 256 px tall. To make each panel the same height as in the combined view, double the height in s.
color=channel overlays the channels with a different color for each. The left-only 1000 Hz was pink (255, 27, 118), the right-only 3000 Hz was green (0, 210, 116), and the parts where both channels have the same sound were near-white (235, 235, 233).
You can also export directly from video files
Video files can be used as input. Specifying an MP4 with video (H.264) and audio (AAC) to -i exported the audio spectrogram.
ffmpeg -i video.mp4 -lavfi showspectrumpic=s=800x400 -frames:v 1 -update 1 spectrogram.png
Long audio uses a lot of memory
Reading the source code, showspectrumpic stores all the audio it receives and draws only after it has received the last of it. I measured three runs for each length, using stereo AAC (128 kbps, 44.1 kHz) pink noise.
| Audio length | Size | Processing time | Peak memory use |
|---|---|---|---|
| 1 minute | 800×400 | 0.55 to 0.59 s | about 100 MB |
| 10 minutes | 800×400 | 4.03 to 4.18 s | about 490 MB |
| 60 minutes | 800×400 | 24.01 to 25.27 s | about 2.6 GB |
| 60 minutes | default (4096×2048) | 16.39 to 16.82 s | about 2.7 GB |
For 60 minutes of audio, using 800×400 was not faster than the default size; it actually took longer.
When I read the same 60-minute audio through astats, a filter that outputs audio statistics, to the end, the peak memory use was about 53 MB. The memory use exceeds 2 GB for 60 minutes of audio because showspectrumpic stores the audio.
If you first downmix to mono with aformat before drawing, memory use for the 60-minute audio dropped to about 880 MB, and processing time was 16.50 to 16.99 s.
ffmpeg -i long.m4a -lavfi aformat=channel_layouts=mono,showspectrumpic=s=800x400 -frames:v 1 -update 1 spectrogram.png
If you do not need to compare left and right, and you are processing long audio on a server with limited memory, use this form to reduce memory use.




