AVAssetImageGenerator 将图像提供给远离所需时间的图像

AVAssetImageGenerator gives image to far away from desired time

我正在尝试将视频分割成多张照片,但是当我使用 AVAssetImageGenerator 时,我只能获取 0.0s、0.5s、0.1s 等的照片

但是我怎样才能得到例如每秒 10 张照片?

let imageGenerator = AVAssetImageGenerator(asset: asset)
        imageGenerator.appliesPreferredTrackTransform = true

        var times = [NSValue]()
        for i in 0..<5 {
            let t = Double(i) / 5 * 60
            times.append(NSValue(time: CMTimeMake(Int64(t), 60)))
        }

        imageGenerator.generateCGImagesAsynchronously(forTimes: times) { (time, imageRef, time2, result, error) in

结果帧时间

time time2
0.0 0.0
0.2 0.0
0.4 0.5005
0.6 0.5005
0.8 1.001

它由

修复
imageGenerator.requestedTimeToleranceAfter = CMTimeMake(1, 60)
imageGenerator.requestedTimeToleranceBefore = CMTimeMake(1, 60)