iOS获取本地视频和网络URL视频的缩略图方法
2016-03-30 16:44
701 查看
首先大家先添加AVFoundation和CoreMedia.framework两个框架
第一种本地视频获取缩略图
第二种获取网络视频的缩略图
第三站方法用AVFoundation实现
文/Lonely__(简书作者)
原文链接:http://www.jianshu.com/p/cc52403f7d42
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
第一种本地视频获取缩略图
NSString *path = @"www.51ios.net/本地路径" MPMoviePlayerController *51iosMPMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; UIImage *img = [51iosMPMovie thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 此处的img就是时间在0.0的缩略图
第二种获取网络视频的缩略图
NSString *videoURL = @"http://www.51ios.net/archives/784" MPMoviePlayerController *51iosMPMovie = [[MPMoviePlayerController alloc]initWithContentURL:videoURL]; 51iosMPMovie.shouldAutoplay = NO; UIImage *thumbnail = [51iosMPMovie thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame]; 此处的thumbnail就是网络视频的缩略图
第三站方法用AVFoundation实现
+(UIImage *)getThumbnailImage:(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; }
文/Lonely__(简书作者)
原文链接:http://www.jianshu.com/p/cc52403f7d42
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
相关文章推荐
- (转)使用Jmeter进行http接口测试
- Android AndBase框架使用封装好的函数完成Http请求(三)
- PySpider HTTP 599: SSL certificate problem错误的解决方法
- http协议
- android+https网址屏蔽证书+IntentService+NotifyManager通知栏+下载apk文件+在通知栏显示下载进度+完成之后提示安装
- linux TCP Wrappers
- 网络相关系列之一:Android中使用HttpClient发送HTTP请求
- 屏蔽HTTPS证书验证下载apk安装包
- c++ 构造http post 发文件
- (OK) port_php-5.6.14_to_Android—(和lighttpd集成成功)—没有基于android 4.4源码
- OSI、TCP/IP参考模型对应的网络协议
- 神经网络模型算法与生物神经网络的最新联系
- 美图欣赏,转载[原文链接http://toutiao.com/a4001258776/]
- HDU5455 沈阳网络赛 Fang Fang
- 跨域问题解决方案(HttpClient安全跨域 & jsonp跨域)
- 常用对照表之HTTP content-type
- ASIHttpRequest所需要的FrameWork
- TCP四次挥手
- httpClient PostMethod
- Nagle算法