ios - CMVideoFormatDescriptionGetCleanAperture() 快速错误

标签 ios swift avfoundation

我无法使用 CMVideoFormatDescriptionGetCleanAperture() 函数。使用

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

var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(port.formatDescription, true)

分别给我以下错误:

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

第二个是

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

有谁知道如何解决这些问题,或者谁能指出在获取用于检索干净孔径的格式描述时有任何错误吗?

最佳答案

CMFormatDescription本身没有成员(member)takeUnretainedValue .它是Unmanaged<T>的成员.您需要先定义一个非托管变量,为其赋值,然后保留它。

因为我不知道你是怎么创建的port.formatDescription ,这是一个例子,其中 formatDescription从 AVC 视频的 PPS/SPS 创建。

// 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. 创建非托管类型
  2. 在未注释的方法中使用此非托管类型
  3. 保留值(value)
  4. 使用它而不用考虑你是如何创建它的。

因此请在创建 port.formatDescription 的位置调整代码作为一个 Unmanaged,你应该是个好人。

关于ios - CMVideoFormatDescriptionGetCleanAperture() 快速错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24395265/

相关文章:

ios - 无法在解析推送通知时注册我的 ios 设备

ios - 为什么 AVFoundation 不接受我在 iOS 设备上的平面像素缓冲区?

ios - AVFoundation 自定义相机导致崩溃/内存压力?

ios - 使用 AVCaptureSession 以编程方式捕获最高分辨率图像

ios - 在 IOS 中使用自动布局在邻居之间居中 View

ios - 移动 imageView 时触发声音

ios - “initWithBase64Encoding”已弃用?

arrays - 在 Swift 的类中创建一个数组函数

ios - 无法识别的选择器发送到实例 0x7fe098c09830

ios - 工作表内容中的行为不能影响父 View