Reputation: 2040
I'm trying to add an overlay to an animated GIF with FFMpeg.
It works, but the quality is pretty dismal. Basically, I'm unable to use the palette that I generate, and that leads to a lot of dither. The main GIF (meaning, not the overlay) is also very low resolution.
I would also like to apply opacity to the watermark (and at one point that worked, too), but that's a plus.
This is what I have:
ffmpeg -v error -i image.gif -vf 'palettegen' palette.png -y;
ffmpeg -v error -i image.gif -i watermark.gif -i palette.png -filter_complex '[1:v]scale=80:30, [0:v]overlay=(main_w-overlay_w) - main_h/30:(main_h-overlay_h) - main_h/30, paletteuse' -an image-watermark.gif -y
At one point I was able to use the palette for the main GIF, so its quality improved. However, the watermark looked pretty bad. It's pretty obvious that I have to do the overlay, and then the palette, so that the palette include the colors present in the watermark. However, I have no idea how to do that.
Can someone point me in the right direction?
Upvotes: 0
Views: 1272
Reputation: 93018
You have to generate the palette for the same visual content that you wish to encode to GIF.
ffmpeg -v error -i image.gif -i watermark.gif -filter_complex '[1:v]scale=80:30[wm];[0:v][wm]overlay=(main_w-overlay_w) - main_h/30:(main_h-overlay_h) - main_h/30, palettegen' palette.png -y;
ffmpeg -v error -i image.gif -i watermark.gif -i palette.png -filter_complex '[1:v]scale=80:30[wm];[0:v][wm]overlay=(main_w-overlay_w) - main_h/30:(main_h-overlay_h) - main_h/30[vid];[vid][2]paletteuse' -an image-watermark.gif -y
(I've kept your existing syntax, although it's preferable to label all input and output pads and not rely on automatic input pickup.)
Upvotes: 1