2012-04-06 19 views
9

tôi đã chiết xuất YUV dữ liệu từ khung video riêng biệt và lưu chúng trong data[0],data[1],data[2]; Kích thước khung là 640*480; Bây giờ tôi tạo các pixelBuffer như sau:CVOpenGLESTextureCacheCreateTextureFromImage trở -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); 

Nhưng err là -6638 , tài liệu chỉ đơn giản nói rằng "Bộ đệm pixel không tương thích với OpenGL do kích thước bộ đệm không được hỗ trợ, định dạng pixel hoặc thuộc tính". mà không giúp tôi nhiều.

Làm cách nào để khắc phục sự cố?

+0

Bạn đã bao giờ tìm ra điều này chưa? Tôi gặp vấn đề tương tự – Hammer

+0

Tôi gặp lỗi tương tự. Bất kỳ tiến bộ nào? – polyclick

Trả lời

1

Khung hình/video nguồn của bạn có độ phân giải là sức mạnh của 2 không? Nếu không, bạn phải thay đổi kích thước nó trước khi tạo texture.

1

của Apple Các chi tiết về nguyên nhân của vấn đề này chính xác trong Technical Q&A 1781

Vấn đề là pixel đệm nguồn phải được IOSSurface hậu thuẫn. Chỉ định một từ điển trống làm giá trị trong kCVPixelBufferIOSurfacePropertiesKey