Incus - expose webcams (and more) inside containers

I needed a webcam inside a container and looked for high-level solutions to no avail. It turns out, the approach in incus is to simply created the devices again in the containers.

Don't try to bind or replicate your video devices in containers. Simply tell incus to create them through mknod, their type and their major and minor device types.

On my machine, in order to get /dev/video0, I had to add the following through incus config edit <instance>:

media0:
  gid: "44"
  major: "511"
  minor: "0"
  mode: "0660"
  path: /dev/media0
  type: unix-char
  uid: "0"
video0:
  gid: "44"
  major: "81"
  minor: "0"
  mode: "0660"
  path: /dev/video0
  type: unix-char

This requires two devices because /dev/media0 is used for the configuration AFAIU.

Major and minor device types can be printed with stat on the host:

stat --printf='%n: major=%Hr minor=%Lr\n' /dev/video0 /dev/media0

The gid matches the one of the video group inside the instance. You'll therefore need to add your user to the video group:

usermod -a -G video <user>

#Commands I used for debugging

The most straight-forward way to test the devices could be used was uvcdynctrl --list from the uvcdynctrl package on Debian. After it could list my device without issue, I checked with guvcview.

It should also be possible to use uvccapture but I had some problems with it. I wasn't able to just run uvccapture. It would say the format is unavailable and fall back to 640x360 but save nothing in its output. Running 'uvccapture -x1920 -y1080' would say something similar but fall back 640x480, creating an image of that size. And if I tried with -x640 -y480, it wouldn't save anything either. Go figure.

#Updates

#Reports

#Notes