5

There are many software for converting videos to animated GIF but I want to know which has least file size for the output of a same video with MP4 and with same frame rate, pixel size.

I'm using Windows 7.

Assume you have a MP4 file and you want to convert it to a GIF file. For example, a 14 seconds MP4 file with 2.53 Mb size. If I use 200×350 pixels and 4 frame per seconds then with "Any GIF Animator" the output has 1.5 Mb size but the quality is so awful. If I just increase frame rate to 30 frames per second then the output is over 700 Mb!

Is there any software that convert a video to GIF with good quality but low size? If not which software gives the best output with respect to quality and size?

8
+50

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):

sample.gif

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.

sample.d.gif

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

sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

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).

  • 1
    Maybe try to avoid full paths like C:\FFMPEG. Copy both ffmpeg.exe and zz123.mp4 into C:\FFMPEG then cd /D into C:\FFMPEG and use simpler file name. – Vi. Apr 13 '16 at 17:51
  • 1
    Also here should be end of the second command and start of the third: -y palette.png ffmpeg.exe. palette.png is the last argument of second command and ffmpeg.exe is the beginning on the third command. Is there a tiny picture palette.png in C:\FFMPEG\bin already? – Vi. Apr 13 '16 at 17:52
  • 1
    After success, you can create a bat file for doing the conversion again simpler. – Vi. Apr 13 '16 at 17:53
  • 1
    You may also want to edit the F line: for high quality mode, try set F=fps=25,scale=512x288:sws_dither=ed:sws_flags=lanczos (essentially both filters no-op), for more compact mode, try set F=fps=12,scale=256x144:sws_dither=ed:sws_flags=lanczos. It is based on video size and FPS on that screenshot. – Vi. Apr 13 '16 at 18:11
  • 1
    So, is the problem resolved? If you create that batch file in FFMPEG/bin directory, you'll have a "conversion bench" for doing it again with other files. FFmpeg can do many things with video: it can also extract part of video, do picture-in-picture, crop frame, adjust brightness contrast and so on. – Vi. Apr 13 '16 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.