Animated GIF images have become an art of its own, with funny scenes and memes flooding the internet. Animated GIFs are also useful to us geeks, for example for showing interactive terminal output. When there is not enough content to warrant entire video but you still need moving picture, animated GIF is what you need. So today we will show five ways you can create GIFs using open source Linux software.
1) Using gtk-recordmydesktop
Lets first install the software we need. We need above mentioned screencasting software, and we also need imagemagick and mplayer. So let's install them.
# apt-get install imagemagick mplayer gtk-recordmydesktop
Next we use recordmyDesktop software to record terminal window while we execute some command. We will keep it simple so we will just ping google. When that is recorded, and file is saved in
~/Videos/mygif.ogv we move to next step. First cd into videos directory.
# cd Videos/ mkdir img_mygif
Then we need to dissemble the video to frames
# mplayer -ao null mygif.ogv -vo jpeg:outdir=/home/miki/Videos/img_mygif
It will play video and start the process, at the end we will have images in the ~/Videos/img_mygif directory. You can enter that directory and delete some of the images on start and the end in order to make GIF shorter.
To create actual GIF, we need to use imagemagick to fuse images back together in GIF format. It is very resourced intensive task, it can throw down to knees even most powerful ones of machines, so we will use options to limit usage of resources, which will in turn make the process take more time. But at least you wont end up with completely unresponsive system. The options for limiting are -limit memory 1 -limit map 1
# convert -limit memory 1 -limit map 1 /home/miki/Videos/img_mygif/* final.gif
In order to make the gif smaller we can optimize it
# convert -limit memory 1 -limit map 1 final.gif -fuzz 10% -layers Optimize final_optimzed.gif
And here is the final GIF:
2) Using Byzanz to make GIF
Byzanz is another software which can greatly simplify the creation of the GIFs. First, of course we need to install Byzanz.
# apt install byzanz
We can right away start by making a GIF
# byzanz-record --duration=5 --x=500 --width=250 --height=100 newgif.gif
The most challenging part here is actually fitting the right area of the screen to capture. The options width and height need to be tested several times before you get the right alignment. Here are the options and the syntax of byzanz-record command:
miki@miki-X550JK:~$ byzanz-record --help Usage: byzanz-record [OPTION...] record your current desktop session Help Options: -?, --help Show help options --help-all Show all help options --help-gtk Show GTK+ Options Application Options: -d, --duration=SECS Duration of animation (default: 10 seconds) -e, --exec=COMMAND Command to execute and time --delay=SECS Delay before start (default: 1 second) -c, --cursor Record mouse cursor -a, --audio Record audio -x, --x=PIXEL X coordinate of rectangle to record -y, --y=PIXEL Y coordinate of rectangle to record -w, --width=PIXEL Width of recording rectangle -h, --height=PIXEL Height of recording rectangle -v, --verbose Be verbose --display=DISPLAY X display to use
3) Using peek to make GIF
Peek is a great piece of software that enables you to quickly record GIFs by selecting and recording a piece of screen. To get peek
# wget https://github.com/phw/peek/releases/download/v0.7.2/peek-0.7.2-Linux.deb
To get dependencies
# apt install libsdl1.2debian ffmpeg
Installing the package
# dpkg -i peek-0.7.2-Linux.deb
And start the peek
It will give you frame like this
You can easily use this frame to get a piece of the screen and record GIF there. For example, I will Peek into terminal again.
4) Using Gifine to make animated GIF
Gifine is a free GTK based application tool that can be used to record your desktop screen and create animated gifs or video.
Before starting, you will need to install FFmpeg to your system. By default, FFmpeg is not available in Ubuntu default repository. So you will need to add PPA for FFmpeg. You can do this with the following command:
# add-apt-repository ppa:jonathonf/ffmpeg-3
Next, update your system with the following command:
# apt-get update -y
Finally, install FFmpeg with the following command:
# apt-get install ffmpeg -y
Next, you will also need to install other dependencies required by Gifine. You can install all of them with the following command:
# apt-get install gcc make build-essential graphicsmagick gifsicle luarocks -y
Next, you will need to download and compile XrectSel to your system. It's basically an application that tells you the geometry of a rectangular screen region which you have selected by dragging the mouse/pointer. You can download it with the following command:
# wget https://github.com/lolilolicon/xrectsel/archive/master.zip
Once the download is finished, extract the downloaded file with the following command:
# unzip master.zip
Next, change the directory to the extracted directory and install XrectSel with the following command:
# cd xrectsel-master ./bootstrap ./configure --prefix /usr make make DESTDIR="$directory" install
Finally, install Gifine with the following command:
# luarocks install --server=http://luarocks.org/dev gifine
Once Gifine is installed, you can launch it with the following command:
You should see the Gifine application UI in the following image:
Next, click on the Record rectangle button, then select a rectangular area on your screen which you want to record. Recording is now begins and you should see the following image:
Once you are done with the recording, click on the Stop recording button. You should see the following image:
Next, click on the Save GIF or Save MP4 button to save the recording as a GIF or a video.
5) Using Gifcurry to make GIF
Gifcurry is a Haskell based program to create animated GIFs, overlaid with optional text, from video files. It includes both the GUI gifcurry_gui and the command line gifcurry_cli. It uses ffmpeg and imagemagic to process video and convert to GIF. Gifcurry offers the features below
- Convert video to gif:
- Add text to gif
- Choose start time
- Set duration
- Set gif width
- Adjust Quality
- Upload to Imgur or Giphy
Run the command below to install it
# add-apt-repository ppa:kirillshkrogalev/ffmpeg-next This PPA provides backported release ffmpeg for current releases Ubuntu (Trusty, Utopic, etc.) More info: https://launchpad.net/~kirillshkrogalev/+archive/ubuntu/ffmpeg-next Press [ENTER] to continue or ctrl-c to cancel adding it
now install ffmpeg and imagemagic
# apt-get install ffmpeg imagemagick Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: i965-va-driver libaacs0 libass5 libavcodec-ffmpeg56 libavdevice-ffmpeg56 libavfilter-ffmpeg5.
Now download gifcurry
# wget https://github.com/lettier/gifcurry/releases/download/220.127.116.11/gifcurry-linux-18.104.22.168.tar.gz --2017-09-08 01:39:58-- https://github.com/lettier/gifcurry/releases/download/22.214.171.124/gifcurry-linux-126.96.36.199.tar.gz
Unzip the compressed archive and access to the folder
# tar -xvf gifcurry-linux-188.8.131.52.tar.gz gifcurry-linux-184.108.40.206/ gifcurry-linux-220.127.116.11/share/
# cd gifcurry-linux-18.104.22.168/bin
You can check the content as below:
# ls -l total 6956 -rwxr-xr-x 1 ubuntu users 3406376 Nov 17 2016 gifcurry_cli -rwxr-xr-x 1 ubuntu users 3714352 Nov 17 2016 gifcurry_gui
You can see the gifcurry for GUI and CLI. You can show the help of the gifcurry GUI as below to see how to use the parameters
# ./gifcurry_cli -? Gifcurry 22.214.171.124 (C) 2016 David Lettier gifcurry_cli [OPTIONS] Common flags: -i --inputfile=FILE The input video file path and name. -o --outputfile=ITEM The output GIF file path and name. -s --starttime=NUM The start time (in seconds) for the first frame. -d --durationtime=NUM How long the GIF lasts (in seconds) from the start time. -w --widthsize=INT How wide the GIF needs to be. Height will scale to match. -q --qualitypercent=NUM Ranges from 0.0 to 100.0. -f --fontchoice=ITEM Choose your desired font for the top and bottom text. -t --toptext=ITEM The text you wish to add to the top of the GIF. -b --bottomtext=ITEM The text you wish to add to the bottom of the GIF. -? --help Display help message -V --version Print version information --numeric-version Print just the version number
Now we can create our gif in command line. In the command above, we will try to create a gif animation of a video that we have. The default video takes 13 secondes but for our gif animation, we will set less time
# ./gifcurry_cli -i ~/funny-cat.mkv -o /home/ubuntu/funnycat.gif -s 138.00 -d 8.00 -w 250 -q 30 -f Roboto -b FunnyCat _____ _ __ | __ (_)/ _| | | \/_| |_ ___ _ _ _ __ _ __ _ _ | | __| | _/ __| | | | '__| '__| | | | | |_\ \ | || (__| |_| | | | | | |_| | \____/_|_| \___|\__,_|_| |_| \__, | __/ | |___/ Gifcurry (C) 2016 David Lettier. https://www.lettier.com/ Input file: /root/funny-cat.mkv Output file: /home/ubuntu/funnycat.gif Start second: 138.000 Duration: 8.000 seconds GIF width: 250px Quality: 30.0% Font Choice: Roboto Top text: Bottom text: FunnyCat Writing temporary frames to... ./frames22605 Font matched: default Writing your GIF to... /home/ubuntu/funnycat.gif Done.
There we have five ways to make animated GIFs on Linux and this guide show the case of an Ubuntu system. The first method, using imagemagick, is also useful if you have video from the internet, not made by yourself. Second and third method rely on you making the screencast on your computer. The fourth can be usefull to do a gif of your desktop or a video of your choice as the fifth tool. You can pick methods based on your needs and preference, and generally, all the methods can get you the same result. This was all for today's article, thank you for reading.