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

Don Moir donmoir at comcast.net
Mon Apr 21 22:41:36 CEST 2014

----- Original Message ----- 
From: "wm4" <nfxjfg at googlemail.com>
To: <libav-user at ffmpeg.org>
Sent: Monday, April 21, 2014 2:55 PM
Subject: Re: [Libav-user] Convert frame data from AV_PIX_FMT_BGR24 to AV_PIX_FMT_PAL8

> 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.

Each frame in gif89 format can have its own palette so does not require looking at all frames. Not trivial but not complex either.

> 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
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

More information about the Libav-user mailing list