I am trying to create a small macOS application that grabs a bunch of frames from a video depending on a timing factor, the video is dragged from the user computer and dropped into the application, something similar to the movie editors (e.g iMovie)
ex: factor = 5 -> get a frame each 5 seconds.
Currently I am using this code from AVAssetImageGenerator
:
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
imageGenerator.requestedTimeToleranceAfter = .zero
imageGenerator.requestedTimeToleranceBefore = .zero
imageGenerator.generateCGImagesAsynchronously(forTimes: times) { requestedTime, cgImage, _, _, _ in
// Do Something with CGImage
}
However, this function seems to take a lot of time to be finished especially that I am passing 6 different factors from 1 to 6.
This calculation should be fast, the user shouldn't wait a lot especially if he has like 120 min video :)
The question is, can we use Metal to run the code above on GPU in order to make it faster? and how other software generate frames quickly without any delay?