我正在爲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];
}
感謝,