根据我的理解你可以做到这一点,虽然你的应用程序只能运行有限的时间,但取决于你的视频大小,这可能就足够了。实际上,我在我的动画创作应用idAnimate - Animating on the iPad with the touch of a finger上完成了这个操作。据我所知,该应用程序将被授予约10分钟的时间来完成任务,这可能就足够了。如果您的应用需要额外的时间,您可能需要了解如何优化视频渲染算法,降低视频质量等等。
反正这里是有点怎么我这个假设的代码使用AVAssetWriter生成视频: 首先你要拨打电话获得背景的许可,并提供适合做什么块当你的时间完成(后台任务到期处理):
UIApplication *app = [UIApplication sharedApplication];
_backgroundRenderingID = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:_backgroundRenderingID];
_backgroundRenderingID = UIBackgroundTaskInvalid;
}];
之后,你可以开始渲染视频:
videoWriter = [[AVAssetWriter alloc] initWithURL:
[NSURL fileURLWithPath:self.moviePath] fileType:AVFileTypeMPEG4
error:&error];
NSParameterAssert(videoWriter);
...
当你完成确保你让OS知道,您的任务清晰了背景是com成品:
[[UIApplication sharedApplication] endBackgroundTask:_backgroundRenderingID];
我希望有所帮助。
但这会快速烧毁电池,因为这涉及大量计算和RAM I/O。 – Raptor 2013-04-23 09:05:21
如果生成的电影值得他们使用它,如果不是不。也许可以在速度上做一些改进,现在每帧处理一个图像几次。 – 2013-04-23 10:21:40