Home Linux Commandline Tips How to Convert Videos to GIFs Using FFmpeg

How to Convert Videos to GIFs Using FFmpeg

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
Convert Videos to GIFs
Convert Videos to GIFs

The above approach produces a large GIF file size we might not need.

$ ls -l rock.gif
Large GIF File
Large GIF File

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

The -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.

Resize GIF File
Resize GIF File

The resulting GIF file size is also significantly smaller than expected.

$ ls -l rock.gif
Check GIF File Size
Check GIF File Size

You might also like to read the following related articles:

We can now convert videos to GIFs using FFmpeg on a Linux OS environment.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.