我正在尝试为CMSampleBuffer中的每个示例设置CMSampleBuffer。
到目前为止,我已经尝试获取字典(Dictionary<NSObject, AnyObject>、NSDictionary、CFDictionary),并在CMSampleBuffer及其附件上调用CMSetAttachment。
为了检索附件,我使用CMSampleBufferGetSampleAttachmentsArray。
我该怎么用Swift来设置这些旗子呢?
发布于 2017-07-20 07:22:07
以下是与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)
}https://stackoverflow.com/questions/29517903
复制相似问题