我试图为kCMSampleAttachmentKey_DisplayImmediately
中的每个样本设置CMSampleBuffer
。
到目前为止,我已尝试获取字典(Dictionary<NSObject, AnyObject>
,NSDictionary
,CFDictionary
),并在CMSetAttachment
及其附件上调用CMSampleBuffer
要检索附件,请使用CMSampleBufferGetSampleAttachmentsArray
。
任何想法如何在Swift中设置这些标志?
答案 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)
}