开发者

How to set a transparent background for an AVVideoComposition?

Update - I've added a 50 reputation bounty for answering this question!

I have an application that needs to put together some videos and photos to create a movie out of them. I am using AVMutableComposition for that. To be able to instruct it how the videos get composed I have to use an AVMutableVideoComposition. This thing has a property called backgroundColor and Apple Documentation says:

Only solid BGRA colors are supported; patterns and other supported colors are ignored. If the rendered pixel buffer does not have alpha, the alpha value of the background color is ig开发者_如何学运维nored.

What I understand from this is that there is a way to add alpha channel to the backgroundColor but I just don't understand how. What does If the rendered pixel buffer does not have alpha, the alpha value of the background color is ignored. mean? And how I can add such thing?

If I just do myVideoCompositionInstruction.backgroundColor = [[UIColor colorWithWhite:1 alpha:0] CGColor]; it just doesn't work - the background stays white and doesn't go transparent.

Any help would be much appreciated, Thanks!


In Apple's documentation for AVVideoCompositionInstruction the property you want to set, backgroundColor, is of type CGColorRef.

My bet is, because you are setting backgroundColor with UIColor and only then getting the value of it through the CGColor property, for some reason the alpha value doesn't get passed into a CGColorRef object. You know the white value gets passed because the default color is black.

UIColor has some limitations. I suggest you read the following article. Take particular notice of the section "The problems with UIColor" of the article.

I'm guessing the best solution for your problem is defining backgroundColor with CGColor directly (use CGColorCreate, for instance), instead of UIColor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜