获取本地视频缩略图,既第一帧图片的方法

来源:互联网 发布:质量控制系统 php 编辑:程序博客网 时间:2024/04/29 17:04

请问如何获取本地视频的缩略图呢?

  • 0.00 / 5 5
  • 1 / 5
  • 2 / 5
  • 3 / 5
  • 4 / 5
  • 5 / 5
0 votes, 0.00 avg. rating (0% score)

我在网上找的方法

+(UIImage *)getImage1:(NSString *)videoURL
{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoURL] options:nil];
    AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    gen.appliesPreferredTrackTransform = YES;
    CMTime time = CMTimeMakeWithSeconds(0.0, 600);
    NSError *error = nil;
    CMTime actualTime;
    CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
    UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
    CGImageRelease(image);
    return thumb;
    
}

这个方法 不能获取本地视频的缩略图, CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];这句话  image为空, 不知道 哪位能看看到底怎么才能正确的获取我的APP 里Docment里视频的缩略图?

补充内容 (2013-5-17 09:57):
问题 已解决, 是视频格式的问题,AVI的抓不出图来

以上为原文,参数vedioURL,是本地路径,存在手机的路径,类似如下

/var/mobile/Applications/E673C67A-0B3B-4BC8-90BC-1696941E6522/Documents/MyRecordVideo/2014-03-19 13:00:30.0.mp4





0 0
原创粉丝点击