Skip to content

Instantly share code, notes, and snippets.

@PaulWall43
Created March 25, 2018 19:49
Show Gist options
  • Save PaulWall43/acb301db8762e6b396e34c8bac87d89a to your computer and use it in GitHub Desktop.
Save PaulWall43/acb301db8762e6b396e34c8bac87d89a to your computer and use it in GitHub Desktop.
func createThumbnailOfVideoFromRemoteUrl(url: String) -> UIImage? {
let asset = AVAsset(url: URL(string: url)!)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
//Can set this to improve performance if target size is known before hand
//assetImgGenerate.maximumSize = CGSize(width,height)
let time = CMTimeMakeWithSeconds(1.0, 600)
do {
let img = try assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let thumbnail = UIImage(cgImage: img)
return thumbnail
} catch {
print(error.localizedDescription)
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment