I am trying to generate thumbnail images from a video using the following code. It does generate UIImages but the images are all the same at different time. For example, for a video which lasts 3 seconds, it will generate 6 images but all the images are the same image for the very beginning of the video. Any ideas on what I did wrong?
let asset = AVAsset(url: videoURL)
let imageGenerator = AVAssetImageGenerator(asset: asset)
let scale = 2
let step = 1
let duration = Int(CMTimeGetSeconds(asset.duration) * Double(scale))
var epoches = [NSValue]()
for i in stride(from: 1, to: duration, by: step) {
//let time = CMTimeMake(Int64(i), Int32(scale))
let time = CMTimeMakeWithSeconds(Double(i)/Double(scale), Int32(scale))
let cgImage = try! imageGenerator.copyCGImage(at: time, actualTime: nil)
let uiImage = UIImage(cgImage: cgImage)
self?.imagePool.append(uiImage)
epoches.append(NSValue(time: time))
}