Sometime you need a GIF for your README or presentations but those online convertors are very annoying filled to the brim with ads and limited options. So in order to get rid of this I tried ffmpeg to convert video files into GIFs. You must have ffmpeg installed in your device to proceed, download link here.

The following command will do the trick:

ffmpeg -ss [start_time] -t [duration/no_of_seconds_from_start] 
-i [input].[extension(.mp4)/(.mkv)] 
-vf "fps=10,scale=[width]:[height]:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" 
-loop 0 [output].[extension(.mp4)/(.mkv)]

Summary

Let me break it down for you:

The -ss and -t flag give the start time and how many seconds to take from that time for the GIF from the video, if the video is already clipped/you need the whole video just remove these flags.

The -i is to specify the input file.

The -vf flag specifies the properties of the GIF to be made you can change fps of GIF here (higher fps=larger file size) also in scale= you can provide the width and height of the GIF. If you need to change one dimension only/keep aspect ratio same as of video just provide one of the height/width and other as -1 the latter will taken care of by ffmpeg. The last argument of this flag is generating the pallete for the GIF which I would suggest to keep as is.

You can also give the flag -loop 0 for the GIF to loop the animation. And then just provide the output file name.

And there you learned how to make GIFs in command line today! Cheers!

Example

The following command converts a video starting from 00:00:10s till the next 4 seconds with 10 fps and 200px width keeping the aspect ratio same.

ffmpeg -ss 10 -t 4 -i Bojji_OP.mp4 
-vf "fps=10,scale=200:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"
-loop 0 bojji_200.gif

demo