我正在尝试使用 AVFoundation 在 OSX 中录制带有音频的屏幕,当我录制视频时效果很好。但是当添加音频输入并将其附加到 AVAssetWriterInput 时,资产编写器状态更改为 .failed。
if let sampleBuffer = sampleBuffer {
if CMSampleBufferDataIsReady(sampleBuffer) {
if assetWriter.status == .unknown {
let startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
assetWriter.startWriting()
assetWriter.startSession(atSourceTime: startTime)
}
if assetWriter.status == .failed {
print("writer error \(String(describing: assetWriter.error?.localizedDescription))")
return false
}
if isVideo {
if videoInputWriter.isReadyForMoreMediaData {
videoInputWriter.append(sampleBuffer)
return true
}
} else {
if audioInputWriter.isReadyForMoreMediaData {
audioInputWriter.append(sampleBuffer)
return true
}
}
}
}
错误信息是
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x600002841320 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}