Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用CVOpenGLESTextureCache将GLKView记录到mov文件_Ios_Opengl Es 2.0_Glkit - Fatal编程技术网

Ios 使用CVOpenGLESTextureCache将GLKView记录到mov文件

Ios 使用CVOpenGLESTextureCache将GLKView记录到mov文件,ios,opengl-es-2.0,glkit,Ios,Opengl Es 2.0,Glkit,我是opengl新手,我正在尝试录制GLKView,但迄今为止运气不佳。 这是我的密码: EAGLContext * _context = self.glkview.context; #if COREVIDEO_USE_EAGLCONTEXT_CLASS_IN_API CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, _context, NULL, &_videoTexture

我是opengl新手,我正在尝试录制GLKView,但迄今为止运气不佳。 这是我的密码:

     EAGLContext * _context = self.glkview.context;

#if COREVIDEO_USE_EAGLCONTEXT_CLASS_IN_API
    CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, _context, NULL, &_videoTextureCache);
#else
    CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)_context, NULL, &_videoTextureCache);
#endif
    if (err)
    {
        NSLog(@"Error at CVOpenGLESTextureCacheCreate %d", err);
        return;
    }


   CFDictionaryRef empty; // empty value for attr value.
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault, // our empty IOSurface properties dictionary
                           NULL,
                           NULL,
                           0,
                           &kCFTypeDictionaryKeyCallBacks,
                           &kCFTypeDictionaryValueCallBacks);
attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                  1,
                                  &kCFTypeDictionaryKeyCallBacks,
                                  &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(attrs,
                     kCVPixelBufferIOSurfacePropertiesKey,
                     empty);

// for simplicity, lets just say the image is 640x480
CVPixelBufferCreate(kCFAllocatorDefault, 640, 480,
                    kCVPixelFormatType_32BGRA,
                    attrs,
                    &renderTarget);
// in real life check the error return value of course.


// first create a texture from our renderTarget
// textureCache will be what you previously made with CVOpenGLESTextureCacheCreate
CVOpenGLESTextureRef renderTexture;
CVOpenGLESTextureCacheCreateTextureFromImage (
                                              kCFAllocatorDefault,
                                              _videoTextureCache,
                                              renderTarget,
                                              NULL, // texture attributes
                                              GL_TEXTURE_2D,
                                              GL_RGBA, // opengl format
                                              640,
                                              480,
                                              GL_BGRA, // native iOS format
                                              GL_UNSIGNED_BYTE,
                                              0,
                                              &renderTexture);
// check err value

// set the texture up like any other texture
glBindTexture(CVOpenGLESTextureGetTarget(renderTexture),
              CVOpenGLESTextureGetName(renderTexture));
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// bind the texture to the framebuffer you're going to render to 
// (boilerplate code to make a framebuffer not shown)

 glPixelStorei(GL_UNPACK_ALIGNMENT,4);

 glGenTextures(1, &_texureName);
 glBindTexture(GL_TEXTURE_2D, _texureName);
 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei) 1024, (GLsizei) 768, 0, GL_RGBA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(renderTarget));

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                       GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0);
这是将数据写入文件的方法

- (void)writeVideoFrameAtTime:(CMTime)time {

    if (_videoTextureCache == NULL)
        return;

        BOOL success = [_assetWriterPixelBufferInput appendPixelBuffer:renderTarget withPresentationTime:time];
        //NSLog(@"writing");
        if (!success) {
            NSLog(@"Pixel Buffer not appended");
        }

}

你可以试试这个,它是免费的,而且使用非常简单

如果您试图从视图中录制视频片段,以便以后以高帧速率播放,我可能有其他方法。哪种方法?我正在尝试创建一个mp4/mov电影文件。与在运行时从glk捕获不同,您可以将输入重新录制为游戏或正在播放的任何内容,然后重新启动模拟,在渲染到屏幕外帧缓冲区时在背景中播放-然后您可以将帧组装成视频。使用此方法可以获得1-10 fps,因为它在背景中。mm。。我需要在运行时录制屏幕,而不是用于游戏演示。