gpt4 book ai didi

ios - iOS Swift : Error Domain=NSOSStatusErrorDomain Code=-12792?

转载 作者:行者123 更新时间:2023-12-01 16:15:07 36 4
gpt4 key购买 nike

我正在尝试使用以下代码获取视频缩略图:

let asset = AVAsset(URL: url)
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true

do {
let cgImage = try imgGenerator.copyCGImageAtTime(CMTimeMake(1, 30), actualTime: nil)
let uiImage = UIImage(CGImage: cgImage)
imageview.image = uiImage
}
catch let error as NSError
{
print("Image generation failed with error \(error)")
}

有时它可以工作,有时却不显示以下错误:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x14eab520 {Error Domain=NSOSStatusErrorDomain Code=-12792 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12792)}



我试图弄清楚 Domain=NSOSStatusErrorDomain Code=-12792是什么,但是我不明白如何获得有关此错误代码的更多详细信息。如何将错误代码转换成字符串以获取有关此错误含义的相关信息?

最佳答案

我可以通过以下方法解决此问题。

swift 4.1

func createThumbnailForVideo(atURL videoURL: URL , completion : @escaping (UIImage?)->Void) {
let asset = AVAsset(url: videoURL)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
let time = CMTimeMakeWithSeconds(1, preferredTimescale: 60)
let times = [NSValue(time: time)]
assetImgGenerate.generateCGImagesAsynchronously(forTimes: times, completionHandler: { _, image, _, _, _ in
if let image = image {
let uiImage = UIImage(cgImage: image)
completion(uiImage)
} else {
completion(nil)
}
})
}

希望这会有所帮助。

关于ios - iOS Swift : Error Domain=NSOSStatusErrorDomain Code=-12792?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387551/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com