< Back

Creating a GIF from a Sequence of PNGs


Question:

When I use FFmpeg1 to convert a bunch of pngs to a GIF, it produces an ugly GIF (see the example script below and Figure 1). How do you use FFmpeg to convert a series of .png images to a high quality GIF in Windows?

Example script (creates an ugly GIF):

   ffmpeg.exe -r 20 -i HighQual_%6d.png -s:v 2152x1914 -f GIF ffmpeg_HighQual.gif

 

Figure 1: This is a snap-shot of an unsightly GIF generated with the code above.

 

Solution:
Both FFmpeg and ImageMagick convert2 can create a GIF from a sequence of PNGs.

Method 1: Using FFmpeg
After placing both ffmpeg.exe (found in the Tecplot’s bin directory) and the sequence of PNGs you want to convert into a folder, navigate to that folder in your command line. And complete the following steps:

1a)   Create a palette of colors3 from one of your PNG files:

       ffmpeg -i HighQual_000024.png -vf palettegen palette.png

1b)   Using this palette (palette.png), convert the sequence of PNG images to a GIF:

       ffmpeg -r 15 -i HighQual_%6d.png -i palette.png -filter_complex "paletteuse" ffmpeg_generated.gif

You should now have a GIF in your folder called ffmpeg_generated.gif (or whatever you named it). See Figure 2 below for an example:

Figure 2: This high quality GIF was generated with FFmpeg using the two-step process above.

 

 

Method 2: Using ImageMagick convert
Follow these steps to access the convert.exe and produce a convert-generated GIF:

2a)   Download ImageMagick for Windows and install, but make sure to add legacy utilities (e.g. convert) while going through the installation wizard (see Figure 3).

Figure 3: Make sure to include “Install legacy utilities (e.g. convert).”

2b)   Place both convert.exe (found here for example: C:\Program Files\ImageMagick-7.0.8-Q16) and the sequence of PNGs you want to convert into a folder, and navigate to that folder in your command line.

2c)   Enter this code into your command line:

       convert.exe HighQual_*.png convert_generated.gif

 

A GIF, such as convert_generated.gif, should now be present in your folder. The convert generated GIF is similar to Figure 2.

 

 

Notes:
1 See Use FFmpeg to create videos from PNGs for more information.
2 The authoritative ImageMagick license can be found at http://www.imagemagick.org/script/license.php.
3 This is an alteration of a procedure found here.