CVOpenGLESTextureCacheCreateTextureFromImage return -6683(kCVReturnPixelBufferNotOpenGLCompatible)

不想你离开。 提交于 2019-12-04 00:10:35

问题


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);

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.

How can I fixed it?


回答1:


Does your source image/video frame have a resolution which is a power of 2? If not, you must resize it before creating the texture.




回答2:


Apple details the cause of this exact issue in Technical Q&A 1781

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



来源:https://stackoverflow.com/questions/10047159/cvopenglestexturecachecreatetexturefromimage-return-6683kcvreturnpixelbufferno

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!