开发者

Render movie to a OpenGL texture in iOS

开发者 https://www.devze.com 2023-03-27 00:23 出处:网络
Is it possible to render a movie to an OpenGL texture in real time开发者_高级运维 using the Apple iOS frameworks?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号