gpt4 book ai didi

ios - 使用 AVCaptureVideoDataOutput 和 AVCaptureAudioDataOutput

转载 作者:行者123 更新时间:2023-11-30 12:26:19 24 4
gpt4 key购买 nike

我运行了一个 AVCaptureVideoDataOutput session ,设置如下,效果很好,并将缓冲区记录到文件中。

我还想录制音频,但缓冲区中似乎没有任何音频,即使我已将麦克风添加为 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

}

最佳答案

检查func captureOutput(AVCaptureOutput, didOutput: CMSampleBuffer, from: AVCaptureConnection)
如果您想从 AVCaptureAudioDataOutput 获取音频样本数据,则使用 AVCaptureAudioDataOutputSampleBufferDelegate https://developer.apple.com/documentation/avfoundation/avcaptureaudiodataoutputsamplebufferdelegate

关于ios - 使用 AVCaptureVideoDataOutput 和 AVCaptureAudioDataOutput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44163542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com