Niket Singh
Niket Singh

Reputation: 199

Overlay a Transparent Video on Image and export into GIF using FFmpeg in android

I am overlaying an alpha video on an image and making the black portion of video as transparent and exporting the resultant video as MP4 by using the below command:

ffmpeg -loop 1 -i image.jpg -i alphaVideo.mp4 -filter_complex [1:v]colorkey=0x000000:0.1:0.1[ckout];[0:v][ckout]overlay[out] -map [out] -t 5 -c:a copy result.mp4

Then I convert the resultant video into GIF by using this: ffmpeg -i result.mp4 output.gif

How can I do this in a single command? How to make output.gif directly without creating result.mp4?

Upvotes: 0

Views: 376

Answers (1)

llogan
llogan

Reputation: 133693

Just change result.mp4 to result.gif.

If you want better quality then adapt the answer from How do I convert a video to GIF using ffmpeg, with reasonable quality?:

ffmpeg -loop 1 -i image.jpg -i alphaVideo.mp4 -filter_complex "[1:v]colorkey=0x000000:0.1:0.1[ckout];[0:v][ckout]overlay=shortest=1:format=auto,fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

Upvotes: 2

Related Questions