Fastest way to create animated gifs from mp4
For first you should create a set of jpg images with maximum quality using mplayer
and jpeg
option sets to 100 (jpeg:quality=100).
mplayer -ao null -ss 0:00:00 -endpos 10 mts.flv -vo jpeg:outdir=jpeg_dir:quality=100
Next, you need to convert generated jpgs to gifs using convert
, just type:
for i in ./jpeg_dir/*.jpg; do convert "$i" "${i%.jpg}.gif"; done
And finally using gifsicle
create animated gif:
gifsicle --delay=10 --loop ./jpeg_dir/*.gif > anim.gif
Also, you can use optimization level flag --optimize=03
. It can be helpful to reduce file size:
gifsicle --delay=10 --optimize=03 --loop *.gif > anim.gif
Additionally, you can manipulate with number of colors --colors num
of current palette and --color-method method
to determine most appropriate palette.
As for me most appropriate method is median-cut
median-cut is the median cut algorithm described by Heckbert
Also, I try to manipulate with described flags and found most useful options to achievebetter quality of generated gif-image:
gifsicle --delay=3 --optimize=03 --color-method median-cut --loop *.gif > anim.gif
Be accurate with --delay=NUM
to correspond animation speed . This param depends on FPS of original video.
It could improve passing from uncompressed images, like .ppm, for example with mplayer the command line would be:
mplayer -benchmark -noframedrop -nosound -vf format=rgb24 -vo pnm *.avi -osdlevel 0
These will save the jpg compress/uncompress cycle.
It would also help working with a Solid State Drive.
Use "animate" program from imagemagick package after splitting video to images. Like thisanimate ./*.jpg. Then just save opened merged in ImageMagick program images as gif. But it may be large/ Then nеed to optimize and resize(better to do it with mplayer first scale=240:180).