The Linux OS can do many things for you at no cost. Only thing is you should know what tool(an open source tool?) you should use. Creating gif files from a video file is not an exception for this. When I tried to explain about watch command which requires some video for that. But I felt youtube is blocked in most of the IT companies. So I came with a plan to convert the video file to a GIF image so that I can bypass firewalls. This post is all about it on how I achieved it.

Install ImageMagick and other tools in Linux ubuntu

Image magic will not work out of the box; we have to install Mplayer and gtk-recordmydesktop for that.

apt-get install imagemagick mplayer gtk-recordmydesktop

Output:

root@linuxnix:/home/surendra/Signed_Doc# apt-get install imagemagick mplayer gtk-recordmydesktop
Reading package lists... Done
Building dependency tree
Reading state information... Done
gtk-recordmydesktop is already the newest version (0.3.8-4.1ubuntu1).
mplayer is already the newest version (2:1.2.1-1ubuntu1).
The following packages were automatically installed and are no longer required:
calibre-bin fonts-mathjax libbonoboui2-0 libbonoboui2-common libchm1
libclass-data-inheritable-perl libclass-method-modifiers-perl
The following NEW packages will be installed:
imagemagick
The following packages will be upgraded:
imagemagick-6.q16
1 upgraded, 1 newly installed, 0 to remove and 110 not upgraded.
Need to get 432 kB of archives.
After this operation, 151 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 imagemagick-6.q16 amd64 8:6.8.9.9-7ubuntu5.5 [388 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 imagemagick amd64 8:6.8.9.9-7ubuntu5.5 [44.9 kB]
Fetched 432 kB in 2s (159 kB/s)
(Reading database ... 498133 files and directories currently installed.)
Preparing to unpack .../imagemagick-6.q16_8%3a6.8.9.9-7ubuntu5.5_amd64.deb ...
Unpacking imagemagick-6.q16 (8:6.8.9.9-7ubuntu5.5) over (8:6.8.9.9-7ubuntu5.4) ...
Selecting previously unselected package imagemagick.
Preparing to unpack .../imagemagick_8%3a6.8.9.9-7ubuntu5.5_amd64.deb ...
Unpacking imagemagick (8:6.8.9.9-7ubuntu5.5) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
lay) in auto mode
update-alternatives: using /usr/bin/montage-im6 to provide /usr/bin/montage (montage) in auto mode
update-alternatives: using /usr/bin/mogrify-im6 to provide /usr/bin/mogrify (mogrify) in auto mode

These are the required software which just got installed: ImageMagick, MPlayer and Desktop Recorder.

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.

Convert video into jpeg image in Linux

The Mplayer is useful for converting video to jpeg images frame by frame.

mplayer -ao null <video file name> -vo jpeg:outdir=output

Example:

cd /home/surendra/videos

mplayer -ao null abc.ogv -vo jpeg:outdir=output

-ao is to specify audio output drivers to be used. Here we used null which indicates use none for converting.

-vo is to determine video output as jpeg image files and save these files output folder.

Now our directory where jpegs are stored is “output.”

Use ImageMagick to convert the screenshots into animated gifs

convert output/* output.gif

We can optimize the screenshots using convert command

convert output.gif -fuzz 10% -layers Optimize optimised.gif

Hope this is helpful to you people. Please comment on this.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.