extension UIImage {
/// 根据视频url和时间点截图
static func thumbnailImageForVideo(videoURL: URL, time: TimeInterval) -> UIImage? {
let asset = AVURLAsset.init(url: videoURL, options: nil)
let assetImageGenerator = AVAssetImageGenerator(asset: asset)
assetImageGenerator.appliesPreferredTrackTransform = true
assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureMode.encodedPixels
let thumbnailCGImage: CGImage?
let thumbnailImageTime: CFTimeInterval = time
var thumbnailImage: UIImage?
do {
thumbnailCGImage = try assetImageGenerator.copyCGImage(at: CMTimeMake(Int64(thumbnailImageTime),60), actualTime: nil)
if let cgImage = thumbnailCGImage {
thumbnailImage = UIImage(cgImage: cgImage)
}
} catch {
}
return thumbnailImage
}
}