Since the onset of GIF or Graphical Interchange Format back in 1987, the internet fell in love with this technological approach of making an image exist in a state of continuous motion.
With this brief fact, Gif’s popularity on business and social platforms is becoming impossible to ignore, and for good reasons. This article guide will explore their importance and how to effortlessly create them via the FFmpeg tool.
What is FFmpeg?
FFmpeg tool is primarily defined as a video converter. However, in terms of its functionalities, it does more than just convert video files based on set parameters.
FFmpeg is a complete cross-platform solution that can also convert and stream video and audio files. However, this article guide is more interested in how it can convert video files to GIF files.
Installing FFmpeg in Linux
It can be installed on various Linux OS distributions from one of the following commands. Make sure you have sudoer/root user privileges before running the FFmpeg installation command on your Linux OS command-line.
Install FFmpeg in RHEL
On RHEL-based distributions like RHEL, CentOS Stream, Rocky Linux, and AlmaLinux:
$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm $ sudo dnf upgrade $ sudo subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms" $ sudo yum update $ sudo yum install snapd $ sudo systemctl enable --now snapd.socket $ sudo ln -s /var/lib/snapd/snap /snap $ sudo snap install ffmpeg
On Fedora Linux distribution:
$ sudo dnf makecache $ sudo dnf install ffmpeg-free
On Debian distributions like Ubuntu and Linux Mint:
$ sudo apt update && sudo apt upgrade -y $ sudo apt install ffmpeg
On Arch Linux and Manjaro:
$ sudo pacman -Syu $ sudo pacman -S ffmpeg
On OpenSUSE Leap:
$ sudo zypper refresh $ sudo zypper install ffmpeg
On OpenSUSE Tumbleweed:
$ sudo zypper refresh $ sudo zypper install ffmpeg-4
How to Convert Videos to GIFs in Linux
The simplest FFmpeg video-to-GIF conversion command syntax is:
$ ffmpeg -i video_file.file_extension gif_file_name.gif
We can implement the above command in the following manner; assuming we are converting a video file called rock.mp4 to a GIF file called rock.gif.
$ ffmpeg -i rock.mp4 rock.gif
The above approach produces a large GIF file size we might not need.
$ ls -l rock.gif
You can resize the resulting GIF file to a manageable size using the scale command option and prevent every frame of the input video file from being converted using the fps (frames per second) command option as demonstrated below:
$ ffmpeg -ss 30 -t 5 -i rock.mp4 -vf fps=10,scale=450:-1 rock.gif
-ss command option skips the first 30 seconds of the video file and the
-t command option records the next 5 seconds to be converted to a GIF file.
The resulting GIF file size is also significantly smaller than expected.
$ ls -l rock.gif
You might also like to read the following related articles:
- How to Find Video Resolution (Width and Height) in Linux
- How to Check Video Files Formats in Linux
- How to Create a Video From Images in Linux
We can now convert videos to GIFs using FFmpeg on a Linux OS environment.