Skip to content

Instantly share code, notes, and snippets.

@exce11ent
Created April 22, 2014 08:14
Show Gist options
  • Save exce11ent/11169732 to your computer and use it in GitHub Desktop.
Save exce11ent/11169732 to your computer and use it in GitHub Desktop.
SynchronizedLayer
AVPlayerItem * playerItem = [project playerItem];
if ([playerItem.videoComposition.instructions count] < 1) {
if (completionHandler) completionHandler(nil);
return;
}
AVSynchronizedLayer *synchronizedLayer = [project synchronizedLayer];
AVMutableVideoComposition *mvc = [AVMutableVideoComposition videoComposition];
mvc.instructions = playerItem.videoComposition.instructions;
mvc.renderScale = playerItem.videoComposition.renderScale;
mvc.renderSize = playerItem.videoComposition.renderSize;
mvc.frameDuration = playerItem.videoComposition.frameDuration;
// For export: build a Core Animation tree that contains both the animated title and the video.
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, project.videoSize.width, project.videoSize.height);
videoLayer.frame = CGRectMake(0, 0, project.videoSize.width, project.videoSize.height);
[parentLayer addSublayer:videoLayer];
parentLayer.geometryFlipped = YES;
CALayer *synchronizedLayerCopy = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:synchronizedLayer]];
NSArray *sublayers = [synchronizedLayerCopy.sublayers copy];
for (CALayer *layer in sublayers) {
[parentLayer addSublayer:layer];
}
//post-rendering restore
[[Project currentProject] setVideoSize:preExportSize];
mvc.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment