I need to fetch thumbnail from a video URL to display in ImageView that is in a UITableViewCell.
I can get thumbnail using this method but it takes lots of resource and hence the tableview scrolling lags and stops for the time cellForRowAtIndexPath is called.
This is the method.
func createThumbnailOfVideoFromFileURL(videoURL: String) -> UIImage? {
let asset = AVAsset(url: URL(string: videoURL)!)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
let time = CMTimeMakeWithSeconds(Float64(1), 100)
do {
let img = try assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let thumbnail = UIImage(cgImage: img)
return thumbnail
} catch {
return UIImage(named: "ico_placeholder")
}
}
Can anyone please suggest me an alternative to use SDWebImage so that the images go to the cache and are not fetched everytime UITableView delegates are called. Kindly suggest any other approach if i m wrong.