GIFs are undoubtedly one of the most popular media formats shared on the internet. From tutorials to memes and beyond, people create and share GIFs for everything. But most of the time, these GIFs aren’t originally recorded as files with the “.gif” extension. Usually, a video is trimmed and a specific portion of the media is converted to a GIF.
On Linux, you can quickly create loopable GIFs from your videos using the terminal. And for those who aren’t too fond of the command line, there’s a graphical approach to achieve similar results as well. Here’s how you can convert a video to GIF on Linux.
Convert Videos to GIFs Using FFmpeg
FFmpeg is an open-source collection of libraries and modules related to media processing and handling. Using FFmpeg, you can generate a GIF file out of any video you want.
Install the ffmpeg Package
You need to install the ffmpeg package on your system to get started. On Debian-based distributions like Ubuntu, enter:
sudo apt install ffmpeg
On Arch Linux and Manjaro:
sudo pacman -S ffmpeg
To install FFmpeg on RPM-based distributions like Fedora, CentOS, and RHEL, first, add the RPM Fusion repository to your system:
sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
Then, install the ffmpeg package along with some development libraries by typing:
sudo dnf install ffmpeg ffmpeg-devel
Using FFmpeg to Create GIFs
Once you’ve installed the ffmpeg package, use the following command to convert a video to a high-quality GIF:
ffmpeg -i /path/to/video.mp4 output.gif
FFmpeg will convert the entire video to a GIF file. Therefore, if you want only a specific portion of the video as a GIF, make sure to trim the video beforehand.
For demonstration, here’s a GIF file created using the ffmpeg tool:
Create GIFs From Videos on Linux Using Gifcurry
Although converting an MP4 video to GIF is a fairly simple process and doesn’t require you to enter many commands, those of you repulsed by the idea of using the terminal can use a graphical tool instead. The name’s Gifcurry.
Gifcurry is an open-source graphical application powered by FFmpeg under the hood. As usual, you’ll have to install it on your system first. You can find the official Gifcurry AppImage on the GitHub Releases page.
Once downloaded, grant execute permissions to the AppImage file using the chmod command:
sudo chmod +x ~/Downloads/gifcurry-*.AppImage
Then, launch Gifcurry by double-clicking the AppImage using the graphical file manager installed on your system. Click on Open to start the tool.
During the first launch, you might get a few warnings related to uninstalled dependencies and libraries. While Gifcurry will continue to work without those packages, you should install them using the package manager on your distro to unlock the full potential of the tool.
To begin, select a video file and click Open. Gifcurry will display a preview window on the right and on the left, you’ll notice different options related to video processing. You can select only a part of the video using the slider and timestamp fields on the bottom-right section. Feel free to modify the resolution, duration, and size of the video, or add text over the video before converting it to a GIF.
Once done, click on the File option from the left sidebar to proceed. Browse the location where you want to store the output file and select GIF. Then, finally, click Save to store the output GIF file.
Here’s the GIF generated using Gifcurry:
Alternatively, you can also use Gifcurry from the command line. But to do that, you’ll have to install Gifcurry on your system and not launch it using the AppImage file. You can find more information on installing Gifcurry on its official GitHub page.
Since Gifcurry is based on FFmpeg, their command syntax is very similar. Here’s the command to convert a video file to a GIF using Gifcurry CLI:
gifcurry_cli -i /path/to/video.mp4 -o output.gif
Creating GIFs From Videos Made Easy on Linux
The Linux terminal is a powerful tool to add to your arsenal. Learning how to use it will open new gates and opportunities for you, whether you’re a casual Linux user or a professional system administrator.
Converting videos to GIFs is just the tip of the iceberg. You can do a lot more using the Linux command line. A few prominent examples include video and audio processing, system management, kernel development, etc. The extensive real-world applications of the terminal are the reasons why Linux users fancy the command line so much.