0

I had this question answered that helped me merge two mp4 videos with alphamerge with the following command to an .mov file

ffmpeg -i video.mp4 -i mask.mp4 -filter_complex "[1][0]scale2ref[mask][main];[main][mask]alphamerge" -c:v qtrle output.mov

Now, I was wondering how I would change this for the output of a gif. When I tried

ffmpeg -i word.mp4 -i word.matte.mp4 -filter_complex "[1][0]scale2ref[mask][main];[main][mask]alphamerge" -c:v qtrle output.gif

I got this error

[swscaler @ 0x5601daaa4d40] No accelerated colorspace conversion found from yuv420p to argb.
[gif @ 0x5601d9ad2d00] GIF muxer supports only a single video GIF stream.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

I'm using ffmpeg 4.2.4

1
1
+50

Combining your command with the command from How do I convert a video to GIF using ffmpeg, with reasonable quality?:

ffmpeg -i word.mp4 -i word.matte.mp4 -filter_complex "[1][0]scale2ref[mask][main];[main][mask]alphamerge,fps=10,scale=320:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

Note the removal of -c:v qtrle. You can't put QuickTime Animation RLE video into GIF output.

If you want a background photo combine command from How to overlay with ffmpeg?

ffmpeg -i word.mp4 -i word.matte.mp4 -i background.jpg -filter_complex "[1][0]scale2ref[mask][main];[main][mask]alphamerge[fg];[2][fg]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:format=auto,fps=10,scale=320:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
2
  • Thanks again @llogan! I'll award the bounty once it lets me. Once again I'm unsure it's out of the scope of this question, but would I have to do a third input to change the background to a image/color instead of making it transparent, say a background of paris or something
    – nadermx
    May 15 at 20:56
  • @nadermx See updated answer
    – llogan
    May 15 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.