項(xiàng)目需求要獲取多個(gè)視頻的第十秒截圖
百度了一個(gè)方法
// 獲取視頻第一幀
- (UIImage*) getVideoPreViewImage:(NSURL *)path
{
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:path options:nil];
AVAssetImageGenerator *assetGen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
assetGen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [assetGen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
return videoImage;
}
想當(dāng)然地把CMTime time = CMTimeMakeWithSeconds(0.0, 600);改成CMTime time = CMTimeMakeWithSeconds(10.0, 600);
發(fā)現(xiàn)效率很低
廢了很多時(shí)間去做優(yōu)化,開(kāi)線程,回主線程刷界面,巴拉巴拉
之后查閱了七牛開(kāi)發(fā)文檔之后,才發(fā)現(xiàn),七牛給了獲取視頻截圖的接口,
用文件地址 + vframe/jpg/offset/0 就是取 0秒的截圖 。 后邊0是秒的單位
瞬間XXXXX
[imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?vframe/jpg/offset/10",model.url]]];
這樣就OK了??!
小白總結(jié),歡迎打臉指正