我从[_videoOutput copyPixelBufferForItemTime:[_ playerItem currentTime] itemTimeForDisplay:nil]收到CVPixelBuffer;并将此像素缓冲区传输到CVOpenGLESTextureCacheCreateTextureFromImage函数以创建亮度纹理或铬纹理
// Y-plane
glActiveTexture(GL_TEXTURE0);
err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault,_videoTextureCache, pixelBuffer, NULL, GL_TEXTURE_2D, GL_RED_EXT,width, height, GL_RED_EXT, GL_UNSIGNED_BYTE, 0, &outTexture);
if (err) {
NSLog(@"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err);
}
当我使用OpenGLES 2.0时,它有效,但改为OpenGLES 3.0,它将失败并打印一些错误,如下所示:
CVOpenGLESTextureCacheCreateTextureFromImage -6683出错 无法创建IOSurface图像(纹理)
OpenGLES 3.0 / 2.0代码:
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (!_context) {
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!_context) {
NSLog(@"Failed to create ES context");
}
_openGLESVer = OpenGLESVersion2;
}
答案 0 :(得分:1)
使用OpenGL ES 3.0时,您需要将GL_RED_EXT
替换为GL_LUMINANCE
,请考虑下面的代码(我在一年前在我的应用中使用它),它应该仅适用于pixelBuffer是yuv420sp是全范围还是视频范围。请注意,CVOpenGLESTextureCacheCreateTextureFromImage
不适用于yuv420p。
// Y-plane
glActiveTexture(GL_TEXTURE0);
err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault,_videoTextureCache, pixelBuffer, NULL, GL_TEXTURE_2D, GL_LUMINANCE,width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &outTexture);