AVCaptureVideoDataOutput videoSettings 与 kCVPixelBufferOpenGLESCompatibilityKey

AVCaptureVideoDataOutput videoSettings with kCVPixelBufferOpenGLESCompatibilityKey

我正在尝试从相机获取 openGL 兼容缓冲区。 我正在这样设置 AVCaptureVideoDataOutput:

_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。但仍然得到同样的错误。

您可能还需要添加一个空 kCVPixelBufferIOSurfacePropertiesKey

(NSString*) kCVPixelBufferIOSurfacePropertiesKey : @{}

如前所述here

不过我认为您不应该回避 CVOpenGLESTexture。 iOS GPU 和 CPU 内存是统一的,因此纹理缓存副本(可能)是免费的!