How to Get Higher Quality Gifs with Python and FFMPEG

in #programming6 years ago (edited)

Screenshot from 2018-05-25 15-20-32.png

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:

Screenshot from 2018-05-25 15-24-32.png

Then we use that palette to generate the gif.

You can see the difference here is subtle unless you zoom in:

original.gif
out.gif

But! you might find the higher quality palette version is smaller in file size!

Screenshot from 2018-05-25 15-32-12.png


Sort:  

Really helpfull tutorial
Thanks

Oh! very nice tips. Thanks

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.030
BTC 59391.37
ETH 2525.88
USDT 1.00
SBD 2.47