获取视频文件第一帧图片
2015-12-28 10:34
555 查看
+ (UIImage*) thumbnailImageForVideo:(NSString *)videoPath
{
if(videoPath.length ==
0)
{
return
nil;
}
NSURL *videoURL = [NSURL
fileURLWithPath:videoPath];
AVURLAsset *asset = [[AVURLAsset
alloc] initWithURL:videoURL
options:nil];
NSParameterAssert(asset);
AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator
alloc] initWithAsset:asset];
assetImageGenerator.appliesPreferredTrackTransform =
YES;
assetImageGenerator.apertureMode =
AVAssetImageGeneratorApertureModeEncodedPixels;
CGImageRef thumbnailImageRef =
NULL;
CFTimeInterval thumbnailImageTime =
0;
NSError *thumbnailImageGenerationError =
nil;
thumbnailImageRef = [assetImageGenerator
copyCGImageAtTime:CMTimeMake(thumbnailImageTime,
15) actualTime:NULL
error:&thumbnailImageGenerationError];
UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage
alloc] initWithCGImage:thumbnailImageRef] :
nil;
//NSData *imageData = UIImagePNGRepresentation(thumbnailImage);
CGImageRelease(thumbnailImageRef);
return thumbnailImage;
}
{
if(videoPath.length ==
0)
{
return
nil;
}
NSURL *videoURL = [NSURL
fileURLWithPath:videoPath];
AVURLAsset *asset = [[AVURLAsset
alloc] initWithURL:videoURL
options:nil];
NSParameterAssert(asset);
AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator
alloc] initWithAsset:asset];
assetImageGenerator.appliesPreferredTrackTransform =
YES;
assetImageGenerator.apertureMode =
AVAssetImageGeneratorApertureModeEncodedPixels;
CGImageRef thumbnailImageRef =
NULL;
CFTimeInterval thumbnailImageTime =
0;
NSError *thumbnailImageGenerationError =
nil;
thumbnailImageRef = [assetImageGenerator
copyCGImageAtTime:CMTimeMake(thumbnailImageTime,
15) actualTime:NULL
error:&thumbnailImageGenerationError];
UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage
alloc] initWithCGImage:thumbnailImageRef] :
nil;
//NSData *imageData = UIImagePNGRepresentation(thumbnailImage);
CGImageRelease(thumbnailImageRef);
return thumbnailImage;
}
相关文章推荐
- matplotlib 绘图总结
- Duplicate files copied in APK META-INF/maven/com.squareup.okio/okio/pom.properties
- 几种常用加密算法比较
- 怎么在eclipse中安装properties插件
- Core Animation 简明系列教程
- Exhange上添加IMAP4
- 把vim配置成编程利器
- 判断当前应用程序处于前台还是后台
- Java线程篇(七):Callable和Future
- linux 乱码 GBK转UTF8
- Hdu 2087
- 在老男孩教育的日子
- 使用SVG图片格式
- cocos2dx windows eclipse 开发配置准备
- 百度排名规则及算法(百度内部资料)
- IOS 真机调试 There was an internal API error.
- Educational Codeforces Round 4 A. The Text Splitting 水题
- 将[4,3,2,5,4,3]分割成[4,3,2]、[5,4,3]两个List的算法
- JSP中<base href="<%=basePath%>">作用
- 自定义progressBar(进度条)