我需要一个黑色的CMSampleBufferRef来测试。我使用这个代码。但它是一台白色的CMSampleBufferRef。
CVPixelBufferRef pixelBuffer=NULL;
CVPixelBufferCreate(kCFAllocatorDefault, 1280, 720, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);
CMSampleTimingInfo info ={ kCMTimeInvalid, kCMTimeZero, kCMTimeInvalid };
CMFormatDescriptionRef formatDesc=NULL;
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &formatDesc);
CMSampleBufferRef sampleBuffer=NULL;
CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault,
pixelBuffer,
formatDesc,
&info,
&sampleBuffer);如何使用CVPixelBufferCreate创建黑色CMSampleBufferRef?
发布于 2020-02-28 02:58:15
如果你在你的代码后面添加这个,它会用黑色像素填充像素缓冲区:
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);
UInt32* buffer = (UInt32*)CVPixelBufferGetBaseAddress(pixelBuffer);
for ( unsigned long i = 0; i < width * height; i++ )
{
buffer[i] = CFSwapInt32HostToBig(0x000000ff);
}
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);https://stackoverflow.com/questions/60418462
复制相似问题