How to Create Animated GIF from Video Using Terminal on Linux
GIF is a format moving image files. This format is quite popular in the internet world, especially on social media. Facebook, Tumblr, Flickr, Google + and other social media support this file format content, especially on Twitter, this file format is very popular and widely used.
If you are asking how to make an animated GIF, you can create this file using an application or service on line which can make GIFs. Apart from using the app or using the service on lineon Linux you can create animated GIFs only from Terminal.
With only two apps or tools simple on Linux, you can create an animated GIF from a video that you want. application or tools which we will use are FFmpeg and ImageMagick.
What you need is a video that is suitable as an animated GIF, it would be better if the video is a funny video.
How to Make GIF from Video Using FFmpeg and ImageMagick in Linux Terminal
First you must have FFmpeg, make sure you have FFmpeg installed on Linux. Or if not you can install FFmpeg first.
On Debian, Ubuntu and derivatives distributions, FFmpeg is available on official repository. So if you are using that distro, you can install FFmpeg using the following command:
sudo apt-get update sudo apt-get installl ffmpeg
Wait for the installation process to complete and succeed.
If you already have FFmpeg on Linux. You can convert videos into GIF format. To make it easy, move the video file that you want to turn into an animated GIF to the Home folder, and give it a short name so it’s easy to remember.
Extract and split the video file into frames videos and save them in animated GIF image format by using the following command. Make sure you use the file format output becomes “out%04d.gif”, so that frames they will be correctly named and stored in the order they were.
ffmpeg -t “durasi” -ss “posisi mulai dari hh:mm:ss” -i “input_video” out%04d.gif.
Replace the word “duration” in the command with the length of the GIF you want to create in seconds. Replace the word “position starting from hh:mm:ss” with the start time of the video you want to convert into a GIF in the format “hours:minutes:seconds”.
Replace the word “input_video” in the command with the name of the video that you want to turn into a GIF. For example, if you want to create a 5 second animated GIF from a video called “babi.mp4”.
The part of the video that will be made into a GIF starts from the 12th second and will end the next 5 seconds, because the desired duration is 5 seconds. Then the command to be entered is as follows:
ffmpeg -t 5 -ss 00:00:12 -i bayi.mp4 out%04d.gif
Once done, you will see the lists frames which will be made into a GIF named “out[d+].gif” in Terminal.
Next we have to combine frames to become an animated GIF file using ImageMagick.
Make sure your computer has ImageMagick installed. Usually ImageMagick already exists or is installed manually default on Linux. But if it’s not already installed, you can install ImageMagick first.
On Debian, Ubuntu and their derivatives, ImageMagick is usually available on official repository. So you can install ImageMagick by using the following command:
sudo apt-get update sudo apt-get install imagemagick
Wait for the installation process to complete and succeed.
If ImageMagick is already installed. Convert or combine frames into an animated GIF file using the following command:
convert -delay “frame”x”fps” -loop 0 out*gif "nama_file_output"
The word “-delay” in the command determines the speed of the animation. This word signifies the amount frames in 1 second which will be made into GiF. The word “-loop 0” denotes an unlimited number of repetitions of the animated GIF.
Usually when you see an animated GIF, the animation will keep repeating itself when it’s at the end of the animation. If you want the animation in a limited number of repetitions, you can replace the number “0” with the number of repetitions you want.
For example if you want to create an animated GIF with 60 frames differ by 1 second (60 fps) and the animation will loop indefinitely. So the command is as follows:
convert -delay 1x60 -loop 0 out*.gif animasi_bayi.gif
The word “animasi_bayi.gif” in the command is the file name output which will be a GIF.
Wait for the conversion and merging process frames until it’s finished and becomes an animated GIF. Then check the Home folder, you will see an animated GIF named “animasi_babi.gif”
You have successfully created an animated GIF from a video.
Then you can reduce the size of the animated GIF file that you have created so that it becomes smaller by compressing or slightly reducing the quality of the animated image. This is optional.
We will return to using tools ImageMagick with features optimizer GIFs. Enter the following command to reduce the animation file size.
convert -layers Optimize animasi_beruang.gif beruang_kecil.gif
The word “bear_small.gif” is the file name resulting from the reduction in the size of the animation. You can rename the file with another name as you wish.
Wait for the compression process to finish. Then check your Home folder again, there will be a new animated GIF file in a smaller size called “babi_small.gif” or according to the name you entered in the command.