【发布时间】:2014-06-27 22:14:57
【问题描述】:
在我的项目中,我需要将视频的每一帧的一部分复制到一个唯一的结果图像上。
捕获视频帧并不是什么大问题。它会是这样的:
// duration is the movie lenght in s.
// frameDuration is 1/fps. (or 24fps, frameDuration = 1/24)
// player is a MPMoviePlayerController
for (NSTimeInterval i=0; i < duration; i += frameDuration) {
UIImage * image = [player thumbnailImageAtTime:i timeOption:MPMovieTimeOptionExact];
CGRect destinationRect = [self getDestinationRect:i];
[self drawImage:image inRect:destinationRect fromRect:originRect];
// UI feedback
[self performSelectorOnMainThread:@selector(setProgressValue:) withObject:[NSNumber numberWithFloat:x/totalFrames] waitUntilDone:NO];
}
当我尝试实现drawImage:inRect:fromRect: 方法时,问题就来了。
我试过this code,它:
- 使用
CGImageCreateWithImageInRect从视频帧中创建一个新的CGImage 以提取图像块。 - 在 ImageContext 上创建一个 CGContextDrawImage 来绘制块
但是当视频达到 12-14 秒时,我的 iPhone 4S 宣布他的第三次内存警告并崩溃。我已经使用 Leak 工具分析了该应用程序,它根本没有发现任何泄漏...
我在 Quartz 方面不是很强。有没有更好的优化方法来实现这一点?
【问题讨论】:
标签: ios optimization mpmovieplayercontroller video-processing