gpt4 book ai didi

swift - 如何使用 Swift 3 中的 sampleBuffer、captureOutput 将视频保存到文件?

转载 作者:行者123 更新时间:2023-11-28 15:59:38 25 4
gpt4 key购买 nike

我正在努力解决这个问题。我想使用 AVAssetWriterInput 在 OSX 上使用 Swift 录制实时视频。

我创建了一个名为 inputAVAssetWriterInput 实例,我想将数据附加到输入,然后将其写入文件。

我将 expectsMediaDataInRealTime 设置为 true 就像文档中所说的那样。当我运行该应用程序时出现此错误:

Cannot append sample buffer: Cannot call method when status is 0

我使用 captureOutput 从相机获取数据。

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
// defined on load
// var input:AVAssetWriterInput

// Here I get an error
input.append(sampleBuffer)
}

AVAssetWriterInput 是否会处理视频的编码?如果我还想流式传输数据,是否应该使用 2 个写入器?

谢谢

最佳答案

确保在 input.append(sampleBuffer) 之前调用 AVAssetWriter.startWriting()

关于swift - 如何使用 Swift 3 中的 sampleBuffer、captureOutput 将视频保存到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277088/

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