0

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

1 回答 1

1

它是由

imageGenerator.requestedTimeToleranceAfter = CMTimeMake(1, 60)
imageGenerator.requestedTimeToleranceBefore = CMTimeMake(1, 60)
于 2018-04-16T13:56:07.863 回答