I\'m trying to get the first frame of a video using the classes in AVFoundation. But it appears to not be getting an image at all.
My code currently looks like this
Doing this in Swift 4.0:
// Assumes you have a local `fileURL`
var avAsset = AVURLAsset(url: fileURL, options: nil)
var imageGenerator = AVAssetImageGenerator(asset: avAsset)
imageGenerator.appliesPreferredTrackTransform = true
var thumbnail: UIImage?
do {
thumbnail = try UIImage(cgImage: imageGenerator.copyCGImage(at: CMTime(seconds: 0, preferredTimescale: 1), actualTime: nil))
} catch let e as NSError {
print("Error: \(e.localizedDescription)")
}