Skip to content
This script takes one or more animated GIF files as input and calculates their total durations.
Python
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md Move from PIL to Pillow. Mar 5, 2014
gifduration.py Bump Pillow, and Python 3 compatible stderr print. Apr 29, 2017
requirements.txt Update requirements.txt Apr 7, 2020

README.md

gifduration.py

This script takes one or more animated GIF files as input and calculates their total durations, returning zero for non-animated GIF files.

Requirements

Just run pip install -r requirements.txt, preferably outside a virtual environment if you want this script available system-wide.

Installation

Clone the repository to some appropriate folder and symlink gifduration.py into your PATH, for example:

ln -s ~/Code/gifduration/gifduration.py /usr/local/bin/gifduration

You may also have to make it executable:

chmod +x /usr/local/bin/gifduration

Usage

To get the duration of an animated GIF file, supply it as an argument:

gifduration atom-heart-mother.gif

This will return something like:

atom-heart-mother.gif:
Total duration: 2000 ms (2.00 seconds)
---

To also get the duration of each frame, use the --verbose (or -v) flag:

gifduration --verbose atom-heart-mother.gif

This will return something like:

atom-heart-mother.gif:
Frame 1: 30 ms (0.03 seconds)
Frame 2: 80 ms (0.08 seconds)
Frame 3: 30 ms (0.03 seconds)
[…]
Total duration: 2000 ms (2.00 seconds)
---

You can get the durations of several animated GIF files at once just by supplying all of them as arguments, for example:

gifduration atom-heart-mother.gif meddle.gif a-saucerful-of-secrets.gif

This will return something like:

atom-heart-mother.gif:
Total duration: 2000 ms (2.00 seconds)
---
meddle.gif:
Total duration: 100 ms (0.10 seconds)
---
a-saucerful-of-secrets.gif:
Total duration: 0 ms (0.00 seconds)
---

GIF files that are not animated will return a duration of zero. All other file types will return the message Not a GIF image.

Website

Go here for a simple web service carrying out pretty much the same thing.

You can’t perform that action at this time.