实时CMSampleBuffer处理

时间:2015-07-18 23:00:22

标签: ios swift avfoundation

我尝试在旅途中处理CMSampleBuffers,但即使我正在复制样本并处理副本,我也很快停止接收样本。

我使用AVCaptureAudioDataOutputSampleBufferDelegate获取样本并按照以下方式处理:

    func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {

    if (bufferCopy != nil) {
        bufferCopy == nil
    }

    if CMSampleBufferCreateCopy(kCFAllocatorDefault, sampleBuffer, &bufferCopy) == noErr {

        let encodedSamples = self.encoder.encodeSample(bufferCopy?.takeRetainedValue())
        println(encodedSamples.count)
        CMSampleBufferInvalidate(sampleBuffer)
//            println("Copy: \(bufferCopy!.takeRetainedValue())")
        }
        else {
            println("Failed to copy sampleBuffer")
        }
    }

Objective-C解决方案也可以。

我还用这个例子创建了一个GitHub仓库:https://github.com/Devxhkl/SwiftAudioStreamingOggOpus

0 个答案:

没有答案
相关问题