2017-06-01 126 views
1

我想從攝像頭獲得openGL兼容緩衝區。 我設立AVCaptureVideoDataOutput這樣的:AVCaptureVideoDataOutput videoSettings與kCVPixelBufferOpenGLESCompatibilityKey

_videoDataOutput = [[AVCaptureVideoDataOutput alloc] init]; 
    [_videoDataOutput setSampleBufferDelegate:self queue:_sessionQueue]; 
    // NSArray *pixelsFormats = _videoDataOutput.availableVideoCVPixelFormatTypes; 
    [_videoDataOutput setVideoSettings:@{ 
    (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA), 
    // Flag to enable emitting openGL frames from camera. 
    (NSString *)kCVPixelBufferOpenGLESCompatibilityKey : @(YES) 
    }]; 
    _videoDataOutput.alwaysDiscardsLateVideoFrames = YES; 

但我得到這個錯誤:

[AVCaptureVideoDataOutput setVideoSettings:] - videoSettings dictionary contains one or more unsupported (ignored) keys: (
    OpenGLESCompatibility 
) 

我可以使用kCVPixelBufferOpenGLESCompatibilityKey與AVCaptureVideoDataOutput? 如果不是從相機發出OpenGL兼容幀的最佳方式是什麼?

我已經考慮從CVImageBufferRef創建CVOpenGLESTextureRef,但是需要從CPU到GPU的緩衝區副本。我試圖避免這種情況。

注意:我嘗試從設置中刪除kCVPixelFormatType_32BGRA。但仍然有相同的錯誤。

回答

1

您可能還需要添加一個空kCVPixelBufferIOSurfacePropertiesKey

(NSString*) kCVPixelBufferIOSurfacePropertiesKey : @{} 

提到here

不過,我不認爲你應該回避CVOpenGLESTexture S時。在iOS上,GPU和CPU內存是統一的,因此紋理緩存副本(可能)是免費的!

+0

謝謝我不知道在iOS上GPU和CPU共享相同的地址空間。 – user1150393

相關問題