设置CMSampleBuffer样本附件(Swift)

时间:2015-04-08 14:43:33

标签: ios swift h.264

我试图为kCMSampleAttachmentKey_DisplayImmediately中的每个样本设置CMSampleBuffer

到目前为止,我已尝试获取字典(Dictionary<NSObject, AnyObject>NSDictionaryCFDictionary),并在CMSetAttachment及其附件上调用CMSampleBuffer

要检索附件,请使用CMSampleBufferGetSampleAttachmentsArray

任何想法如何在Swift中设置这些标志?

1 个答案:

答案 0 :(得分:3)

这里的解决方案(可能远非完美)适用于Swift 4(应该与3一起工作)。

func setSampleBufferAttachments(_ sampleBuffer: CMSampleBuffer) {
    let attachments: CFArray! = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true)
    let dictionary = unsafeBitCast(CFArrayGetValueAtIndex(attachments, 0),
        to: CFMutableDictionary.self)
    let key = Unmanaged.passUnretained(kCMSampleAttachmentKey_DisplayImmediately).toOpaque()
    let value = Unmanaged.passUnretained(kCFBooleanTrue).toOpaque()
    CFDictionarySetValue(dictionary, key, value)
}