Created
March 25, 2018 19:49
-
-
Save PaulWall43/acb301db8762e6b396e34c8bac87d89a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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