ffmpeg -i video.mp4 -r 15 -vf "scale=512:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -ss 00:00:03 -to 00:00:09 video.gifFrom https://askubuntu.com/questions/648603/how-to-create-an-animated-gif-from-mp4-video-via-command-line
-i video.mp4is the input video.-r 15is the FPS, 10 or 15 is usually fine, more would be too big of a file.-vf "scale=512:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuseoptimizes the palette of colors of the gif and sets the scale (512px here, use 768 if you need it a bit bigger, but be aware of the final size of the gif if you do so, 512 is a good tradeoff).-ss 00:00:03.00is the start time of the video.-to 00:00:09.00is the end time of the video. I recommend gifs to be no longer than 10 seconds and not bigger than 10-15MB, but depends on the case.video.gif(the last parameter) will be the name of the gif.
Your system needs ffmpeg installed (sudo apt-get install ffmpeg).