2

I'm receiving a high/medium quality thumbnail of remote video by AVAssetImageGenerator, but still it takes 10 to 15 seconds to get thumbnail out of it.
Is there any way to get low quality thumbnail instantly?
below code I've used to get thumbnail of remote video.
The strange is when I download this video it's size was 1.1 MB and created Thumbnail size is 1.8 MB.

let assetForThumbnail = AVAsset(URL: videoURL)
let durationSeconds = CMTimeGetSeconds(assetForThumbnail.duration)
let generator = AVAssetImageGenerator(asset: assetForThumbnail)
generator.appliesPreferredTrackTransform = true
let time = CMTime(seconds: durationSeconds/3.0, preferredTimescale: 600)

generator.generateCGImagesAsynchronouslyForTimes([NSValue(CMTime: time)]) { (requestedTime: CMTime, thumbnail: CGImage?, actualTime: CMTime, result: AVAssetImageGeneratorResult, error: NSError?) in
     print("error: \(error)")
     print("status: \(result)")

     if let thumbnailC = thumbnail {
          let image = UIImage(CGImage: thumbnailC)
     }

}
Kiran Jasvanee
  • 6,362
  • 1
  • 36
  • 52

1 Answers1

2

Try to set AVAssetImageGenerator's maximumSize property like this:

generator.maximumSize = CGSize(width: 320, height: 320)

Vladimir
  • 521
  • 5
  • 16
  • If the problem is not the quality, but the time taken for the operation, you may want to check this answer: http://stackoverflow.com/a/10225553/1502621 – Vladimir Feb 23 '17 at 09:46
  • Hi Vlad, I understood your point and I tried your link and answers on it. whereas **pascalbros** answer I tried, but still taking a same time. and **Nimit Parekh** answer won't help, because MPMoviePlayerController is deprecated on 9.0 – Kiran Jasvanee Feb 23 '17 at 10:14
  • Hi Vlad, please check this link: https://stackoverflow.com/questions/15360721/create-a-thumbnail-or-image-of-an-avplayer-at-current-time – Victor Ray Mar 24 '19 at 15:41