我正在尝试在录制视频会话时添加录制音频。我想帮助我如何制作语法或在哪里添加我的音频设备以及在哪里组合文件。
func setupCameraSession() {
// setup video device input
let videoDeviceInput: AVCaptureDeviceInput
do {
videoDeviceInput = try AVCaptureDeviceInput(device: currentDevice!)
}
catch {
fatalError("Could not create AVCaptureDeviceInput instance with error: \(error).")
}
guard cameraSession.canAddInput(videoDeviceInput) else {
fatalError()
}
cameraSession.addInput(videoDeviceInput)
// setup video output
self.videoDataOutput = AVCaptureVideoDataOutput()
self.videoDataOutput?.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA) ]
let queue: DispatchQueue = DispatchQueue(label: "videocapturequeue", attributes: [])
self.videoDataOutput?.setSampleBufferDelegate(self, queue: queue)
self.videoDataOutput?.alwaysDiscardsLateVideoFrames = true
if self.cameraSession.canAddOutput(videoDataOutput!) {
self.cameraSession.addOutput(videoDataOutput!)
}
do {
try self.currentDevice?.lockForConfiguration()
self.currentDevice?.activeVideoMinFrameDuration = CMTimeMake(1, fpsValue) // 20 fps
self.currentDevice?.unlockForConfiguration()
} catch {
print("could not configure a device")
return
}
self.cameraSession.startRunning()
}