Node.js FFMPEG Project to Convert MP4 Videos to Optimized GIF Animation With Text Using gifify & Imagemagick Library in Javascript




Convert any video file to an optimized animated GIF. Either in its full length or only a part of it.

Demo time

This screencast was recorded with lolilolicon/FFcast then converted to a GIF with:


  • command line interface
  • programmatic JavaScript (Node.JSstream interface
  • unix friendly, supports stdin & stdout
  • optimized! uses pornel/giflossy to generate light GIFS
  • lots of options: movie speed, fps, colors, compression, resize, reverse, from & to, subtitles
  • no temp files used, everything happens in memory
  • fast! Extracting a 5-second GIF from the middle of a 2-hour movie takes less than 20 seconds


Before using gifify, please install:

You can also use the gifify Docker image which comes with everything installed.


Command line usage

Programmatic usage

See the example.

You can also pass a readable stream to gifify(stream, opts).

Readable stream input performance

Gifify supports streams both on command line (cat movie.mp4 | gifify -o out.gif) and in the programmatic API (gifify(readableStream, opts).pipe(writableStream)).

While it’s super useful in some cases, if you have the file on disk already, you better do gifify movie.mp4 -o out.gif or gifify(filePath, opts).pipe(writableStream).

Why? Because piping 3.4GB when you want to cut from 40:20 to 40:22 still takes a loooooot of time and does not give you any performance benefit.

FFmpeg has to read from 0GB -> $START_BYTE_40:20 and discards it. But everything flows in your memory.

When using direct file input from command line, we pass the -i filename option to FFmpeg and then it’s super fast!

Be careful when |piping.

Adding some text

You can burn some simple text into your GIF:



You can burn subtitles into your GIF, it’s that easy:

You must create new subtitles files, the timecodes for the complete film will not work for a five seconds GIF.

Create subtitles using aegisub and augment the font size for a great effect!

Here’s the 22.ass from the previous command, created with aegisub:

Result extracting a GIF from 22 Jump Street:

GIF Performance



Leave a Reply