First install this:
sudo apt-get install imagemagick mplayer gtk-recordmydesktop
On a terminal:
mplayer -ao null <video file name> -vo jpeg:outdir=output
Use ImageMagick to convert the screenshots into an animated gifs.
convert output/* output.gif
you can optimize the screenshots this way:
convert output.gif -fuzz 10% -layers Optimize optimised.gif