title: Converting RGBA to ARGB (glReadPixels -> AVAssetWriter)
body: <p>I want to record images, rendered with OpenGL, into a movie-file with the help of <code>AVAssetWriter</code>. The problem arises, that the only way to access pixels from an OpenGL framebuffer is by using glReadPixels, which only supports the RGBA-pixel format on iOS. But <code>AVAssetWriter</code> doesn't support this format. Here I can either use ARGB or BGRA. As the alpha-values can be ignored, I came to the conclusion, that the fastest way to convert RGBA to ARGB would be to give glReadPixels the buffer shifted by one byte:</p>
  
  <pre><code>UInt8 *buffer = malloc(width*height*4+1);
  glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer+1);
  </code></pre>
  
  <p>The problem is, that the <code>glReadPixels</code> call leads to a <code>EXC_BAD_ACCESS</code> crash. If I don't shift the buffer by one byte, it works perfectly (but obviously with wrong colors in the video-file). What's the problem here?</p>