title: The most efficient way to modify CMSampleBuffer contents
body: <p>I want to modify the contents of CMSampleBuffer and then write it to a file with AVAssetWriter/AVAssetWriterInput.</p>
  
  <p>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.</p>
  
  <p>So can one provide some sort of a hint or suggestion on how to do it more efficiently?</p>
  
  <p>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.</p>
  
  <p>So, any suggestions on how to approach that?</p>
  
  <p>Thanks in advance</p>