9

I have different lxc containers running on my machine and a webcam is also attached. I want all of the lxc containers to access this camera. I came across 'v4l2-loopback' devices and found a way to add devices using;

modprobe v4l2loopback devices=3

And I directed the stream from /dev/video0 to the desired virtual video devices. My question is how to add and remove these v4l2loopback devices at runtime? I want to add/remove a device whenever any lxc container is launched/deleted. Any ideas?

Thanks!

2 Answers 2

12

I don't have an elegant way to remove these devices other than force remove the v4l2loopback module:

sudo modprobe -r v4l2loopback
2
  • 1
    After I run this command it gives me no output. I dont know if it removed anything.... Commented May 24, 2020 at 21:47
  • 3
    You can use v4l2-ctl --list-devices to check your virtual devices Commented Apr 26, 2021 at 21:49
1

If you are running the full up to date v4l2loopback driver from https://github.com/umlaeute/v4l2loopback, then you can use the v4l2loopback-ctl utility to add and remove devices while the module is installed using the command v4l2loopback-ctl add /dev/video2 and v4l2loopback-ctl delete /dev/video2.

Unfortunately, this is not the version that is currently in Debian, which is a mishmash of an old version and some code from the current version, and is still using the old (pre 2021) v4l2loopback-ctl and the driver with no dynamic device management.

5
  • Will reinstallation on older OS Debian flavors use the new version if reinstalled? I am getting errors trying to use that code on Ubuntu 20.04
    – Vass
    Commented Mar 19 at 22:50
  • 1
    For runtime device control you need v4l2loopback version 0.13 or higher. Ubuntu 22.04 still has v4l2loopback 0.12 that has the old v4l2loopback-ctl that doesn't support adding and removing devices in runtime. There are currently no Ubuntu versions that ship v4l2loopback version 0.13, not even the next version currently in development. The only Linux OS shipping v4l2loopback version 0.13 - to the best of my knowledge - is Debian Sid.
    – Guss
    Commented Mar 20 at 16:26
  • 1
    It is easy to check if you have the correct version - run v4l2loopback-ctl --version . If it says "0.6", then you have the old version and that will not let you add and remove devices in runtime. You need a version that says 0.13.0 or higher.
    – Guss
    Commented Mar 20 at 16:28
  • thanks! at the moment, I just use modprobe v4l2loopback video_nr=${videoDevIdNum} card_label="${cardLabel} and to remove modprobe -r v4l2loopback. correct? I add a specific one and then remove all from the app, in run time, seems to work ok at the terminal, and yes, I have 0.6
    – Vass
    Commented Mar 21 at 16:57
  • 1
    That seems like it should work.
    – Guss
    Commented Mar 23 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .