This command works nice with some GIF but with some others return a error:
ffmpeg -f gif -f lavfi -i color=FFFFFF -i animated.gif -y
-filter_complex "[0][1]scale2ref[bg][gif];[bg]setsar=1[bg];[bg][gif]overlay=shortest=1"
-pix_fmt yuv420p -movflags frag_keyframe+empty_moov -movflags +faststart
-crf 20 -b:v 500k -f mp4 animated.mp4
Error:
[libx264 @ 0x55e79dc7e3c0] height not divisible by 2 (1400x933)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0
- maybe incorrect parameters such as bit_rate, rate, width or height
Some help to fix it maintaining the background color functionality?
Use
ffmpeg -f gif -f lavfi -i color=FFFFFF -i animated.gif -y
-filter_complex "[0][1]scale2ref[bg][gif];[bg]setsar=1[bg];[bg][gif]overlay=shortest=1,scale=w='2*trunc(iw/2)':h='2*trunc(ih/2)'"
-pix_fmt yuv420p -movflags frag_keyframe+empty_moov -movflags +faststart
-crf 20 -b:v 500k -f mp4 animated.mp4
For yuv420p
input, x264 requires that the width and height both be even numbers.