AVCaptureDevice on macOS

Viewed 3644

Is it possible to display a camera feed in a macOS app? I'm basically trying to capture images frame by frame from a camera feed. I know how to do this in iOS, but for some reasons, on macOS, I can't seem to find any AVCaptureDevice for video.

let x = AVCaptureDevice.devices()

// When I print x, I only see the Microphone as the only capture device. No reference to video/camera whatsoever

guard let device = AVCaptureDevice.default(for: .video) else{ return }
2 Answers

I had the exact same issue, AVCaptureDevice.devices() only returned one entry, a microphone. Solution for me was to turn on the Camera checkbox in Project:Capabilities:App Sandbox. Output after I set the Camera checkbox...

▿ 2 elements
  - 0 : <AVCaptureHALDevice: 0x60c0000e4980 [Built-in Microphone][AppleHDAEngineInput:1B,0,1,0:1]>
  - 1 : <AVCaptureDALDevice: 0x101302b10 [FaceTime HD Camera][CC245055EWDF6VVDY]>

To find available capture devices use AVCaptureDevice.DiscoverySession as documented here

Then use the default(_:for:position:) method to return a default device for the specified media type as documented here

Related