10

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 }
pvg
  • 2,673
  • 4
  • 17
  • 31
7ball
  • 2,183
  • 4
  • 26
  • 61

2 Answers2

21

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]>
Swany
  • 615
  • 8
  • 14
  • Great, I need to check camera in Capabilities and for safety not to crash when running on device, add "Privacy - Camera Usage Description" in Info.plist file for usage description of camera. – haxpor Mar 29 '18 at 06:31
  • Now available on macOS 10.15+ Is my answer — “this should be the accepted answer now.” – Kristóf Zelei Stated under my answer. – Colin Jul 02 '20 at 01:15
-2

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

Colin
  • 865
  • 1
  • 6
  • 23