【发布时间】:2013-07-02 22:01:00
【问题描述】:
我想将 iOS6 中视频的所有帧放入NSArray。
我使用此代码:
-(void) getAllImagesFromVideo
{
imagesArray = [[NSMutableArray alloc] init];
times = [[NSMutableArray alloc] init];
for (Float64 i = 0; i < 15; i += 0.033) // For 25 fps in 15 sec of Video
{
CMTime time = CMTimeMakeWithSeconds(i, 60);
[times addObject:[NSValue valueWithCMTime:time]];
}
[imageGenerator generateCGImagesAsynchronouslyForTimes:times completionHandler:^(CMTime requestedTime, CGImageRef image, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) {
if (result == AVAssetImageGeneratorSucceeded)
{
UIImage *generatedImage = [[UIImage alloc] initWithCGImage:image];
[imagesArray addObject:generatedImage];
}
}];
}
在 iPad 模拟器上延迟为 90~100 秒,在 iPad 设备上,收到内存警告并最终崩溃。
任何想法,解决方案?使用另一个更底层的框架/库? C++? 对我来说很重要!帮我! :)
谢谢!!!
【问题讨论】:
-
您可以使用ffmpeg framework从视频中提取帧
-
是的,我知道,但我不知道怎么做。有什么帮助吗?谢谢! :)
-
我认为 iPhone 内存无法容纳 400 张图像,我建议将图像保存在您的文档目录中。如果您仍然对示例感兴趣,请告诉我,我会写一个答案
-
@ekeren 我使用其他方法,但我想看看你的答案!谢谢! ;)
-
补充,你最终用了什么?
标签: ios objective-c avfoundation frame-rate image-generation