AI Video Editing Flows

FFmpeg video to GIF: palettegen, frame rate and width

To make a good GIF with FFmpeg, build a palette from the clip first. On our 5 second test clip the plain command gave a 1.15 MB GIF with 97 colours in the frame we checked. The palette method gave 3.73 MB and 255 colours. Below are the commands, the measured sizes, and what changes with frame rate and width.

What to choose

A GIF frame is limited to a small palette. A plain conversion picks the colours for you. The palette method first looks at your clip, builds a palette for it, then converts. It is one command with an extra step inside, and on our clip it gave a larger file with more colours per frame.

MethodFile sizeFramesDurationColours in the frame at 3.0 s
Plain (default palette)1.15 MB605.000 s97
palettegen and paletteuse3.73 MB605.000 s255

For comparison, the same source frame at 480 px wide has 30508 distinct colours before it goes into a GIF. We also measured PSNR between the GIF frame and that source frame: 21.84 dB for the plain GIF and 35.78 dB for the palette GIF. Higher is closer to the source.

Convert with a custom palette

The clip was cut from second 10 of the source for 5 s. The filter does four things: fps sets the frame rate, scale sets the width and keeps the aspect ratio, split makes two copies of the stream, palettegen reads one copy and writes a palette, and paletteuse applies it to the other copy.

Palette method: 3.73 MB, 60 frames
ffmpeg -ss 10 -t 5 -i tos.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" pal12_480.gif
Plain method for comparison: 1.15 MB, 60 frames
ffmpeg -ss 10 -t 5 -i tos.mp4 -vf "fps=12,scale=480:-1:flags=lanczos" plain.gif

Our 8 fps file reported a duration of 5.01 s, while the 12 fps file reported 5.0 s. Check the duration of your own GIF if timing matters.

Frame rate and width

File size follows the number of frames and the pixel count. All rows use the palette method on the same 5 s clip.

SettingCommand (filter start)File sizeFramesSize in pixels
8 fps, 480 widefps=8,scale=480:-12.61 MB40480x200
12 fps, 480 widefps=12,scale=480:-13.73 MB60480x200
20 fps, 480 widefps=20,scale=480:-15.80 MB100480x200
12 fps, 320 widefps=12,scale=320:-11.71 MB60320x134

Going from 12 to 20 fps added 40 frames and took the file from 3.73 MB to 5.80 MB. Dropping to 320 wide gave 1.71 MB. PSNR for the 20 fps and 320 wide files was 35.78 dB and 35.87 dB, close to the 12 fps figure of 35.78 dB. We did not compare the 8 fps file with the source frame, so no PSNR is given for it.

Dither and file size

paletteuse can dither, which spreads colour error as a pattern. The first row below is paletteuse with its default settings. The second adds a Bayer pattern. Bayer gave a smaller file here.

Bayer dither: 2.71 MB
ffmpeg -ss 10 -t 5 -i tos.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" bayer12_480.gif
DitherFile sizePSNR against the source frame
Default3.73 MB35.78 dB
Bayer, scale 52.71 MB37.53 dB

PSNR does not show what the eye sees, and a dither pattern can show on flat areas, so look at the result before you pick one. We measured file size and PSNR only and did not judge the look.

GIF to MP4, and images to GIF

A GIF is a large way to store video. Converting our palette GIF back to MP4 gave 191.6 kB with 60 frames, against 3.73 MB for the GIF. The scale filter keeps both sides even, which H.264 needs.

GIF to MP4: 191.6 kB
ffmpeg -i pal12_480.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" gif_as.mp4

To build a GIF from still images, first we wrote 24 numbered PNG files, then read them at 12 frames per second.

Write numbered frames
ffmpeg -ss 10 -t 2 -i tos.mp4 -vf "fps=12,scale=480:-1:flags=lanczos" fr_%02d.png
Images to GIF: 24 frames, 1.44 MB
ffmpeg -framerate 12 -i fr_%02d.png -vf "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" seq.gif

Method and limits

All commands ran on FFmpeg 8.1.2 (a full Windows build) on a Windows 11 laptop, Ryzen 7 7735U, CPU only, on 2026-11-06. We added -y and -threads 4 to every run; they are left out of the commands shown. In quoted FFmpeg messages the hex address after @ changes on every run, so we replaced it with ...

tos.mp4 is a copy of Tears of Steel clip tos_a_0020_60s.mp4 (60 s, 1280x534, 24 fps), (c) Blender Foundation, licensed CC-BY 3.0. We credit it here as the licence asks. Colours were counted in decoded frame number 36 of the 12 fps files (3.0 s), and the matching frame of each other file.

Limits: one run of each command, so the sizes and times are single measurements and not averages. Times were taken on a laptop that was doing other work. Results depend on the input file and the FFmpeg version, so check yours. We checked one frame per file for colours and PSNR, and we did not review the GIFs by eye.

Related: FFmpeg for video editors, FFmpeg extract frames and turn images into video, FFmpeg compress video: CRF and presets, measured with VMAF, FFmpeg trim video: accurate cuts by time and FFmpeg command builder.

Page checked on Nov 4, 2026.