notes/Convert Video to Animated GIF-Sa6R3nGH.sh
#https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality

#http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

###########FFMPEG OPTION###############
#Generate a palette:
ffmpeg -y -ss 30 -t 3 -i input.flv -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png


#Output the GIF using the palette:

ffmpeg -ss 30 -t 3 -i input.flv -i palette.png -filter_complex "fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif

#########Image Magick Option###########
#Export frames:

mkdir frames
ffmpeg -i input -vf scale=320:-1:flags=lanczos,fps=10 frames/ffout%03d.png

#Then use convert (or gm convert if you prefer GraphicsMagick) to make your animated GIF:
convert -loop 0 frames/ffout*.png output.gif

syntax highlighted by Code2HTML, v. 0.9.1