Skip to main content

MP4 to GIF Animations

·110 words·1 min

I’m converting three explanimations from mp4s to gifs. Initially I used ffmpeg to export images which I then planned to assemble into a gif with gifsicle. But ffmpeg can do it directly.

From Stack Overflow:

ffmpeg -ss 30 -t 3 -i input.mp4 \
    -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
    -loop 0 output.gif
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam \
    -f image2pipe - | \
    convert -delay 10 - -loop 0 -layers optimize output.gif

Tweaking the first for my own needs:

ffmpeg -i anomalistic_month.mp4 \
    -vf "fps=3,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
    -loop 0 anim.gif

After playing with it a bit, it looks like I’m waaay better off just embedding the mp4 instead of tryna use GIFs.