Xcode 导出Opengl ES视频
XCode能够从iPad上捕获Opengl ES帧,这太棒了!我想扩展此功能并捕获我的应用程序的整个Opengl ES电影。有办法吗?Xcode 导出Opengl ES视频,xcode,ipad,opengl-es,screen-grab,Xcode,Ipad,Opengl Es,Screen Grab,XCode能够从iPad上捕获Opengl ES帧,这太棒了!我想扩展此功能并捕获我的应用程序的整个Opengl ES电影。有办法吗? 如果使用XCode是不可能的,我怎么能不用花很多力气和对代码进行大的修改就可以做到呢?多谢各位 我使用了一种非常简单的技术,只需要几行代码 您可以使用以下代码将每个OGL帧捕获到UIImage中: - (UIImage*)captureScreen { NSInteger dataLength = framebufferWidth * framebuf
如果使用XCode是不可能的,我怎么能不用花很多力气和对代码进行大的修改就可以做到呢?多谢各位 我使用了一种非常简单的技术,只需要几行代码 您可以使用以下代码将每个OGL帧捕获到UIImage中:
- (UIImage*)captureScreen {
NSInteger dataLength = framebufferWidth * framebufferHeight * 4;
// Allocate array.
GLuint *buffer = (GLuint *) malloc(dataLength);
GLuint *resultsBuffer = (GLuint *)malloc(dataLength);
// Read data
glReadPixels(0, 0, framebufferWidth, framebufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// Flip vertical
for(int y = 0; y < framebufferHeight; y++) {
for(int x = 0; x < framebufferWidth; x++) {
resultsBuffer[x + y * framebufferWidth] = buffer[x + (framebufferHeight - 1 - y) * framebufferWidth];
}
}
free(buffer);
// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, resultsBuffer, dataLength, releaseScreenshotData);
// prep the ingredients
const int bitsPerComponent = 8;
const int bitsPerPixel = 4 * bitsPerComponent;
const int bytesPerRow = 4 * framebufferWidth;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(framebufferWidth, framebufferHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);
// then make the UIImage from that
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return image;
}
最后,您将拥有大量JPEG文件,这些文件可以通过
如果你想有一部30FPS的好电影,请将你的计算步长硬修复为每帧1/30.0秒。“XCode能够从iPad上捕获Opengl ES帧”-你指的是新的Opengl ES调试器吗?这不是一个真正的帧抓取器,你不能扩展它来做任何超出它当前功能的事情。是的,我说的是GL ES调试器。奇怪的是,它没有使用帧抓取器。那么,它模拟了所有的代码吗?无论如何,谢谢你!它与OpenGL ES驱动程序交互,以在您设置的各种断点处提取渲染和深度缓冲区信息,以及状态和其他设置。它不是一个捕获工具,而是一个调试器。你将无法使用它来录制你的应用程序。好的,那么没有其他方法来录制我的应用程序吗?另外一个方法是,你可以轻松使用AVAssetWriter将JPEG组装成电影。
- (void)onTimer {
// Compute and render new frame
[self update];
// Recording
if (recordingMode == RecordingModeMovie) {
recordingFrameNum++;
// Save frame
UIImage *image = [self captureScreen];
NSString *fileName = [NSString stringWithFormat:@"%d.jpg", (int)recordingFrameNum];
[UIImageJPEGRepresentation(image, 1.0) writeToFile:[basePath stringByAppendingPathComponent:fileName] atomically:NO];
}
}