我一直在努力让read()
发挥作用。
我有一个4通道的8位BGRA编码矩阵,我想将其转换为AVSampleBufferDisplayLayer
,并使用以下代码:
CMSampleBufferRef
在调试器中检查- (CMSampleBufferRef) convertGBRAToCMSampleBuffer:(cv::Mat) bgraImage
{
CVPixelBufferRef pixelBuffer;
CMSampleBufferRef sampleBuffer;
CMSampleTimingInfo timingInfo = { CMTimeMake(1, 60), kCMTimeZero, kCMTimeInvalid };
CMVideoFormatDescriptionRef videoFormatDescription;
size_t width = bgraImage.cols;
size_t height = bgraImage.rows;
size_t bytesPerRow = width*bgraImage.elemSize();
CVPixelBufferCreateWithBytes(
kCFAllocatorDefault,
width,
height,
kCVPixelFormatType_32BGRA,
bgraImage.data,
bytesPerRow,
nil,
nil,
nil,
&pixelBuffer);
CMVideoFormatDescriptionCreateForImageBuffer(
kCFAllocatorDefault,
pixelBuffer,
&videoFormatDescription);
CMSampleBufferCreateForImageBuffer(
kCFAllocatorDefault,
pixelBuffer,
YES,
nil,
nil,
videoFormatDescription,
&timingInfo,
&sampleBuffer);
return sampleBuffer;
}
可以正确渲染图像,但是,当我将pixelBuffer
排入sampleBuffer
时,由于某种原因,我总是会出现白屏。我不太确定自己实现AVSampleBufferDisplayLayer
的方式,但是环顾四周,这似乎是我所需要的。
任何关于为什么我总是会出现白屏的专家建议将受到高度赞赏。
谢谢