我正在尝试创建一个新的应用程序,用于在iPhone上编辑视频,并使用AVFoundation框架。当使用AVMutableComposition和AVMutableVideoComposition生成视频时,应用程序因内存崩溃,有没有更好的方法来编辑视频?或者如何优化它?
以下是代码,我认为这主要是因为我创建的 animatedTitleLayer ,我添加了大约5张照片,以执行核心动画。
// Set up Core Animation layers to contribute a title animation overlay if we have a title set.
if (self.titleText) {
animatedTitleLayer = [self buildAnimatedTitleLayerForSize:videoSize];
if (! forPlayback) {
// 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, videoSize.width, videoSize.height);
videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:animatedTitleLayer];
if (! videoComposition) {
// No transition set -- make a "pass through video track" video composition so we can include the Core Animation tree as a post-processing stage.
videoComposition = [AVMutableVideoComposition videoComposition];
[self buildPassThroughVideoComposition:videoComposition forComposition:composition];
}
videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
}
if (videoComposition) {
// Every videoComposition needs these properties to be set:
videoComposition.frameDuration = CMTimeMake(1, 30); // 30 fps
videoComposition.renderSize = videoSize;
}
还有其他将核心动画转换为视频吗?在上面的代码中,我必须同时添加所有照片。
有一个应用程序,Splice video editor,非常好,快速和稳定。我将要做的几乎与它相同,将核心动画转换为视频,但速度慢且不稳定。