在我的项目中,我需要在一个独特的结果图像上复制一个视频帧的每个帧。iOS - 视频帧处理优化
捕获视频帧并不是什么大不了的事。它会是这样的:
// 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-14s,我的iPhone 4S宣布他的第三个内存警告和崩溃。我异形与泄漏工具的应用,并没有发现任何泄漏在所有...
我不是在石英很强。有没有更好的优化方式来实现这一目标?
马丁嗨,一路图像提取物是完美的,但在应用程序,如果视频时长超过30秒,然后应用内存警告崩溃。你有其他的方式或者有什么变化吗?谢谢 – iBhavik 2013-05-14 06:34:15
嗨。它不应该与长视频崩溃。检查你的代码,也许你在处理程序块中包含泄漏。您无法将所有提取的图像保留在内存中,因为设备没有足够的内存空间。 – Martin 2013-05-14 08:06:28
@iBhavik你有没有找到任何解决方案 – Nil 2017-07-06 15:29:22