5

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 ignored.

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!

Mihai Fratu
  • 7,579
  • 2
  • 37
  • 63

1 Answers1

2

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.

MiguelB
  • 1,913
  • 18
  • 20
  • Thanks for the tip. I will try this as soon as I get to the office tomorrow and I'll let you know if this works... – Mihai Fratu Jul 17 '11 at 08:31
  • I did this `CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); float transparentWhite[] = { 1, 1, 1, 0 }; CGColorRef backgroundColor = CGColorCreate(colorSpace, transparentWhite); _videoInstruction.backgroundColor = backgroundColor;` and it still doesn't work... – Mihai Fratu Jul 18 '11 at 07:59
  • I tried this, the white color gets visible with this method but the alpha is ignored, even if I set opacity for the rendered pixel buffer. Any ideas why this could happen and any ways to workaround ? – Deepak Sharma Jul 09 '14 at 06:01