My app is displaying video on iOS, currently using AVSampleBufferDisplayLayer. Before video is shown on screen I need to add barrel distortion effect to it. How to do it efficiently? There is no easy way to manipulate CALayer contents without significant performance penalty. Requirement for video is 1920x1080 at 60 frames per second.
First alternative was to use VTDecompressionSession instead of AVSampleBufferDisplayLayer and use OpenGL shaders for distortion. But it looks like reading frames back from GPU is quite slow, it takes 20-25 milliseconds per frame for decoding and reading the YUV data.
Second alternative was using software video decoding and then OpenGL shaders. This is actually faster than using VTDecompressionSession but will kill the battery very quickly.
Third alternative would to apply CIFilter to CALayer, but according to documentation this is not supported on iOS.
Fourth approach would be to render to offscreen using UIView's renderInContext-method. Haven't tried this yet but it is probably as slow as reading YUV-data. Is there a better alternative to manipulate CALayer contents or other way to distort image with good performance? Looks like reading data from GPU is slow and should be avoided.