Reducing GIF Dithering with ffmpeg
TODO: collapasable, copyable, download, etc
I have a screen recording. I process it with ffmpeg -i ~/Desktop/Screen\ Recording\ 2023-10-11\ at\ 1.26.59\ PM.mov -pix_fmt rgb8 -r 10 output.gif && gifsicle -O3 output.gif -o output.gif
The gif has grey dots all over it in a regular grid. Why is that?The grey dots you're seeing in the GIF are likely a result of dithering. Dithering is a technique used to simulate colors or tones in an image that aren't present in the limited color palette of the format. The GIF format supports a maximum of 256 colors, so when you convert a video (which likely has thousands or millions of colors) to a GIF, some form of dithering is often applied to approximate the colors of the original video.
The -pix_fmt rgb8
flag in your ffmpeg
command is instructing ffmpeg
to output an 8-bit RGB palette, which further reduces the number of colors available in the resulting image, making the dithering more pronounced.
If you want to reduce the appearance of these dots:
- Increase the palette size: Instead of using
-pix_fmt rgb8
, use the palettegen and paletteuse filters in ffmpeg to generate and use a custom 256-color palette. This can help to create a GIF that better matches the original video's colors:
ffmpeg -i ~/Desktop/Screen\ Recording\ 2023-10-11\ at\ 1.26.59\ PM.mov -vf "fps=10,palettegen" palette.png
ffmpeg -i ~/Desktop/Screen\ Recording\ 2023-10-11\ at\ 1.26.59\ PM.mov -i palette.png -filter_complex "fps=10,paletteuse" output.gif
- Reduce dithering: If you still notice unwanted dithering, you can modify the
paletteuse
filter to reduce it. For example:
-filter_complex "fps=10,paletteuse=dither=none"
However, reducing dithering can sometimes result in banding or color inaccuracies.
- Post-process with gifsicle: Continue using
gifsicle
as you've been doing to optimize the GIF size:
gifsicle -O3 output.gif -o output_optimized.gif
Remember, GIFs inherently have limitations with color due to their restricted palette. While these steps can help improve the appearance, some loss of color fidelity is expected when converting full-color videos to GIF format.How can I get ffmpeg to not ask if palette.png already exists Y/N to overwrite. it should just always overwriteYou can use the -y
flag with ffmpeg
to automatically overwrite the output file if it already exists without prompting for confirmation.
For example:
ffmpeg -y -i ~/Desktop/Screen\ Recording\ 2023-10-11\ at\ 1.26.59\ PM.mov -vf "fps=10,palettegen" palette.png
By adding -y
before specifying the input file (or anywhere in the command), ffmpeg
will overwrite palette.png
(or any other output file) without asking.
Related Chats
Convert MOV to GIF 0.352
FPCX Stabilization Settings Tutorial 0.329
Git LFS Issue Resolution 0.328
Stencil Vector Graphic Program 0.312
Volume Rendering in Graphics 0.275
Hero Sprite Sheets Created 0.245
Grey Paladin Giant Art 0.236
Prevent Event Propagation with JS 0.224
RGB to Hex Conversion 0.224