title: Render movie to a OpenGL texture in iOS
body: <p>Is it possible to render a movie to an OpenGL texture in real time using the Apple iOS frameworks?
  I've seen it in an <a href="http://nehe.gamedev.net/tutorial/playing_avi_files_in_opengl/23001/" rel="nofollow">old NeHe tutorial</a> using glTexSubImage2D, but I'm wondering how can I access the RGB data using the Apple frameworks?</p>
  
  <p>init</p>
  
  <pre><code>NSString *mPath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"];
  NSURL *url = [NSURL fileURLWithPath:mPath];
  NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
  AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:options];
  
  imgGen = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
  imgGen.requestedTimeToleranceBefore = kCMTimeZero;
  imgGen.requestedTimeToleranceAfter = kCMTimeZero;
  </code></pre>
  
  <p>each frame</p>
  
  <pre><code>double time = 0.xyz * asset.duration;
  
  CMTime reqTime = CMTimeMakeWithSeconds (time, preferredTimeScale), actTime;
  NSError *err = nil;
  CGImageRef ref = [imgGen actualTime:&amp;actTime error:&amp;err];
  
  //... GL calls to make an image from the CGImageRef
  </code></pre>
  
  <p>This method is incredibly slow for realtime rendering, and I can only generate ~15 frames.  One way may be to generate frames on the fly asynchronsly, but surely it can be done in real time?  The most time consuming part is the copyCGImageAtTime call.</p>