Created
April 22, 2014 08:14
-
-
Save exce11ent/11169732 to your computer and use it in GitHub Desktop.
SynchronizedLayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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