Reputation: 143
I have two videos, one which the user films with the device's camera, and the other is a video with alpha channel that I want to present on top of the first video. I've been searching a lot and haven't found the right method to do that. 1. What is the right format for the overlay video (the one with the alpha)? 2. How do I do the match between the two? There is an app called Action Movie FX which does exactly what I'm talking about. Thanks in advance.
Upvotes: 1
Views: 244
Reputation: 5845
Ray Wenderlish has a very good tutorial to do exactly this. http://www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos.
The basic concept if creating layers on top of each other. For example the following code will add a UILabel onto a video:
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:36];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, 100)];
[subtitle1Text setString:_subTitle1.text];
[subtitle1Text setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text setForegroundColor:[[UIColor whiteColor] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
[overlayLayer addSublayer:subtitle1Text];
overlayLayer.frame = CGRectMake(0, 0, size.width, size.height);
[overlayLayer setMasksToBounds:YES];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
Upvotes: 1