Okay, so let's make a post about this since I'm pretty sure I'll forget about it later on.
I'll just put commands line since it's for my reference anyway~
1st step: Cut the video to the scene where you want it to be GIF'ed
ffmpeg -i input.mkv -an -ss hh:mm:ss.000 -to hh:mm:ss.000 -qscale 0 output.mkv
* -an : remove audio stream
* -ss : video start time
* -to : video end time
* -qscale 0 : I always use this command to retain the original quality of the source used on the output.
2nd step: Filter out color palette to be used when creating the GIF
ffmpeg -i input.mkv -vf palettegen palette.png
3rd step: Resize the resolution of output from 1st step
*Simple rescaling
ffmpeg -i input.mkv -vf scale=320:240 output.mkv
or
*Keep aspect ratio
ffmpeg -i input.mkv -vf scale=320:-1 output.mkv /or -2
4th step: Creating the GIF
ffmpeg -i input.mkv -i palette.png -lavfi paletteuse output.gif
* -i input.mkv : take the video source from 3rd step.
* -i palette.png : take the filter from 2nd step
Tadaa!~~
Video source credit: TienWu