IOS从视频中获取截图
2015-09-14 17:59
645 查看
从视频中获取截图:
NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”];
mpviemController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movpath]];
MPMoviePlayerController *mp=[mpviemController moviePlayer];
UIImage *thumbImage=[mp thumbnailImageAtTime:second timeOption:MPMovieTimeOptionNearestKeyFrame];
NSData *imagedata =UIImagePNGRepresentation(thumbImage);
[imagedata writeToFile:@"iosxcode4.png" atomically:YES];
第二种方式 直接为UIImage写一个分类:
+(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;
}
NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”];
mpviemController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movpath]];
MPMoviePlayerController *mp=[mpviemController moviePlayer];
UIImage *thumbImage=[mp thumbnailImageAtTime:second timeOption:MPMovieTimeOptionNearestKeyFrame];
NSData *imagedata =UIImagePNGRepresentation(thumbImage);
[imagedata writeToFile:@"iosxcode4.png" atomically:YES];
第二种方式 直接为UIImage写一个分类:
+(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;
}
相关文章推荐
- iOS开发:利用SDWebImage实现图片加载与缓存
- iOS cocoapods
- iOS开发:一个瀑布流的设计与实现(已实现缓存池功能,该功能使得瀑布流cell可以循环利用)
- (转)27个提升效率的iOS开源库推荐
- IOS开发模块总结(二)后台运行程序(1) 后台运行程序详解(二)
- iOS 计算年龄
- IOS开发模块总结(二)后台运行程序(1) 后台运行程序详解(一)
- iOS开发的22个奇谲巧技
- iOS开发之摇一摇功能的实现
- iOS ios与js交互,获取webview完整url,title,获取元素并赋值跳转
- iOS开发--touchID指纹识别
- ios
- iOS--常用控件--WebView与js相互调用
- ffmpeg在iOS的使用 - iFrameExtractor源码解析
- iOS 警告收录及科学快速的消除方法
- 全面了解 iOS 静态库开发
- framework not found XCTest
- ios arc下内存管理
- FIRST TODY STAR
- iOS运动事件学习