Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Tuesday, August 22, 2017 at 22:03


If you wonder how to produce GIF animation from any video tutorial, the answer is ffmpeg. Learn it once and use it forever. This short article explains 2 steps to produce GIF in small size from MP4 and WEBM videos. I hope by reading this article, anyone uses Kazam to record screen can produce GIF tutorials easily & quickly!

Subscribe to UbuntuBuzz Telegram Channel to get article updates directly.

MP4 to GIF


Assume your video is video.mp4:

First, create a PNG pallete:
ffmpeg -y -i video.mp4 -vf palettegen palette.png

Second, produce GIF using the pallete:
ffmpeg -y -i video.mp4 -i palette.png -filter_complex paletteuse -r 10 animation.gif

The result is a file named animation.gif. I get 1.7MB GIF file out of 300KB MP4. This is 10x smaller compared to 17MB GIF I get without using pallete.



WEBM to GIF


Assume your video is video.webm:

First, like above, create a PNG pallete:
ffmpeg -y -i video.webm -vf palettegen palette.png

Second, produce GIF using the pallete:
ffmpeg -y -i video.webm -i palette.png -filter_complex paletteuse -r 10 animation.gif

Here's the result.


References


Thanks to Mulvya from StackOverflow.