I have a list of inputs (a combination of gifs and png) that I am trying to overlay and create a new gif. I was able to achieve this using this command and the following result:
_ffmpeg
.withOptions([
'-ss 1',
'-i animated.gif',
'-i base-goldfish.png',
'-i eyes-wink.gif',
'-i mouth-pleased.png',
'-i palette.png',
'-filter_complex [0][1]overlay[i1];[i1][2]overlay[i2];[i2][3]overlay',
'-f gif',
])
.output('./res.gif')
.on('start', console.log)
.on('error', console.error)
.run();
As you can see, the result is very grainy. I have then generated a palette.png
with the hopes of improving the quality.
However I struggle to find the syntax to use complex_filter
to combine an overlay and a palette. Does someone know?
ps1: I also tried to generate an mp4 (with good quality) and then convert it to .gif, but the result is identically bad.
ps2: I used gifski to convert the mp4 to gif with good success. But i'd like to avoid introducing a new dependency.
Adapt How do I convert a video to GIF using ffmpeg, with reasonable quality?
ffmpeg -ss 1 -i animated.gif -i base-goldfish.png -i eyes-wink.gif -i mouth-pleased.png -filter_complex "[0][1]overlay=format=auto[i1];[i1][2]overlay=format=auto[i2];[i2][3]overlay=format=auto,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
format=auto
was added to each overlay filter to improve quality of the overlay.