首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在swift中将CMSampleBuffer转换为CMAttachmentBearer

如何在swift中将CMSampleBuffer转换为CMAttachmentBearer
EN

Stack Overflow用户
提问于 2015-01-03 22:38:05
回答 1查看 1.5K关注 0票数 0

我是swift的新手,我想在(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection委托中调用函数CMCopyDictionaryOfAttachments

我的代码:

代码语言:javascript
复制
// MARK: Delegates

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
    // got an image
    let pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)
    let attachments : CFDictionaryRef = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, CMAttachmentMode( kCMAttachmentMode_ShouldPropagate)) as CFDictionaryRef!

}

这通过xcode :'CMSampleBuffer' is not identical to 'CMAttachmentBearer'得到了一个错误,那么我如何使用sampleBuffer作为目标,这段代码如果用objective-c编写就能正常工作

EN

回答 1

Stack Overflow用户

发布于 2015-01-04 00:57:49

我猜您代码中的主要问题是您传递的是CMSampleBuffer而不是CVPixelBufferRef

下一个问题是CMCopyDictionaryOfAttachments返回一个需要使用takeRetainedValue()进行转换的非托管实例。

代码语言:javascript
复制
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
    // got an image
    let pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)
    let attachments : [NSObject : AnyObject] = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, pixelBuffer, CMAttachmentMode( kCMAttachmentMode_ShouldPropagate)).takeRetainedValue()

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27755958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档