Hi,
My application requires a mode where the contents of a view are captured and recorded to a video file. The view contains an animation that I want to capture, as well as various controls that the user interacts with.
I know how to capture a UIImage from a view using drawViewHierarchyInRect and UIGraphicsGetImageFromCurrentImageContext. I also know how to take a series of these images, along with the timestamps from when they were captured, and render them to a video file (the code for this is complex, but it relies on AVAssetWriterInputPixelBufferAdaptor).
The problem I'm having is performance. I'd like to capture 30fps, but even on an iPhone 7, the best I can manage with this scheme is 20.
Writing the captured images to the video file isn't the issue, as this is being done on a low priority background thread. The problem is that doing the initial image capture takes a long time, around 44 milliseconds, and it has to be done on the main thread, which causes the whole app to perform poorly. Is there a faster way to do this?
I considered using the snapshotViewAfterScreenUpdates function of UIView to snapshot the views, figuring I could save them in memory and render them later on a low-priority thread. But this doesn't work. When I try to extract a UIImage from a view snapshot, all I get is a blank image.
Any thoughts as to how this can be done more efficiently?
Thanks,
Frank