How do I resize an animated GIF and keep transparency?

1

I tried to resize an animated GIF with transparency, but it turned the background a solid white. How do I keep the transparency?

I read https://superuser.com/a/556031/130929 and tried

>set FILTERS=scale=320:-1:flags=lanczos
>ffmpeg -hide_banner -i logo.gif -vf "%FILTERS%,palettegen=stats_mode=diff" -y palette.png
>ffmpeg -hide_banner -i logo.gif -i palette.png -lavfi "%FILTERS% [x]; [x][1:v] paletteuse" logo-320.gif

I also tried -gifflags +transdiff but it didn't help as the blog post in the answer says it's the default anyways. I also tried without stats_mode=diff.

I also tried with a palette for each frame, but that only made the file bigger and didn't keep transparency.

>ffmpeg -hide_banner -i logo.gif -filter_complex "[0:v] scale=320:-1:flags=lanczos,split [a][b]; [a] palettegen=stats_mode=single [p]; [b][p] paletteuse=new=1" logo-320.gif

Chloe

Posted 2018-09-28T21:13:39.293

Reputation: 4 502

Answers

3

I upgraded from 3.4.1 to 4.0.2 and it worked. However, I got better results with

>ffmpeg -hide_banner -v warning -i logo.gif -filter_complex "[0:v] scale=320:-1:flags=lanczos,split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse" logo-320.gif

To avoid a white line artifact around the edge by adding palettegen=reserve_transparent=on:transparency_color=ffffff.

Chloe

Posted 2018-09-28T21:13:39.293

Reputation: 4 502

This worked great, thank you! – AveryFreeman – 2019-07-16T01:45:57.877