CVOpenGLESTextureCacheCreateTextureFromImage返回错误6683 [英] CVOpenGLESTextureCacheCreateTextureFromImage returns error 6683

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

问题描述

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

I am currently attempting to draw an image in openGL using YUV420 format (bi-planar). I receive raw data, and am attempting to parse it into a CVPixelBuffer, and then pass said buffer using CVOpenGLESTextureCacheCreateTextureFromImage. While I receive no errors when parsing into the CVPixelBuffer, I receive an error (-6683) when trying to pass into CVOpenGLESTextureCacheCreateTextureFromImage. I'm trying my best to follow apple's GLCameraRipple sample code - except again, I'm using raw image data instead of data from the camera.

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

Hopefully someone can explain what it is that I'm missing here - I assume it's a missing attribute...

仅供参考,平面0是Y平面,平面1是UV平面-UV平面应为Y平面的宽度和高度的一半.

FYI, plane 0 is the Y plane and plane 1 is the UV plane - where the UV plane should be half the width and height of the Y plane.

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

感谢任何能够提供帮助的人. 虽然我知道有一个类似的问题(不太一样),但所说的问题也很老,从未收到任何回应.我希望自己的情况能有更多的运气.

Thank you to anyone able to offer assistance. And while I'm aware there is an issue similar (not quite the same), said issue is also quite old and never received any responses. I'm hoping for more luck for my situation.

推荐答案

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

The iosurface property is null in the CVPixelBuffer you've created.

手动创建:

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

由CMSampleBufferGetImageBuffer创建:

Created by CMSampleBufferGetImageBuffer:

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

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

To my knowledge there is no solution.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆