gpt4 book ai didi

avfoundation - CMSampleBufferGetImageBuffer 返回空

转载 作者:行者123 更新时间:2023-12-04 05:23:13 30 4
gpt4 key购买 nike

我正在尝试从 CMSampleBufferRef 检索 CVPixelBufferRef,以便更改 CVPixelBufferRef 以动态覆盖水印。

我正在使用 CMSampleBufferGetImageBuffer(sampleBuffer) 来实现这一点。我正在打印返回的 CVPixelBufferRef 的结果,但它始终为空。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

NSLog(@"PixelBuffer %@",pixelBuffer);
...

}

我还缺少什么吗?

最佳答案

经过数小时的调试,结果证明样本可能是视频或音频样本。因此,尝试从音频缓冲区获取 CVPixelBufferRef 会返回 null。

我在继续之前通过检查样本类型解决了这个问题。由于我对音频样本不感兴趣,所以我只是在它是音频样本时返回。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

CMFormatDescriptionRef formatDesc = CMSampleBufferGetFormatDescription(sampleBuffer);
CMMediaType mediaType = CMFormatDescriptionGetMediaType(formatDesc);

//Checking sample type before proceeding
if (mediaType == kCMMediaType_Audio)
{return;}

//Processing the sample...

}

关于avfoundation - CMSampleBufferGetImageBuffer 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38591957/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com