我正在研究一个项目,在该项目中,我使用AVCaptureSession
捕获用户的视频输入。问题是我需要BGRA格式的输出来使用OPENCV渲染,但是然后我需要将其更改回默认的420F格式,以向用户显示。因此,我将videoSettings
中的PixelFormatType
设置为kCVPixelFormatType_32BGRA
,
[videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
,我想在CaptureOutput中将示例缓冲区转换为420F:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
[self doSomeOpenCV:sampleBuffer]; // the OpenCV part
//convert sampleBuffer to kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
}
有没有办法这样做?也许,有一个函数可以给定输入以指定格式返回SampleBuffer?
为什么不使用AVSampleBufferDisplayLayer
显示您的BGRA样品缓冲区和Ditch WebRTC(至少出于显示目的(?
如果您不想这样做,您当然可以将BGRA缓冲区转换为YUV,甚至可以在GPU上有效地进行效率,但是最好的转换不是转换,除了谁想键入那么多在iPad屏幕键盘上?