Problem and Introduction¶
I wanted to include some gif screencasts in my posts and started looking for a neat solution. I can live with a command line or gui solution as long as it works reasonable well and is in the Debian Jessie (stable) repositories.
Interesting Links¶
- https://scottlinux.com/2011/07/31/create-animated-gif-in-linux-from-command-line/
- http://askubuntu.com/questions/107726/how-to-create-animated-gif-images-of-a-screencast#107735
- http://recordmydesktop.sourceforge.net/rug/app_a.php
- https://davidwalsh.name/convert-video-gif
- http://www.imagemagick.org/Usage/video/
- http://www.linux.org/threads/animated-screen-capture-with-byzanz.7715/
Solutions¶
From the links above I managed to extract two different solutions:
byzanz
- Debian package ‘byzanz’. This is the easiest and best solution I could find. Set the duration of the recording with the -d
option. Replace ‘foo.gif’ with your preferred filename:
byzanz-record -d 20 foo.gif
or
- record a video with ‘recordmydesktop’ (see code example 0), ‘gtk-recordmydesktop’ or use an existing video
- With ‘avconv’ you can directly convert to gif (see code example 1) and skip step 3. Another aproach is to extract stillimages with ‘mplayer’ (see code example 2) or with ‘avconv’ (see code example 3).
- convert to ‘gif’ with imagemagick (see code example 4)
Code example 0 (record a video; replace foobar.ogv with your filename):
recordmydesktop -o foobar.ogv
Code example 1 (direct video to gif conversion; replace foobar.ogv with your filename):
avconv -i foobar.ogv -pix_fmt rgb24 foobar.gif
Code example 2 (extraction of still images; replace foobar.ogv with your filename):
mplayer -ao null foobar.ogv -vo jpeg:outdir=output
Code example 3 (extraction of still images; replace foobar.ogv with your filename):
avconv -i foobar.ogv -r 15 output/image-%3d.png
Code example 4 (convert stillimages to gif):
convert output/* -layers Optimize output.gif
This solution produces usable gifs with small filesizes. The still image extraction and conversion to gif takes a lot of computing.
If you have any questions, suggestions, thoughts and comments please feel free to email me.
License of this blog post:
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.