我正在使用此代码创建CMVideoFormatDescriptionRef
:
CMVideoDimensions dimensions = {
.width = width,
.height = height
};
CMVideoFormatDescriptionRef videoInfo = NULL;
NSDictionary *options2 = [NSDictionary dictionaryWithObjectsAndKeys:
@(YES), kCVPixelBufferCGImageCompatibilityKey,
@(YES), kCVPixelBufferCGBitmapContextCompatibilityKey,
dimensions, kCVImageBufferDisplayDimensionsKey,
nil];
CFDictionaryRef dictOptionsRef = (__bridge CFDictionaryRef)options2;
CMFormatDescriptionCreate(kCFAllocatorDefault, kCMMediaType_Video, 'brga', dictOptionsRef, &videoInfo);
我需要将该字典传递给CMFormatDescriptionCreate
。
问题是最后一行
dimensions, kCVImageBufferDisplayDimensionsKey,
这不是将dimensions
添加到该字典的正确方法。它崩溃了应用程序。
我试图用{:1}}将整个事情包裹起来:
NSValue
它在理论上有效,没有崩溃,但NSValue *miValue = [NSValue value: &dimensions
withObjCType:@encode(CMVideoDimensions)];
未正确创建(OSStatus -12731)。如果我从字典中删除最后一行,则会创建videoInfo
,但没有维度的定义,假定为0x0像素或videoInfo
。见下文:
codecType
来自常规<CMVideoFormatDescription 0x17044c270 [0x1b0330bb8]> {
mediaType:'vide'
mediaSubType:'brga'
mediaSpecific: {
codecType: 0 dimensions: 0 x 0 <--HERE!!!
}
extensions: {<CFBasicHash 0x17086dcc0 [0x1b0330bb8]>{type = immutable dict, count = 4,
entries =>
0 : <CFString 0x1aa9427c8 [0x1b0330bb8]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0x1aa942808 [0x1b0330bb8]>{contents = "ITU_R_601_4"}
3 : <CFString 0x1aa942c68 [0x1b0330bb8]>{contents = "CGImageCompatibility"} = <CFBoolean 0x1b0331110 [0x1b0330bb8]>{value = true}
5 : <CFString 0x1aa9428a8 [0x1b0330bb8]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x1aa9427e8 [0x1b0330bb8]>{contents = "ITU_R_709_2"}
6 : <CFString 0x1aa942c48 [0x1b0330bb8]>{contents = "CGBitmapContextCompatibility"} = <CFBoolean 0x1b0331110 [0x1b0330bb8]>{value = true}
}
}
}
的{{1}}将CMVideoFormatDescriptionRef
显示为CMSampleBufferRef
,并将框架的常规尺寸显示为1920x1080。
我该怎么做?
答案 0 :(得分:0)
kCVImageBufferDisplayDimensionsKey
标头文件表示密钥的值为
//带有以下两个键的CFDictionary
kCVImageBufferDisplayWidthKey
和kCVImageBufferDisplayHeightKey
,两者都是CFNumber
。
您改为通过CMVideoDimensions
,因此请将其更改为
NSDictionary *dimensions = [NSDictionary dictionaryWithObjectsAndKeys:@(width), kCVImageBufferDisplayWidthKey, @(height), kCVImageBufferDisplayHeightKey];