您的位置:首页 > 其它

视频截图

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]);

}];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: