I want to modify the contents of CMSampleBuffer and then write it to a file with AVAssetWriter/AVAssetWriterInput.
The way I do this is by creating a Core Graphics bitmap context and then drawing into it, but it’s way too slow. Specifically, I need to draw an image into the buffer.
So can one provide some sort of a hint or suggestion on how to do it more efficiently?
I thought about using OpenGL to accomplish that, that is, first create a texture A from CMSampleBuffer. Then render texture B, created from image I want to draw, into texture A, then retrieve the data backing the texture A from OpenGL and finally hand that data over to AVAssetWriter/AVAssetWriterInput. But the docs say that transferring texture data from GPU back to CPU is kinda expensive.
So, any suggestions on how to approach that?
Thanks in advance
OpenGL is probably the way to go. It might be slightly more efficient to render to an offscreen framebuffer rather than a texture, though.
To extract a texture from a sample buffer:
To process the texture through OpenGL, you could then do something like this: