ffmpeg
Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.
You haven't posted your mp4 sample, so I am using my own.
Plain conversion
ffmpeg -i sample.mkv -y sample.gif
Result 12M (Note: it won't be hosted foverer here):
Trickier conversion
According to this article.
filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif
The result has half resolution, looks better, but still 12M.
Let's try to trade quality for smallness
Reduce FPS to 15 and drop dithering
filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif
Result: 3.7M
Trying to fit in 2 MiB to attach here as a picture
12 FPS, 320x180, no dither, 1.8M
Windows way
You can also use FFmpeg from command line in Windows.
I haven't tried, but something like this should work:
set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif
I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.
Batch file
It is probably not convenient to manually edit and paste those commands every time one need to do the conversion. Here is a (untested) batch file:
set SOURCE=input.mp4
set DESTINATION=output.gif
set FPS=12
set SIZE=256x144
set DITHER=none
set F=fps=%FPS%,scale=%SIZE%:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -v warning -i %SOURCE% -vf %F%,palettegen -y palette.png
ffmpeg.exe -v warning -i %SOURCE% -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither="%DITHER% -y %DESTINATION%
pause
You can play with output size and FPS, as well as with dithering (may be numbers from 0 to 5 instead of none
).