[FFmpeg-devel] Color quantization for GIF

Clément Bœsch u at pkh.me
Sun Jan 25 19:55:17 CET 2015


Hi folks,

I've been trying to improve GIF support even more recently. This is the result:
http://lucy.pkh.me/gone-nutty-current.gifhttp://lucy.pkh.me/gone-nutty.gif

How it works in 2 lines:
  ffmpeg -i in -vf palettegen -y palette.png
  ffmpeg -i in -i palette.png -lavfi paletteuse out.gif

The +:
 • 1 single optimal palette for the whole stream
 • no high memory requirement (works in 2 pass)
 • obviously better quality

The -:
 • indecent size because the dithering is way too noisy, and as a result the
   transparency mechanism of GIF is inefficient (or worse: -gifflags -transdiff
   to disable it often makes the output smaller)

If someone has a suggestion for the dithering, please stand up.

Small summary:

 Changelog                   |   1 +
 doc/filters.texi            |  55 +++++++
 libavcodec/gif.c            |  53 +++++-
 libavfilter/Makefile        |   2 +
 libavfilter/allfilters.c    |   2 +
 libavfilter/version.h       |   4 +-
 libavfilter/vf_palettegen.c | 382 ++++++++++++++++++++++++++++++++++++++++++++
 libavfilter/vf_paletteuse.c | 282 ++++++++++++++++++++++++++++++++
 libavformat/gif.c           |  84 ++++++----
 tests/ref/fate/gifenc-pal8  | 346 +++++++++++++++++++--------------------
 10 files changed, 1001 insertions(+), 210 deletions(-)

> [PATCH 1/6] avformat/gif: simplify gif_image_write_header() prototype
> [PATCH 2/6] avformat/gif: use first packet palette as global for PAL8
> [PATCH 3/6] avcodec/gif: support crop and transparency with PAL8

So these 3 commits are basically to make the GIF support properly PAL8 (one
single global palette for the format, and the transparency/crop optimizations
.encoder side).

> [PATCH 4/6] avfilter: add palettegen filter
> [PATCH 5/6] avfilter: add paletteuse filter

The 2 main filters, derived from Paul Heckbert paper (1982). It's using a 5-bit
component resolution for simplicity, and there are many room for improvement
(look for TODO/XXX/FIXME).

No FATE test yet, but should be easy to add (no floating point).

> [PATCH 6/6] avfilter: bump minor and Changelog document the new

(bumping only once at the end, I hope no one mind)


More information about the ffmpeg-devel mailing list