本文介绍了CVOpenGLESTextureCacheCreateTextureFromImage返回-6683(kCVReturnPixelBufferNotOpenGLCompatible)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had extract Y U V data from video frame separately and saved them in data[0],data[1],data[2];The frame size is 640*480;Now I creat the pixelBuffer as below:

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不兼容由于缓冲区大小,像素格式或属性不受支持。这对我没有多大帮助。

But the err is -6638, the documentation simply states that "The pixel buffer is not compatible with OpenGL due to an unsupported buffer size, pixel format, or attribute." which does not help me much.

我该如何解决?

推荐答案

Apple在

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

The issue is that the source pixel buffer must be IOSSurface backed. Specify an empty dictionary as the value in kCVPixelBufferIOSurfacePropertiesKey

这篇关于CVOpenGLESTextureCacheCreateTextureFromImage返回-6683(kCVReturnPixelBufferNotOpenGLCompatible)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:20