Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG - Merging Videos with Transparency

I am trying to merge two videos together, both have transparency, using the command

ffmpeg.exe -i person2.mov -vf "[in] scale=iw/2:ih/2,fade=out:300:30:alpha=1, pad=2*iw:ih [left]; movie=person2.mov, scale=iw/2:ih/2,fade=out:300:30:alpha=1 [right]; [left][right] overlay=main_w/3:0,fade=out:300:30:alpha=1 [out]" -b:v 768k Output_people.mov

By doing that I get the following output:

http://i263.photobucket.com/albums/ii122/Fernando461/Untitled.png

As you can see, it was possible to get the two videos to be on top of each other. But then, when I try to merge this video (Output_people.mov) with another video, it doesn't have the same transparency. Is it possible to keep transparency in the outcome?

Edit 1:

This is the output I get: https://www.dropbox.com/s/gpid1pptfio31gd/ffmpeg-20130701-193206.log

And by "it doesn't have the same transparecy" I meant that the background is black instead of being transparent, so if I put one video on top of each other, the one in the back is covered by a black part of the one in the front.

Edit 2: Adding -vcodec qtrle to the code worked. Thanks mark4o!

like image 753
fernandonos Avatar asked Jul 02 '13 00:07

fernandonos


1 Answers

You did not specify a video codec for the output, so it is using the default video codec for .mov files which is H.264 (libx264 encoder). However H.264 does not support an alpha channel. If you want transparency in your output video you will need to specify an output video codec that supports an alpha channel, such as the one used for your input, i.e. QuickTime Animation RLE (qtrle). To do this, add the option -c:v qtrle before the output file name. Another codec that supports an alpha channel and can be stored in .mov files is png.

You can check the list of encoders supported by your ffmpeg with ffmpeg -encoders. A command like ffmpeg -h encoder=qtrle will list information specific to that encoder, including the supported pixel formats. A pixel format that includes the string argb, rgba, abgr, bgra, gbra, or yuva has an alpha channel.

like image 55
mark4o Avatar answered Oct 17 '22 11:10

mark4o