Mac webcam as camera

I’m running an instance of HA (in venv) on my macbook pro, it has a webcam, can anyone advise how to configure the webcam as a camera?
Cheers

FFmpeg should work.

Something like this should do the trick.

$ ffmpeg -i /dev/video0 -codec:v libx264 -qp 0 lossless.mp4
1 Like

OK making some progress. I brew install ffmpeg then after some Googling I found the list of cameras with ffmpeg -f avfoundation -list_devices true -i ""

[AVFoundation input device @ 0x7ff4a9e07380] AVFoundation video devices:
[AVFoundation input device @ 0x7ff4a9e07380] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7ff4a9e07380] [1] Capture screen 0
[AVFoundation input device @ 0x7ff4a9e07380] AVFoundation audio devices:
[AVFoundation input device @ 0x7ff4a9e07380] [0] Built-in Microphone

I can capture a video to disk with ffmpeg -f avfoundation -framerate 30 -i "0" out2.mpg. All good so far. I then tried a few variations of the config below, without any errors from HA but always get a grey box with FFMPEG(Image not available). Any suggestions @fabaff ?

camera:
  - platform: ffmpeg
    input: "0"
    extra_arguments: "-f avfoundation -framerate 30"

Trying ffmpeg again, this time with a usb webcam, still no working config. Anybody?

I guess that it’s a macOS issue. ffmpeg is working for the built-in camera and an USB webcam on Fedora 27.

1 Like

I’m also interested in this. I can record a video at the command line, but not sure how to set up the built-in FaceTime camera as a normal camera source.

@robmarkcole Did you ever find a decent solution for this? Trying to setup my Logitech camera for Facebox testing.

Sadly not, but I’m sure its just a matter of googling

Made a bit of progress on this in my case using a Logitech C920 Webcam:

ffmpeg -f avfoundation -framerate 2 -i "0" -f mpeg1video -b 200k -r 30 -vf scale=1920:1080 http://127.0.0.1:8080

Starts the output from the webcam BUT I’m getting a connection refused:

Connection to tcp://127.0.0.1:8080 failed: Connection refused

Which seems to point to an ACL issue according to a few posts elsewhere. Just not sure how to fix that.

1 Like
./ffmpeg -f avfoundation -framerate 25 -video_size 640x480 -i "0" -vcodec libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv422p -f mpegts udp://127.0.0.1:12345

This works for me on the iMac with the internal FaceTime Kamera. But I cannot open the stream with VLC?

1 Like

I tried the same code and it does indeed work but can’t get the feed to display in VLC.

Its a VLC problem, I had read it somewhere, its about the MTU size or something. Using mpv player for mac it does indeed work quite well.
I have then moved on to trying using the ffmpeg camera component in homeassistant. But there it simply says idling or something. Have not had time to dig deeper yet …

1 Like

Yep I have it working in MPV now… although its showing a 5 second lag with 1280x720 at 24fps. Have you managed to lower this lag down?

I came up withthis solution using MQTT