Je crée un CMVideoFormatDescriptionRef
partir de CMVideoFormatDescriptionRef
en utilisant ce code:
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);
J'ai besoin de passer ce dictionary à CMFormatDescriptionCreate
.
Le problème est la dernière ligne
dimensions, kCVImageBufferDisplayDimensionsKey,
Ce n'est pas la bonne façon d'append des dimensions
à ce dict. Il bloque l'application.
J'ai essayé d'emballer le tout sur un NSValue
utilisant ceci:
NSValue *miValue = [NSValue value: &dimensions withObjCType:@encode(CMVideoDimensions)];
Cela fonctionne en théorie, pas de crash, mais videoInfo
n'est pas créé correctement (OSStatus -12731). Si je supprime cette dernière ligne du dictionary, videoInfo
est créé mais n'a aucune définition pour les dimensions, qui sont supposées être 0x0 pixels, ou codecType
. Voir ci-dessous:
<CMVideoFormatDescription 0x17044c270 [0x1b0330bb8]> { mediaType:'vide' mediaSubType:'brga' mediaSpecific: { codecType: 0 dimensions: 0 x 0 <--HERE!!! } extensions: {<CFBasicHash 0x17086dcc0 [0x1b0330bb8]>{type = immutable dict, count = 4, ensortinges => 0 : <CFSsortingng 0x1aa9427c8 [0x1b0330bb8]>{contents = "CVImageBufferYCbCrMasortingx"} = <CFSsortingng 0x1aa942808 [0x1b0330bb8]>{contents = "ITU_R_601_4"} 3 : <CFSsortingng 0x1aa942c68 [0x1b0330bb8]>{contents = "CGImageCompatibility"} = <CFBoolean 0x1b0331110 [0x1b0330bb8]>{value = true} 5 : <CFSsortingng 0x1aa9428a8 [0x1b0330bb8]>{contents = "CVImageBufferColorPrimaries"} = <CFSsortingng 0x1aa9427e8 [0x1b0330bb8]>{contents = "ITU_R_709_2"} 6 : <CFSsortingng 0x1aa942c48 [0x1b0330bb8]>{contents = "CGBitmapContextCompatibility"} = <CFBoolean 0x1b0331110 [0x1b0330bb8]>{value = true} } } }
Un CMVideoFormatDescriptionRef
d'un CMSampleBufferRef
normal montre codecType
comme BGRA
et les dimensions régulières du cadre, 1920×1080, par exemple.
Comment je fais ça?
Le file d'en-tête kCVImageBufferDisplayDimensionsKey
indique que la valeur de la key est un
// CFDictionary avec les deux keys suivantes
kCVImageBufferDisplayWidthKey
et kCVImageBufferDisplayHeightKey
, qui sont tous les deux CFNumber
s.
Vous CMVideoDimensions
place, alors changez pour
NSDictionary *dimensions = [NSDictionary dictionaryWithObjectsAndKeys:@(width), kCVImageBufferDisplayWidthKey, @(height), kCVImageBufferDisplayHeightKey];