AVAssetImageGenerator使图像远离所需时间

时间:2018-04-12 13:12:41

标签: time avassetimagegenerator

我正在尝试将视频分割成多张照片,但是当我使用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

1 个答案:

答案 0 :(得分:0)

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