在Swift 4.2中我试图从视频中截取屏幕截图
func thumbnailImageFor(fileUrl:URL) -> UIImage? {
let asset = AVAsset(url: fileUrl)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
let time = CMTimeMakeWithSeconds(1.0, preferredTimescale: 600)
do {
let img = try assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let thumbnail = UIImage(cgImage: img)
return thumbnail
} catch {
print(error)
return nil
}
}
But getting error:
错误域= AVFoundationErrorDomain代码= -11800“操作无法完成”UserInfo = {NSLocalizedFailureReason =发生未知错误(-12792),NSLocalizedDescription =操作无法完成,NSUnderlyingError = 0x600000f46580 {错误域= NSOSStatusErrorDomain代码= -12792“(null)”}}
我错过了什么吗?
1 回答
我认为这可能与电影的文件类型有关,因为这有效: