I am trying to implement a simple macOS app with screen recording capabilities.
I don't want to record a microphone input, but rather a sound that comes out of my Mac's speakers. Example: this way I want to be able to record a YouTube video to a file.
Is this possible with AVCaptureSession? Googling shows the examples that capture video and microphore, but not the internal audio.
Here is the working code that I have to capture video and microphone. What do I have to modify to disable the microphone and get the internal PC's sound that comes to the speakers?
session = AVCaptureSession()
session.sessionPreset = AVCaptureSession.Preset.high
movieFileOutput = AVCaptureMovieFileOutput()
let displayId: CGDirectDisplayID = CGDirectDisplayID(CGMainDisplayID())
let audioDevice = AVCaptureDevice.default(for: .audio)!
let audioInput = try! AVCaptureDeviceInput(device: audioDevice)
let videoInput: AVCaptureScreenInput = AVCaptureScreenInput(displayID: displayId)!
session.addInput(videoInput)
session.addInput(audioInput)
session.addOutput(movieFileOutput)
session.startRunning()
movieFileOutput.startRecording(to: self.destinationUrl, recordingDelegate: self)