Adding a structure to a NSDictionary


I am creating a CMVideoFormatDescriptionRef out of thin air using this 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);

I need to pass that dictionary to CMFormatDescriptionCreate.

The problem is the last line

dimensions, kCVImageBufferDisplayDimensionsKey,

This is not the correct way to add dimensions to that dict. It crashes the app.

I have tried to wrap the whole thing on a NSValue using this:

NSValue *miValue = [NSValue value: &dimensions withObjCType:@encode(CMVideoDimensions)];

It works in theory, no crash, but videoInfo is not created correctly (OSStatus -12731). If I remove this last line from the dictionary, videoInfo is created but has no definition for the dimensions, that are assumed to be 0x0 pixels, or codecType. See below:

<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} } } }

A CMVideoFormatDescriptionRef from a regular CMSampleBufferRef shows codecType as BGRA and the regular dimensions of the frame, 1920x1080, for example.

How do I do that?


The kCVImageBufferDisplayDimensionsKey header file says the key's value is a


// CFDictionary with the following two keys


kCVImageBufferDisplayWidthKey and kCVImageBufferDisplayHeightKey, both of which are CFNumbers.

You're passing CMVideoDimensions instead, so change that to

NSDictionary *dimensions = [NSDictionary dictionaryWithObjectsAndKeys:@(width), kCVImageBufferDisplayWidthKey, @(height), kCVImageBufferDisplayHeightKey];


  • object_getInstanceVariable/object_setInstanceVariable in ARC
  • Generic return type for primitives
  • python re.compile and split with ÆØÅ charcters
  • Converting Dictionary to Dataframe with tuple as key
  • Bokeh custom ToolTips {safe} tag displays nothing
  • Implicit property animations do not work with CAReplicatorLayer?
  • Best HTML5 structure for a layout where the title/header is outside the article tag
  • How to make SASS put relative paths in its output
  • ConfigurationBuilder not working in azure function
  • Convert two columns Pandas data frame to dictionary of list with first column as keys
  • Find longest path less than or equal to given value of an acyclic, directed graph in Python
  • How do I bind multiple properties in an Android layout element
  • Python getting common name from URL using ssl.getpeercert()
  • Creating a DropDownList
  • Who propagate bugfixes across branches (corporate development)?
  • URLConnection doesn't work since API 10 and higher?
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • How can I sort a a table with VBA with given text condition?
  • debug library loaded with ctypes using gdb
  • Scrapy recursive link crawler
  • Deleting and Updating values from a cusrsor adapter
  • req.body is undefined - nodejs
  • Is possible to count alias result on mysql
  • How to model a transition system with SPIN
  • Symfony2: How to get request parameter
  • Importing jscolor library in angular 2
  • To display the title for the current loaction in map in iphone
  • ORA-29908: missing primary invocation for ancillary operator
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Akka Routing: Reply's send to router ends up as dead letters
  • php design question - will a Helper help here?
  • Is there a mandatory requirement to switch app.yaml?
  • KeystoneJS: Relationships in Admin UI not updating
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • JTable with a ScrollPane misbehaving
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time