Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
how to make a nice GIF from png frames

Make sure ffmpeg is up-to-date:

brew update
brew upgrade ffmpeg

Convert a MOV into frames. Tweak the 2/1 if you want more or fewer frames.

mkdir frames
ffmpeg -i screen-recording.mov -r 2/1 frames/%03d.png

Optional: crop the frames to 600x400px using 824,690 as top/left

mkdir cropped
convert ??.png -crop 600x400+824+690 cropped/

Create the pallete.gif

ffmpeg -i cropped/%02d.png -vf palettegen palette.png

Aaaand create the GIF. The 6*PTS is added to slow down the GIF frames.

ffmpeg -v warning -i cropped/%02d.png -i palette.png  -lavfi "paletteuse,setpts=6*PTS" -y out.gif

Bonus tip: if you want the last frame to have a longer duration, just copy your last frame image a bunch of times and use new frame numbers as filename.

copy 20.png 21.png
copy 20.png 22.png
copy 20.png 23.png
copy 20.png 24.png

Sources: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

@varoon

This comment has been minimized.

Copy link

commented Apr 5, 2018

Hello,
How to Add Transparent of the GIF ?
The PNG images have transparency and the output GIF does not have transparent. Any fix ?

@kkevlar

This comment has been minimized.

Copy link

commented Aug 22, 2018

@samdivaio

This comment has been minimized.

Copy link

commented Nov 28, 2018

They do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.