How to use video URL for thumbnail #498
Unanswered
mehroozkhan
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
You can check NukeUI for an example https://github.com/kean/NukeUI/blob/main/Sources/VideoImageDecoder.swift. It generates thumbnails before displaying a video. The system downloads the entire video though - I don't know if that's acceptable to you. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
The above never worked for me. So I ended up using the AVKit to generate a videoThumbnail instead. Hope this help someone out in the future. static func videoThumbnail(from url: URL, at time: CMTime = .zero, width: CGFloat = 300) async -> UIImage? {
let asset = AVURLAsset(url: url)
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
imageGenerator.maximumSize = CGSize(width: width, height: 0)
do {
// Use the async image(at:) method for a more modern approach.
let (cgImage, _) = try await imageGenerator.image(at: time)
return UIImage(cgImage: cgImage)
} catch {
return nil
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @kean ,
is there any way to use video url with Nuke , so it can display thumbnail image of video, and cache it as well.
actually i am using your library in a table view, and if i use my own code to generate thumbnail from video url then there are UI glitches when user scroll and video thumbnail is not generated yet and that cell is reused to display image with Nuke.
Any suggestions ?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions