CVOpenGLESTextureCacheCreateTextureFromImage返回-6683(kCVReturnPixelBufferNotOpenGLCompatible)

时间:2012-04-06 17:48:19

标签: iphone opengl-es yuv

我分别从视频帧中提取了Y U V数据并将其保存在data[0],data[1],data[2];中。帧大小为640*480;现在我创建了pixelBuffer,如下所示:

void *pYUV[3] = {data[0], data[1], data[2]};
size_t planeWidth = {640, 320, 320};
size_t planeHeight = {480, 240, 240};
size_t planeBytesPerRow = {640, 320, 320};
CVReturn renturn = CVPixelBufferCreateWithPlanarBytes(kCFAllocatorDefault,
                                   640, 
                                   480,
                                   kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, 
                                   nil,
                                   nil,
                                   3, 
                                   pYUV,
                                   planeWidth,
                                   planeHeight, 
                                   planeBytesPerRow, 
                                   nil,
                                   nil, nil, &_pixelBuffer);
CVPixelBufferLockBaseAddress(_pixelBuffer, 0);
CVPixelBufferRetain(_pixelBuffer);
    // Periodic texture cache flush every frame
CVOpenGLESTextureCacheFlush(_textureCache, 0);

// The Buffer cannot be used with OpenGL as either its size, pixelformat or attributes are not supported by OpenGL
 glActiveTexture(GL_TEXTURE0);
CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, 
                                                            _textureCache,
                                                            _pixelBuffer,
                                                            NULL,
                                                            GL_TEXTURE_2D,
                                                            GL_LUMINANCE,
                                                            im.width,
                                                            im.height,
                                                            GL_LUMINANCE,
                                                            GL_UNSIGNED_BYTE,
                                                            0,
                                                            &_yTexture);

if (!_yTexture || err) {
    NSLog(@"CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err);  
    return;
}
glBindTexture(CVOpenGLESTextureGetTarget(_yTexture), CVOpenGLESTextureGetName(_yTexture));
 CVPixelBufferUnlockBaseAddress(_pixelBuffer, 0);

但错误是-6638,文档只是声明“由于不支持的缓冲区大小,像素格式或属性,像素缓冲区与OpenGL不兼容。”这对我没有多大帮助。

我该如何解决?

2 个答案:

答案 0 :(得分:1)

您的源图像/视频帧的分辨率是2的幂吗?如果没有,则必须在创建纹理之前调整其大小。

答案 1 :(得分:1)

Apple在Technical Q&A 1781

中详细说明了此问题的原因

问题是源像素缓冲区必须是IOSSurface支持的。指定一个空字典作为kCVPixelBufferIOSurfacePropertiesKey

中的值