AVURLAsset和AVAssetImageGenerator返回空图像

use*_*788 3 iphone thumbnails avfoundation

我试图从我从iPhone相机捕获的.mov文件中获取缩略图.我目前将电影保存在应用程序的文档部分.当我调用[资产持续时间]时,它返回一个空对象.此外,当我尝试调用copyCGImageAtTime:actualtime:error方法时,它还返回一个null对象.我花了不少时间试图解决这个问题.我已经尝试将我的代码移动到我的应用程序的另一个主要部分,看看我是否可以让它工作.我也试过在模拟器上运行它没有运气.这是代码:

NSString* destinationPath = [NSString stringWithFormat:@"%@/aaa/aaa.mov", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:destinationPath] options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error2 = nil;
CMTime actualTime;

CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error2];
UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);   
Run Code Online (Sandbox Code Playgroud)

我还确认该电影确实存在于该文件夹下.任何帮助将不胜感激.谢谢 :)

- 编辑 -

忘记提到copyCGImageAtTime的错误是AVUnknown错误.

--Edit2--发现了问题.我没有在url的开头包含file://.它现在有效.

use*_*788 9

发现了问题.我没有file://在网址的开头包含.它现在有效.