Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureDevice on macOS

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 }
like image 504
7ball Avatar asked Nov 15 '17 19:11

7ball


People also ask

What is Avcapture in iOS?

An object that configures capture behavior and coordinates the flow of data from input devices to capture outputs. iOS 4.0+ iPadOS 4.0+ macOS 10.7+ Mac Catalyst 14.0+

What is AV capture device?

A capture device (also referred to as a capture card) is a hardware device that you connect to your computer that converts the video signal from your camera's output into a digital format your computer can recognize.


1 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]>
like image 194
Swany Avatar answered Sep 18 '22 15:09

Swany