Please check the link "Create thumbnails from the video"
https://littlebitesofcocoa.com/115-generating-thumbnails-from-videos
For an application, it is enough to distribute one or several thumbnails (small previews of still images) of what is in the video. However, depending on where the video comes from, we may not have easy access to pre-made thumbnails for it. Let's see how we can use AVAssetImageGenerator to capture our own. We start with a simple NSURL for video, it can be local or remote. We will create an AVAsset with it and with a new AVAssetImageGenerator object. We will configure the generator to apply the preferred transforms so that our sketches are in the correct orientation.
import AVFoundation if let asset = AVAsset(URL: videoURL) { let durationSeconds = CMTimeGetSeconds(asset.duration) let generator = AVAssetImageGenerator(asset: asset) generator.appliesPreferredTrackTransform = true let time = CMTimeMakeWithSeconds(durationSeconds/3.0, 600) var thumbnailImage: CGImageRef generator.generateCGImagesAsynchronouslyForTimes([NSValue(CMTime: time)]) { (requestedTime: CMTime, thumbnail: CGImage?, actualTime: CMTime, result: AVAssetImageGeneratorResult, error: NSError?) in self.videoThumbnailImageView.image = UIImage(CGImage: thumbnail) } }
Disha Apr 13 '17 at 9:48 on 2017-04-13 09:48
source share