视频截图
2016-04-24 11:32
435 查看
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface
ViewController ()
@property (weak,
nonatomic) IBOutlet
UIImageView *imageView;
@property (nonatomic,
strong) AVAssetImageGenerator *imageGenerator;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
//网盘
电影
//图片的截图
NSString *path = [[NSBundle
mainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4"
ofType:nil];
NSURL *url = [NSURL
fileURLWithPath:path];
AVAsset *asset = [AVAsset
assetWithURL:url];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator
alloc]initWithAsset:asset];//创建视频图片发生器
self.imageGenerator = imageGenerator;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//时间有误差
//注意点:
时间
用浮点,截取了第60 秒的图片,可以是数组,截取多张图片
[self.imageGenerator
generateCGImagesAsynchronouslyForTimes:@[@60.0]
completionHandler:^(CMTime requestedTime,
CGImageRef _Nullable image,
CMTime actualTime,
AVAssetImageGeneratorResult result, NSError *
_Nullable error) {
//异步
同步 A B
//如果异步
崩溃了
就用 同步
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image = [UIImage
imageWithCGImage:image];
});
//设置界面
更新UI
NSLog(@"%@",[NSThread
currentThread]);
}];
}
#import <AVFoundation/AVFoundation.h>
@interface
ViewController ()
@property (weak,
nonatomic) IBOutlet
UIImageView *imageView;
@property (nonatomic,
strong) AVAssetImageGenerator *imageGenerator;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
//网盘
电影
//图片的截图
NSString *path = [[NSBundle
mainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4"
ofType:nil];
NSURL *url = [NSURL
fileURLWithPath:path];
AVAsset *asset = [AVAsset
assetWithURL:url];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator
alloc]initWithAsset:asset];//创建视频图片发生器
self.imageGenerator = imageGenerator;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//时间有误差
//注意点:
时间
用浮点,截取了第60 秒的图片,可以是数组,截取多张图片
[self.imageGenerator
generateCGImagesAsynchronouslyForTimes:@[@60.0]
completionHandler:^(CMTime requestedTime,
CGImageRef _Nullable image,
CMTime actualTime,
AVAssetImageGeneratorResult result, NSError *
_Nullable error) {
//异步
同步 A B
//如果异步
崩溃了
就用 同步
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image = [UIImage
imageWithCGImage:image];
});
//设置界面
更新UI
NSLog(@"%@",[NSThread
currentThread]);
}];
}
相关文章推荐
- sizeof 的用法
- 类的继承与派生的基础学习
- 【读书笔记】Android安全机制解析与应用实践之源码分析
- 降维中的特征选择
- SQL语句练习
- csu 1542
- 栈及简单表达式求值
- leetcode-171. Excel Sheet Column Number
- reids-string
- 基础知识(十六)Opencv、python、ubuntu
- objec
- CXF入门RI实现
- caffe源码学习(一) google protocol buffer
- CentOS下Web服务器环境搭建LNMP一键安装包
- SGU 101 && POJ 1041 欧拉路径/欧拉回路
- 重装WIN7操作系统详细步骤
- 一个对象绕某个轴旋转,朝向另一个对象(在旋转瞄准过程中只沿着y轴旋转)
- 股价S&P预测——线性回归
- 在ADT和Android Studio中配置和使用Git
- 【坑】