Specify background color when converting GIF to MP4 with ffmpeg

2

I have an animated GIF with transparency. I want to convert it to an MP4. When I do so, the transparent regions are filled with fully opaque white. I'd like to specify the color used to replace these transparent pixels. How would I do this?

  • Please don't recommend using convert of gifsicle which requires a separate operation. Speed is a priority. The solution needs to use only ffmpeg. Thanks.

okor

Posted 2017-04-04T20:28:32.490

Reputation: 123

Answers

2

Use

ffmpeg -f lavfi -i color=RRGGBB -i in.gif
  -filter_complex "[0][1]scale2ref[bg][gif];[bg]setsar=1[bg];[bg][gif]overlay=shortest=1"
out.mp4

A canvas is created, which is black, if color (in hex) is not specified. In the filter complex. it is resized to be the same size as the GIF, and then the GIF is overlaid on it. Within the GIF's transparent areas. the background shows through.

Gyan

Posted 2017-04-04T20:28:32.490

Reputation: 21 016