Convert GIFs to Video in MP4 or WEBM Format

APRIL 11, 2020

Many platforms—among which are Google PageSpeed or ImgIX—recommend serving animated assets over video formats as opposed to GIF animations. GIFs are heavy, and data transfer can be reduced somewhere between two and twenty times (when using the webm format) and, on top of that, videos can be streamed.

From GIF to MP4

ffmpeg -i animation.gif animation.mp4

From GIF to webm

ffmpeg -i animation.gif -c vp9 -b:v 0 -crf 12 my-animation.webm
  • crf · The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn't technically lossless. The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate. Choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value. If it looks bad, choose a lower value.
  • b:v maximum bit rate allowed. Higher means better quality.