2012-04-06 56 views
9

我不得不從單獨的視頻幀提取YUV數據並將其保存在data[0],data[1],data[2];的幀大小爲640*480;現在我創造了pixelBuffer如下:CVOpenGLESTextureCacheCreateTextureFromImage返回-6683(kCVReturnPixelBufferNotOpenGLCompatible)

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不兼容」。這對我沒有多大幫助。

我該如何修復它?

+0

你有沒有想過這個?我有同樣的問題 – Hammer 2012-07-06 23:57:00

+0

我得到了同樣的錯誤。任何進展? – polyclick 2012-10-01 15:28:51

回答

1

您的源圖像/視頻幀是否具有2的冪的分辨率?如果沒有,您必須在創建紋理之前調整它的大小。

1

蘋果詳細介紹了這個確切問題Technical Q&A 1781

原因的問題是,源像素緩衝區必須IOSSurface支持。指定一個空字典作爲值kCVPixelBufferIOSurfacePropertiesKey