dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
AVURLAsset *asset = [[AVURLAsset alloc]initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);// 处理视频内容常见刻度,600是24fps、25fps、30fps的公倍数
NSError *error = nil;
CMTime actualTime;
CGImageRef imageRef = [generator copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
// 存入内存、存入本地
[[PFMediaTool shareMediaTool].frameKeyMap setObject:resultImage forKey:frameKey];
[self saveImageToCache:resultImage forKey:frameKey];
CGImageRelease(imageRef);
dispatch_async(dispatch_get_main_queue(), ^{
completeBlock(resultImage);
});
});
网友评论