1

我有一个运行设置如下的 AVCaptureVideoDataOutput 会话,它运行良好并将缓冲区记录到文件中。

我还想录制音频,但缓冲区中似乎没有任何音频,即使我已将麦克风添加为 captureSession 的输入。

我怀疑我还需要使用 AVCaptureAudioDataOutput。

func setupCaptureSession()
{
captureSession.beginConfiguration()
captureSession.sessionPreset = AVCaptureSessionPreset1280x720
videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "sample 
buffer delegate", attributes: []))


videoOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_32BGRA as UInt32)]

videoOutput.alwaysDiscardsLateVideoFrames = true

captureSession.addOutput(videoOutput)

captureSession.addInput(deviceInputFromDevice(backCameraDevice))

captureSession.addInput(deviceInputFromDevice(micDevice))

captureSession.commitConfiguration()
captureSession.startRunning()
}

然后这是我获取视频缓冲区并将其发送到文件中的方法

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

writeVideoFromData(sampleBuffer) // a function that writes the buffer to disk

}
4

1 回答 1

1

如果要从 AVCaptureAudioDataOutput https://developer.apple.com/documentation/avfoundation/avcaptureaudiodataoutputsamplebufferdelegatefunc captureOutput(AVCaptureOutput, didOutput: CMSampleBuffer, from: AVCaptureConnection) 获取音频的样本数据,请检查AVCaptureAudioDataOutputSampleBufferDelegate

于 2017-06-14T08:03:33.397 回答