CMVideoFormatDescriptionGetCleanAperture() swift error

I can’t get the CMVideoFormatDescriptionGetCleanAperture() function to work. Using

var videoDescriptionRef = port.formatDescription as CMVideoFormatDescriptionRef
var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(videoDescriptionRef, true)


  • UICollectionView cells with Images inside UITableView prototype
  • OS X Server Continuous Integration ipa distribution
  • Upload image AWS S3 bucket in swift
  • Application Loader: ERROR ITMS-90502
  • camera overlay picture
  • AVFoundation: add text to the CMSampleBufferRef video frame
  • var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(port.formatDescription, true)

    gives me the following errors, respectively:

    Cannot convert expression's type 'CMVideoFormatDescriptionRef' to type 'CMVideoFormatDescriptionRef'

    And the second is

    Could not find an overlad for '__conversion' that accepts the supplied arguments

    Does anyone know how to fix these or can anyone point out any errors in getting the format description for retrieving the clean aperture?

    2 Solutions Collect From Internet About “CMVideoFormatDescriptionGetCleanAperture() swift error”

    CMFormatDescription itself does not have a member takeUnretainedValue. It is a member of Unmanaged<T>. You need to define an unmanaged variable first, get a value into it and then you retain it.

    As I do not know how you created port.formatDescription, here is an example where formatDescription is created from PPS/SPS from an AVC video.

    // create the receiving unmanaged variable
    var formatDescription: Unmanaged<CMVideoFormatDescription>?
    // call the not annotated method, this method will fill in formatDescription which is Unmanaged<T>
    let result = CMVideoFormatDescriptionCreateFromH264ParameterSets(nil, UInt(parameterSets.count), parameterSets, parameterSetSizes, 4, &formatDescription)
    // check result, yada yada yada before continuing
    // now we can actually retain the value
    let formatDescriptionRef = formatDescription!.takeUnretainedValue() as CMVideoFormatDescriptionRef
    // and we can do what ever we want with it in Swift without caring anymore. 
    var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(formatDescriptionRef, 1)
    1. Create an unmanaged type
    2. Use this unmanaged type in an not annotated method
    3. Retain the value
    4. Work with it without thinking about how you created it.

    So adjust your code where you create the port.formatDescription as a Unmanaged and you should be good.

    Try to use .takeUnretainedValue() like this:

    var videoDescription : CMVideoFormatDescription = port.formatDescription.takeUnretainedValue()
    var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(videoDescription, true)