12

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

1 Answer 1

19

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.

2
  • 1
    This worked great, thank you! Commented Jul 16, 2019 at 1:45
  • My source gif was 1.4MB at 512x512, after using this script the 320x320 is 3MB. HOW!! Commented Mar 14 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .