ios - CVOpenGLESTextureCacheCreateTextureFromImage 返回错误 6683

标签 ios opengl-es-2.0 yuv

我目前正在尝试使用 YUV420 格式(双平面)在 openGL 中绘制图像。我收到原始数据,并试图将其解析为 CVPixelBuffer,然后使用 CVOpenGLESTextureCacheCreateTextureFromImage 传递所述缓冲区。虽然我在解析到 CVPixelBuffer 时没有收到任何错误,但在尝试传递到 CVOpenGLESTextureCacheCreateTextureFromImage 时收到错误 (-6683)。我正在尽最大努力遵循苹果的 GLCameraRipple 示例代码 - 再次不同的是,我使用的是原始图像数据而不是来自相机的数据。

希望有人可以解释我在这里缺少的是什么 - 我认为它是一个缺少的属性...

仅供引用,平面 0 是 Y 平面,平面 1 是 UV 平面 - 其中 UV 平面应该是 Y 平面宽度和高度的一半。

size_t numPlanes = image->GetNumPlanes();
size_t planeWidth[numPlanes];
size_t planeHeight[numPlanes];
size_t scanWidth[numPlanes];
void *planeIndex[numPlanes];
for(int i = 0; i<numPlanes; i++){
    i<1 ? planeWidth[i] = image->GetWidth() : planeWidth[i] = image->GetWidth()/2;
    i<1 ? planeHeight[i] = image->GetHeight() : planeWidth[i] = image->GetHeight()/2;
    scanWidth[i] = image->GetScanWidth(i);
    planeIndex[i] = image->GetPlanePointer(i);
}

CVPixelBufferRef pixelBuffer;
CFDictionaryRef empty;
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault,
                           NULL,
                           NULL,
                           0,
                           &kCFTypeDictionaryKeyCallBacks,
                           &kCFTypeDictionaryValueCallBacks);

attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                  1,
                                  &kCFTypeDictionaryKeyCallBacks,
                                  &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(attrs, kCVPixelBufferIOSurfacePropertiesKey, empty);



CVReturn cvError = CVPixelBufferCreateWithPlanarBytes(kCFAllocatorDefault,
                                                      image->GetWidth(),
                                                      image->GetHeight(),
                                                      kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
                                                      nil,
                                                      nil,
                                                      numPlanes,
                                                      planeIndex,
                                                      planeWidth,
                                                      planeHeight,
                                                      scanWidth,
                                                      nil, nil, attrs, &pixelBuffer);
if(cvError) NSLog(@"Error at CVPixelBufferCreateWithPlanarBytes:  %d", cvError);

CVReturn err;
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);

if (!_videoTextureCache)
{
    NSLog(@"No video texture cache");
    return;
}

if (_bModel == nil ||
    width != _textureWidth ||
    height != _textureHeight)
{
    _textureWidth = width;
    _textureHeight = height;

    _bModel = [[BufferModel alloc] initWithScreenWidth:_screenWidth
                                          screenHeight:_screenHeight
                                            meshFactor:_meshFactor
                                          textureWidth:_textureWidth
                                         textureHeight:_textureHeight];

    [self setupBuffers];
}

[self cleanUpTextures];

// CVOpenGLESTextureCacheCreateTextureFromImage will create GLES texture
// optimally from CVImageBufferRef.

// Y-plane
glActiveTexture(GL_TEXTURE0);
err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
                                                   _videoTextureCache,
                                                   pixelBuffer,
                                                   NULL,
                                                   GL_TEXTURE_2D,
                                                   GL_RED_EXT,
                                                   _textureWidth,
                                                   _textureHeight,
                                                   GL_RED_EXT,
                                                   GL_UNSIGNED_BYTE,
                                                   0,
                                                   &_lumaTexture);
if (err)
{
    NSLog(@"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err);
}

感谢任何能够提供帮助的人。 虽然我知道有一个类似的问题(不完全相同),但所说的问题也很老,从未收到任何回复。我希望我的情况能有更多好运。

最佳答案

您创建的 CVPixelBuffer 中的 iosurface 属性为 null。

手动创建:

<CVPixelBuffer 0x1fd52790 width=1280 height=720 pixelFormat=420v iosurface=0x0 planes=2>

由 CMSampleBufferGetImageBuffer 创建:

<CVPixelBuffer 0x1fd521e0 width=1280 height=720 pixelFormat=420f iosurface=0x21621c54 planes=2>

据我所知,没有解决方案。

关于ios - CVOpenGLESTextureCacheCreateTextureFromImage 返回错误 6683,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12646273/

相关文章:

ios - Opengl ES - 绘制多个对象的最佳方法是什么

ios - 如何创建一个精度为 0.1 秒的计时器?

ios - 如何在 swift 中解析整个 rss feed xml 数据

opengl-es - glGetShaderInfoLog 返回空字符串,但着色器程序未正确链接

android - 透明纹理帧缓冲区 (OpenGL ES 2)

opengl-es - 如何在 OpenGL ES 中不转换 rgb 显示 yuv 格式的数据?

ffmpeg - 无损RGB24到YUV444转换

python-3.x - 使用ffmpeg从MP4文件中仅提取Y(YUV420p)帧?

ios - Swift:通过深度链接到 Twitter 应用程序将图像共享到 Twitter

ios - 如何在iOS中的动画图像上放置按钮?