Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestions about CVOpenGLESTextureCacheCreateTextureFromImage
    text
    copied!<p>I attempt to extract yuv data from the pixel buffer received from camera and then re-create a pixel buffer, but I got -6683 at CVOpenGLESTextureCacheCreateTextureFromImage, the documentation simply states that </p> <blockquote> <p>The pixel buffer is not compatible with OpenGL due to an unsupported buffer size, pixel format, or attribute.</p> </blockquote> <p>Which does not help me much. How can I fix it? The code as below:</p> <pre><code>- (void)Init { *****; OSStatus err = CMBufferQueueCreate(kCFAllocatorDefault, 1, CMBufferQueueGetCallbacksForUnsortedSampleBuffers(), &amp;previewBufferQueue); } - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { OSStatus err = CMBufferQueueEnqueue(previewBufferQueue, sampleBuffer); if ( !err ) { dispatch_async(dispatch_get_main_queue(), ^{ CMSampleBufferRef sbuf = (CMSampleBufferRef)CMBufferQueueDequeueAndRetain(previewBufferQueue); if (sbuf) { CVImageBufferRef pixBuf = CMSampleBufferGetImageBuffer(sbuf); [self.delegate displayPixelBuffer:pixBuf]; CFRelease(sbuf); } }); } } </code></pre> <p>The displayPixelBuffer method:</p> <pre><code>-(void)displayPixelBuffer:(CVImageBufferRef)pixelBuffer { CVPixelBufferLockBaseAddress(pixelBuffer, 0); size_t planeWidth[2] = {CVPixelBufferGetWidthOfPlane(pixelBuffer, 0), width}; size_t planeHeight[2] = {CVPixelBufferGetHeightOfPlane(pixelBuffer, 0), CVPixelBufferGetHeightOfPlane(pixelBuffer, 1)}; size_t planeBytesPerRow[2] = {CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0), width/2}; unsigned char *YUV2[2] = {0}; YUV2[0] = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0); YUV2[1] = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1); CVReturn renturn = CVPixelBufferCreateWithPlanarBytes(kCFAllocatorDefault, width, height, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, 0, 0, 2, (void *)YUV2, planeWidth, planeHeight, planeBytesPerRow, nil, nil, nil, &amp;imageBuffer); glActiveTexture(GL_TEXTURE0); CVOpenGLESTextureRef texture = NULL; CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, videoTextureCache, imageBuffer, NULL, GL_TEXTURE_2D, GL_LUMINANCE, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &amp;texture); if (!texture || err) { NSLog(@"CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err); return; } glBindTexture(CVOpenGLESTextureGetTarget(texture), 0); // Flush the CVOpenGLESTexture cache and release the texture CVOpenGLESTextureCacheFlush(videoTextureCache, 0); CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); CFRelease(texture); } </code></pre> <p>The result is CVOpenGLESTextureCacheCreateTextureFromImage failed(error:-6683), why?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload