Reputation: 2422
I want to get preview image(not thumbnail image).
Of course, I can get thumbnail of video from first frame with this code.
func generateThumbImage() -> UIImage{
let assetImgGenerate : AVAssetImageGenerator = AVAssetImageGenerator(asset: self)
assetImgGenerate.appliesPreferredTrackTransform = true
let time : CMTime = CMTimeMake(1, 30)
let img : CGImage = try! assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let frameImg : UIImage = UIImage(cgImage: img)
return frameImg
}
Can anyone please suggest solution?
Upvotes: 1
Views: 1216
Reputation: 25491
I am not sure if iOS has a function that will do this for your automatically, but the way this is generally done on other platforms or for streamed video files, is that thumbnails are generated at regular intervals throughout the video, say every 10 seconds for a 2 minute video, and these are what are displayed in the area you highlight.
You can do this yourself with your code above but looping and moving the time you generate your thumbnail at - but if an iOS function exists to do this for you that would clearly be easier.
For streamed video services, the thumbnail generation is often done at the same time as the video is transcoded as it is more efficient that way, and the file of thumbnails is included in the manifest or 'index' file for the video when it is being streamed.
Upvotes: 2