Make your own Gif to Mp4 converter using ffmpeg and bash



Many social media sites, mostly Facebook... have fairly poor support for gifs. To get around this problem, you can convert gifs into mp4 video files, and they will autoplay etc. So this will be a super quick and easy tutorial on building your own command line tool for doing just that.

I'm going to use ffpmeg, the tool which allows the conversion of various different image and video formats, compressions and other useful features.

First up, I'm going to open my environment variables. In my case vim ~/.zshrc, because I'm using zsh but yours may be something like ~/.bash_profile or ~/.bashrc.

Now enter the following somewhere in your bash_profile.

g2v() {  
  ffmpeg -f gif -i $1 $2
}

Now hit source ~/.zshrc (or whatever your version is), to reload your bash configuration.

Before we can run this, however. You need to make sure you have ffmpeg installed. If you're a Mac user, that's brew install ffmpeg using Homebrew, of course.

Now run, g2v ~/path/to/your.gif ~/you/output/path.mp4 and you'll have an mp4 version of your gif waiting for you.