Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Image thumbnail from video
import AVFoundation
func getThumbnail(url: URL) -> UIImage? {
do {
let asset = AVURLAsset(url: url , options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(0, 1), actualTime: nil)
let thumbnail = UIImage(cgImage: cgImage)
return thumbnail
} catch (let error) {
debugPrint("Error with thumbnail generation: \(error.localizedDescription)")
return nil

This comment has been minimized.

Copy link
Owner Author

@filsv filsv commented Sep 20, 2019

Not supported on WatchOS (currently 6.0)
Supported on: iOS 4.0+, macOS 10.7+, tvOS 9.0+;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment