Convert video in mp4 or webm format to gif and optimize it

This is just a quick remark about playing around with videos into conversion.

Sometimes I make some video from my smartphone, and I want to share it, but in reduced size and without any sound.  Sometimes I do a desktop recording with Peek utility into gif directly, or with OBS into video format.

In all these cases I want to reduce the output size. Previously I have been using some web resources for a quick conversion, like this one – https://convertio.co/de/webm-gif/
But the last time I used it – it converted 7.9 MB  file into 113 MB gif. o_O

Video to Gif

So I decided to use some console utilities, as I sometimes do, to do a better job. For converting a video into gif I need ffmpeg utility. Simply install it
sudo apt install ffmpeg

and use

-r here is a frame rate. So I make it only 5 fps here. Can be 10 fps, results are a bit better. For my case 5 is enough.
After that, I have 31 MB gif file. Already much better than with this web conversion.

gif

After that, I want to optimize it with gifsicle.
Install sudo apt install gifsicle and use

What I do here is a reduction of colors palette from 256 colors to 16. It still looks pretty good for a gif. Also, I use the 3rd level of optimization. Described in a man page – http://www.lcdf.org/gifsicle/man.html. Color reduction method I have picked up by trying all 3 of them.

The result is the 18 MB gif which is playing for 2 minutes and still good enough. :D

via GIPHY