根據我的理解你可以做到這一點,雖然你的應用程序只能運行有限的時間,但取決於你的視頻大小,這可能就足夠了。實際上,我在我的動畫創作應用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