I have a requirement to take a video, convert each frame to and image and save these images to disk. I'd like to use AVAssetImageGenerator
for efficiency's sake, and have code similar to the following:
The issue is that I don't know when all image generation is complete, but I need to take action once all frames are written to disk. For example:
assetGenerator.generateCGImagesAsynchronously(forTimes: frameTimes, completionHandler: { (requestedTime, image, actualTime, result, error) in
// 1. Keep a reference to each image
// 2. Wait until all images are generated
// 3. Process images as a set
})
It's step 2 above that's tripping me up. I imagine I can try to count the number of times the completion handler gets called, and trigger the appropriate method when the count equals the number of frames.
But I'm wondering if there's a way to use the API to know when every frame has been processed? Maybe just something I've missed? Any guidance or advice would be appreciated.