Skip to content

Instantly share code, notes, and snippets.

@ericdke
Created January 20, 2016 10:33
Show Gist options
  • Save ericdke/537617c2e4be51b98a62 to your computer and use it in GitHub Desktop.
Save ericdke/537617c2e4be51b98a62 to your computer and use it in GitHub Desktop.
import AVFoundation
func getImageFromVideo(videoURL: String) -> UIImage? {
do {
let asset = AVURLAsset(URL: NSURL(fileURLWithPath: videoURL), options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = try imgGenerator.copyCGImageAtTime(CMTimeMake(0, 1), actualTime: nil)
let image = UIImage(CGImage: cgImage)
return image
} catch {
print(error)
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment