user12649691
user12649691

Reputation:

RuntimeError: 'v4l2loopback' backend: std::exception when using pyvirtualcam

When using pyvirtualcam, the following line

with pyvirtualcam.Camera(width=1280, height=720, fps=5) as cam

gives the following error

File "/home/linux1/Documents/jpeg-camera/./main.py", line 12, in <module>
    with pyvirtualcam.Camera(width=1280, height=720, fps=5) as cam:
  File "/home/linux1/.local/lib/python3.10/site-packages/pyvirtualcam/camera.py", line 219, in __init__
    raise RuntimeError('\n'.join(errors))
RuntimeError: 'v4l2loopback' backend: std::exception

I have tried downgrading, however this does not work

Upvotes: 1

Views: 1302

Answers (1)

onorabil
onorabil

Reputation: 401

Most probably a pyvirtualcam issue. I solved it by manually specifying the device at initialization. For the example below, /dev/video4; if video4 is taken (ls /dev), pick another one. More details (assumes Ubuntu):

  1. Set the device when loading v4l2loopback (video_nr)

$ sudo modprobe -r v4l2loopback && sudo modprobe v4l2loopback devices=1 video_nr=4 card_label="Virtual" exclusive_caps=1 max_buffers=2

  1. Check you can open the device

$ v4l2-ctl --list-devices -d4 # it should NOT say 'Cannot open device /dev/video4'

$ gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video4 # additional check

  1. Set the (same) device for pyvirtualwebcam

with pyvirtualcam.Camera(width=1280, height=720, fps=5, device='/dev/video4') as cam

If you cannot open the stream (2. fails), you could try compiling v4l2loopback as instructed here: https://github.com/umlaeute/v4l2loopback

Make sure you have loaded the (new) module, it will probably end up in the extra folder (as opposed to the one from apt)

$ modinfo v4l2loopback should return something like

filename: /lib/modules/5.16.xxx-generic/extra/v4l2loopback.ko

If not, manally delete the old .ko and run depmod again sudo depmod -a

Upvotes: 2

Related Questions