我正在为iPhone开发视频播放器。我使用ffmpeg库来解码视频帧,我使用opengl 2.0将帧渲染到屏幕上。来自uint8_t缓冲区的CVOpenGLESTextureCacheCreateTextureFromImage
但我的渲染方法是非常缓慢的。
一位用户告诉我: iOS 5包含一种快速执行此操作的新方法。诀窍是使用AVFoundation并将核心视频像素缓冲区直接链接到OpenGL纹理。
我现在的问题是,我的视频播放器发送呈现方法一个uint8_t *类型,然后我用glTexSubImage2D。
但是,如果我想使用CVOpenGLESTextureCacheCreateTextureFromImage我需要一个CVImageBufferRef与框架。
问题是:如何从uint8_t缓冲区创建CVImageBufferRef?
这是我的渲染方法:
- (void) render: (uint8_t*) buffer
{
的NSLog(@ “渲染”);
[EAGLContext setCurrentContext:context];
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// OpenGL loads textures lazily so accessing the buffer is deferred until draw; notify
// the movie player that we're done with the texture after glDrawArrays.
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mFrameW, mFrameH, GL_RGB,GL_UNSIGNED_SHORT_5_6_5, buffer);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
[moviePlayerDelegate bufferDone];
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
感谢,