Single Command to Enable/Disable GIF Infinite Loop in Your Linux

Got an animated GIF, and want to disable or enable infinite loop playback? Or, you want to configure how many times it should play?

This is super easy to do the trick in most Linux (Ubuntu, Debian, Fedora, Arch, and most others) via a single FFmpeg command.

Install FFmpeg

The FFmpeg library is so popular, that it’s mostly already installed in your system.

Just in case you don’t have it, run one of the commands below to get it:

  • For Debian, Ubuntu, Linux Mint, etc., use command to install it:
    sudo apt install ffmpeg
  • Arch/Manjaro user can get it via command:
    sudo pacman -S ffmpeg
  • And for Fedora based systems, run:
    sudo dnf install ffmpeg

Single FFmpeg command to configure GIF loop count

Before running the command, you may need to first open a terminal window and navigate to the folder that contains your GIF file.

This can be done either by right-clicking in that folder and select “Open in Terminal”:

Or use cd command to do the navigation (for example, navigate to user’s Downloads folder):

cd ~/Downloads

Then, use the single command to configure GIF loop count:

ffmpeg -i inputfile.gif -loop 0 -vcodec copy outputfile.gif

In this command:

  • -i means input. You need to specify the original GIF file (inputfile.gif in command) right after it.
  • -loop 0 says loop infinitely! You can change the number 0 accordingly:
    • -1 means only once.
    • 0 means infinitely.
    • 1 – 2 times.
    • 2 – 3 times.
    • 3 – 4 times.
  • -vcodec copy – means copy the video codec directly. Without this option, FFmpeg will do decode and then encode processes, which takes more time and may cause large output file size.
  • outputfile.gif – means output file, you can set whatever as you want.

For example, I have a “overview.gif” file stored in Downloads folder (see the previous screenshot). Run the command below will convert it into “overview-loop2.gif” which only play twice (as the top feature image does):

That’s it. Enjoy!

Merilyn Ne
Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.