We have a method that extracts 1-second video image thumbnails using an AVAssetImageGenerator
.
After updating our devices to iOS/iPadOS 17, both the generateCGImagesAsynchronously(forTimes:completionHandler:)
and async images(for:)
methods take considerably longer than previous versions of iOS/iPadOS to asynchronously return images.
Running the code below on various devices with a 10 minute test video returned the following results:
iOS / iPadOS 16.7
- iPhone 13 Pro Max - 601 images extracted in 7.31719 seconds.
- iPad Pro (11-inch) (3rd generation) - 601 images extracted in 7.34210 seconds.
iOS / iPadOS 17.0.2
- iPhone 15 Pro Max - 601 images extracted in 22.80841 seconds.
- iPad mini (6th generation) - 601 images extracted in 26.94888 seconds.
iOS 17.1 Beta
- iPhone Xs Max - 601 images extracted in 38.74796 seconds.
(The iPhone Xs Max was returning only slighter better times when running iOS 17.0.2)
Has anyone else experienced this issue when running on iOS 17?
Task {
let path = Bundle.main.path(forResource: "10min_60fps", ofType: "mp4")!
let url = URL(filePath: path)
let asset = AVAsset(url: url)
let numFrames = Int(ceil(asset.duration.seconds))
let times = (0..<numFrames).map { CMTime(value: CMTimeValue($0 * 1000), timescale: 1000) } // 1 fps
let generator = AVAssetImageGenerator(asset: asset)
generator.requestedTimeToleranceBefore = .zero
generator.requestedTimeToleranceAfter = .zero
generator.appliesPreferredTrackTransform = true
generator.maximumSize = CGSize(width: 160 * 4, height: 90 * 4)
var images = generator.images(for: times)
var count = 0
let start = Date()
while await images.next() != nil {
count += 1
}
let duration = Date().timeIntervalSince(start)
let seconds = String(format: "%.5f", duration)
print("\(count) images extracted in \(seconds) seconds.")
}