0

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.

Gregory
  • 557
  • 6
  • 17

2 Answers2

1

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.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • What does `split[s0][s1]` represent? – Gregory Oct 04 '21 at 17:56
  • @Gregory [How do I convert a video to GIF using ffmpeg, with reasonable quality?](https://superuser.com/a/556031) says "split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette". `[s0][s1]` are arbitrary names given to the outputs from the split filter. – llogan Oct 04 '21 at 18:28
0

This is the command I ended up with:

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=stats_mode=single[p];[s1][p]paletteuse=new=1 output.gif
Gregory
  • 557
  • 6
  • 17