我正在iOS上做一个视频播放器项目。
它使用AVFoundation从视频文件中提取CVPixelBuffer,然后将该缓冲区作为纹理发送到OpenGL。
概念证明代码是受苹果的示例代码启发的.AVFoundation在YCbCr颜色空间中提供每个帧,需要将其转换为RGB以在OpenGL中呈现。根据不同的YCbCr标准(例如国际电联-R BT.709、ITU BT.601),这种转换似乎有多个转换矩阵选项。示例代码通过以下代码确定要使用的代码:
CFTypeRef colorAttachments = CVBufferGetAttachment(pixelBuffer,kCVImageBufferYCbCrMatrixKey,NULL);if (colorAttachments == kCVImageBufferYCbCrMatrix_ITU_R_601_4) { _preferredConversion = kColorConversion601;}pixelBuffer= kColorConversion709;}
但是,我使用的是colorAttachment,返回的Unmanaged<CFTypeRef>是类型的,而常数的kCVImageBufferYCbCrMatrix_ITU_R_601_4是CFString类型的,所以它们不能直接相等。我做了一些研究,结果是:
CFEqual(colorAttachments, kCVImageBufferYCbCrMatrix_ITU_R_601_4) // returns false
CFEqual(colorAttachments, kCVImageBufferYCbCrMatrix_ITU_R_709_2) // returns false too!!
//-----------------------------------------
CFGetType(colorAttachments) // returns 1
CFStringGetType() // returns 7, note kCVImageBufferYCbCrMatrix_ITU_R_601_4 is of type CFString
// so I still can't check their equality
// because the retrieved colorAttachments is not of type CFString at all我尝试了两个变换,通过硬编码矩阵和结果(渲染场景)似乎没有区别,这是可以预见的,因为这两个变换矩阵并没有太大的差别。
我的问题:
发布于 2018-01-31 14:44:33
使用takeUnretainedValue()将为您提供一个CFTypeRef。然后,这需要从下浇到CFString。例如,代码可能如下所示:
if let colorAttachment = CVBufferGetAttachment(image, kCVImageBufferYCbCrMatrixKey, nil)?.takeUnretainedValue(),
CFGetTypeID(colorAttachment) == CFStringGetTypeID() {
let colorAttachmentString = colorAttachment as! CFString
print(colorAttachmentString)
print(colorAttachmentString == kCVImageBufferYCbCrMatrix_ITU_R_601_4)
print(colorAttachmentString == kCVImageBufferYCbCrMatrix_ITU_R_709_2)
}其中的指纹:
ITU_R_601_4
true
falsehttps://stackoverflow.com/questions/41217608
复制相似问题