[Libav-user] Convert frame data from AV_PIX_FMT_BGR24 to AV_PIX_FMT_PAL8

wm4 nfxjfg at googlemail.com
Mon Apr 21 20:55:44 CEST 2014


On Sun, 20 Apr 2014 14:13:41 +0100
"Chris Garry" <cgarry at sweeneydesign.co.uk> wrote:

> My application needs to convert frame data from its internal format of BGR24
> to palletized 8-bit data so that it can generate a colour animated GIF.  Is
> there a function in the FFmpeg libraries to do this?
> 
> I tried creating an SwsContext and using sws_scale(), but an output format
> of AV_PIX_FMT_PAL8 is not by sws_getCachedContext().

Yes, it doesn't, because not only is it not trivial, it also requires
finding an optimal palette by looking at all frames that are going to
be in the gif.

Rather than using ffmpeg to generate gif, using something else would
probably be better. This "something else" would probably use RGBA
directly.

But I don't know what can produce good gifs. Maybe imagemagick? (You'd
feed it a bunch of PNGs.)

> I understand that creating a suitable optimised palette for a frame is
> non-trivial but would have thought that this must have been done many times
> before.  Therefore I just wanted to check it if a function to do this
> already exists before I bite the bullet and write my own version.

I don't know of anything. But note that the FFmpeg gif encoder actually
can take 8-bit RGB (i.e. all 3 components in a single byte), but that's
going to look ugly.

> Thanks and regards,
> Chris Garry


More information about the Libav-user mailing list