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 old NeHe tutorial using glTexSubImage2D, but I'm wondering how can I access the RGB data using the Apple frameworks?
init
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;
each frame
double time = 0.xyz * asset.duration;
CMTime reqTime = CMTimeMakeWithSeconds (time, preferredTimeScale), actTime;
NSError *err = nil;
CGImageRef ref = [imgGen actualTime:&actTime error:&err];
//... GL calls to make an image from the CGImageRef
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.
精彩评论