How to Get Higher Quality Gifs with Python and FFMPEG
One of the things that lets a gif down is obvious dithering. We can mitigate this by pre-processing the palette, then using it in the subsequent gif to find the best match rather than overplay our dither hand.
Take our previous Python code and tweak it thus:
# output the result
os.system('ffmpeg -framerate 24 -i frames/%03d.png -c:v ffv1 -r 24 -y out.avi')
os.system('ffmpeg -y -i out.avi -vf palettegen palette.png')
os.system('ffmpeg -y -i out.avi -i palette.png -lavfi paletteuse out.gif')
What we do here is take the AVI and extract a palette, which will look like this:
Then we use that palette to generate the gif.
You can see the difference here is subtle unless you zoom in:
But! you might find the higher quality palette version is smaller in file size!
![](https://steemitimages.com/640x0/https://cdn.steemitimages.com/0x0/https://cdn.discordapp.com/attachments/383256479056134146/446022370608676864/makerhacks.png)
Really helpfull tutorial
Thanks
Thanks for sharing
Oh! very nice tips. Thanks