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.
Asked
Active
Viewed 183 times
1
-
While the example mentioned below would composite still images with alpha over a video, it does not work for a video with alpha that would be composited over another video. For an actual working example of a video with a full alpha channel under iOS, see http://stackoverflow.com/a/17138789/763355 – MoDJ Dec 06 '15 at 00:03
1 Answers
1
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];

Mika
- 5,807
- 6
- 38
- 83