首页 > 代码库 > iOS 获取本地视频的缩略图
iOS 获取本地视频的缩略图
+(UIImage *)getImage:(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;
}
需要添加AVFoundation和CoreMedia.framework
另外一种那个方法
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:videoURL]; moviePlayer.shouldAutoplay = NO;
UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];
//这个也一样
+(UIImage *)fFirstVideoFrame:(NSString *)path
{
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:path]];
UIImage *img = [mp thumbnailImageAtTime:0.0
timeOption:MPMovieTimeOptionNearestKeyFrame];
[mp stop];
[mp release];
return img;
}
转:http://blog.sina.com.cn/s/blog_6d01cce301019xym.html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。