I create video thumbnails with the following code, and it works in most cases. However, sometimes it throws an error and a thumbnail is not created. I cannot understand why this does not work sometimes.
This is how I create a video thumbnail:
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)") }
It works in most cases, when it does not work, it causes this error:
Error generating thumbnail: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x17658520 {Error Domain=NSOSStatusErrorDomain Code=-12792 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12792)}
I do not know why he throws this error and did not find a solution to stack overflow, although other people faced the same problem.
swift error-handling avplayer video-thumbnails
Sam May 22 '16 at 11:54 2016-05-22 11:54
source share