現在、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);
}
支援を提供できる人に感謝します。同様の問題があることは承知していますが(まったく同じではありません)、この問題も非常に古く、応答がありません。私は自分の状況にもっと幸運を祈っています。