iphone - 不能让 AVAssetImageGenerator 给我电影的所有帧

标签 iphone ios video thumbnails

我不能让 AVAssetImageGenerator 给我电影的所有帧。

使用这段代码:

NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mov"];
NSURL *url=[NSURL fileURLWithPath:path];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
self.asset=[[AVURLAsset alloc] initWithURL:url options:options];

NSMutableArray *thumbTimes=[NSMutableArray arrayWithCapacity:asset.duration.value];
for(int t=0;t < asset.duration.value;t++) {
    CMTime thumbTime = CMTimeMake(t,asset.duration.timescale);
    NSValue *v=[NSValue valueWithCMTime:thumbTime];
    [thumbTimes addObject:v];
}
self.generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
self.generator.appliesPreferredTrackTransform=TRUE;
self.generator.requestedTimeToleranceAfter=kCMTimeZero;
self.generator.requestedTimeToleranceBefore=kCMTimeZero;


AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
    if (result != AVAssetImageGeneratorSucceeded) {
        NSLog(@"couldn't generate thumbnail, error:%@", error);
    }
    NSLog(@"actual time: %lld/%d (requested: %lld/%d)",actualTime.value,actualTime.timescale,requestedTime.value,requestedTime.timescale);
};
CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:thumbTimes completionHandler:handler];

我得到:

2012-04-19 18:55:06.801 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 0/600)
2012-04-19 18:55:07.836 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 1/600)
2012-04-19 18:55:08.314 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 2/600)
2012-04-19 18:55:09.350 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 3/600)
2012-04-19 18:55:10.186 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 4/600)
2012-04-19 18:55:11.257 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 5/600)
2012-04-19 18:55:11.697 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 6/600)
2012-04-19 18:55:12.246 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 7/600)
2012-04-19 18:55:13.255 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 8/600)
2012-04-19 18:55:14.513 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 9/600)
2012-04-19 18:55:15.944 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 10/600)
2012-04-19 18:55:17.230 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 11/600)
2012-04-19 18:55:17.995 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 12/600)
2012-04-19 18:55:18.716 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 13/600)
2012-04-19 18:55:19.399 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 14/600)

正如您在代码中看到的那样,我尝试设置 AVURLAssetPreferPreciseDurationAndTimingKeyrequestedTimeToleranceBeforerequestedTimeToleranceAfter 但没有任何效果。

有什么想法吗?

最佳答案

使用您的代码,您可以获得电影的所有帧。请求时间和实际时间之间的差异是由电影帧率引起的。看来,你的电影有大约。 25-29 帧/秒。因此,例如时间 1/600s 和 8/600s 之间没有差异帧。

关于iphone - 不能让 AVAssetImageGenerator 给我电影的所有帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10232072/

相关文章:

iphone - iphone上tableview上的sqlite db上的文本搜索太慢了

ios 7 UIView animateWithDuration : . 。立即运行

iOS - 如何按顺序执行两个转换?

安卓视频缩略图

c++ - FFMPEG API 和裁剪

javascript - 联系表格在 iPhone 上无效

iphone - 在 iBooks 中打开 PDF

iphone - 具有自定义 rightView 的 UITextField 中的宽度问题

opencv - 如何使用 OpenCV 读取实时提要

ios - 在 Swift 中按顺序播放音频文件,其中第二个声音重复播放