Convert GIF to MP4 for Instagram with FFmpeg

I made a script to account for Instagram’s idiosynchracies when converting a GIF to MP4 using FFmpeg. Here it is:

And now the details…

Doing a conversion of GIF to MP4 with ffmpeg seems like it should be simple enough:

But it isn’t! This can be insufficient in a couple of ways..

Problem 1: Video too short

instagram "video too short" notification

Solution: Use a filter to loop the input enough times to meet the 3s minimum time requirement

Problem 2: Wrong color encoding

Instagram blank video preview

Given a color encoding that it doesn’t understand, Instagram just kinda poops out

Solution: By default, my ffmpeg used yuv444p, which Instagram wasn’t happy with. I haven’t done an exhaustive survey of the color encoding that Instagram will accept, but here is one: yuv420p.

In addition, the conversion requires the file’s height to be divisible by 2, so we need yet another filter:


Now since so many GIFs that I wish to post to Instagram are actually shorter than 3s, I automated everything above and here is the first cut of the script. To see if I made any changes since actually using it “in production” check the version I’m currently using in my dotfiles.


To convert yup.gif to yup.mp4

To convert yup.gif into yup.insta.mp4

To create an insta.mp4 directly from a remote GIF

Happy giffing! 😀