from http://askubuntu.com/questions/107726/how-to-create-animated-gif-images-of-a-screencast
First install this:
sudo apt-get install imagemagick mplayer gtk-recordmydesktop
those are the required stuff, ImageMagick, MPlayer and Desktop Recorder. Then use Desktop Recorder to capture a portion of the screen/application to use as the screencast. After the Desktop Recorder has saved the recording into an OGV video, MPlayer will be used to capture JPEG screenshots, saving them into the 'output' directory.
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