objective-c - 如何使用 CVPixelBufferCreate 创建黑色的 CMSampleBufferRef?
问题描述
我需要一个黑色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?
解决方案
如果在代码之后添加它,它将用黑色像素填充像素缓冲区:
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);
推荐阅读
- php - MacPorts 不会切换 PHP 版本
- java - Android Studio Java 模块未找到依赖项
- vba - 向不同单元格之间移动的数据添加文本
- java - 向 List 添加新元素会替换以前的元素
- php - Wordpress 中管理员用户的仅查看模式
- javascript - 如何在 html 表格中的某个位置插入 's?
- ldap - python-ldap:仅从 LDAP 搜索中检索几个条目
- javascript - 如何检查 div 是否包含某些文本?
- javascript - UI5 应用程序(在 WebIDE 中):sap.m.ColumnListItem:根据一列中的值更改整行颜色:出了什么问题?
- c# - FileSystemWatcher.Created 无法正常工作