Creating a .gif from video with FFmpeg

Preparing video files for Discourse or FB can create challenges that delay or discourage sharing. Viewing high quality video not only requires an investment of time, but also consideration of loss due to compression. A .gif provides an economization of time and file size when used as a companion or substitute for a moment of video. A .gif might be preferred to a contact sheet when an observable would require a high frame rate and thus a larger contact sheet to be appreciated.

Once well understood, this process takes just a few minutes in post depending on the length of the source file.

This process utilizes the open source command line application FFmpeg. This application can be installed with Homebrew.


  • Will this work on my operating system?

From FFmpeg’s About:

FFmpeg is the leading multimedia framework, able to decode , encode , transcode , mux , demux , stream , filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.

  • Why does this tutorial crop to a 486x486 square on center?

The tutorial involves cropping to reduce file size. With hosting limitations in mind, the LZX Discourse has a 4mb file size limitation for .gifs. (This file size limitation is adjustable via the Discourse admin panel.)

Installing Homebrew and FFmpeg

If your operating system does not come with FFmpeg already installed, Linux, Windows 10, and Mac users can use Homebrew to install the application.

  • Homebrew can be installed with the following command:

/bin/bash -c "$(curl -fsSL"

  • FFmpeg can then be installed with the following command:

brew install ffmpeg

Creating a .gif from video with FFmpeg:

Once a video clip has been captured, it can be converted into a time lapse contact sheet in the following way:

  • Navigate in terminal to the folder containing your video file.

  • Use FFmpeg to crop your video file with user defined dimensions and offset:

ffmpeg -i -filter:v "crop=486:486:120:0"

  • Use FFmpeg to convert your cropped video file into a .gif:

ffmpeg -i -filter_complex "[0:v] fps=29,scale=iw:ih,split [a][b];[a] palettegen [p];[b][p] paletteuse" test.gif




another great job! I’m thrilled you used the palettegen version rather than the simpler one as this gives much more interesting results.