Twitter abuses all media file uploads, each type in its own way. If we want to upload a good looking animation loop from some low-color, high-detail generative art, we have to game their system's mechanisms.
-
don't upload a video file, they will re-encode it into absolute 💩
-
create a GIF, which they will auto-convert into a video file 😱
-
The frames of the GIF will be resized to an even-sized width using an extremely naive algorithm. Your GIF should be an even size (1000, 2000, &c) so the multiple of this size to avoid janky artifacts caused by floating point division.
-
The GIF format is also terrible, so you have to game that too. In particular, if we create a GIF using ffmpeg's defaults we end up with one small divergent color palette per frame. This leads to weird inconsistencies and artifacts between frames and blows up the file size. To avoid this, choose a representative frame from your animation and generate a palette from that:
ffmpeg -i frame-030.png -vf palettegen -y palette.png
And then generate your GIF using that palette:
ffmpeg -framerate 20 -pattern_type glob -i 'frame-*.png' -i palette.png -filter_complex "paletteuse" art.gif
If the GIF looks right, but is slightly too large to upload, you can give gifsicle
a try:
gifsicle -O art.gif > art-optimized.gif
... et Voilà! Your beautiful art is as Twitter ready as it can be. Vaya con dios!
Thanks for this! I didn't know about the 508px output. That's great info - I'll try switching my GIFs over to 1016px.
I got really frustrated using ffmpeg and imagemagick (I avoid the command line if at all possible). I found ScreenToGif where you can input pngs then modify individiaul frame delays, add transitions, copy/paste/reverse frames etc. Then it has it's own encoding options or has ffmpeg built in if that's your preference. It's like ezgif, but lives on your desktop, so it runs a lot better for me.
gifisicle also works great for me. I'll go with -O3 --lossy=30 (or more) if I'm really having trouble getting the size down.