5

Working with v4l2loopback devices I can run these two virtual devices:

a) running the preview image from a Canon DSLR via USB through v4l2loopback into OBS:

modprobe v4l2loopback
gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc fd=0 ! decodebin name=dec ! queue ! videoconvert ! tee ! v4l2sink device=/dev/video0

Found here, and it works.

b) Streaming the output of OBS into a browser based conferencing system, like this:

modprobe v4l2loopback devices=1 video_nr=10 card_label="OBS Cam" exclusive_caps=1

Found here, this also works.

However, I need to run both a) and b) at the same time, which isn't working as expected. They are interfering, it seems they are using the same buffer the video flips back and forth between the two producers.

What I learned and tried: A kernel module can only be loaded once. The v4l2loopback module can be unloaded using the command modprobe -r v4l2loopback. I don't know if loading it a second time will be ignored or unload the previous one.

I've tried to load the module with devices=2 as an option as well as different video devices, but I can't find the right syntax.

Max N
  • 1,134
  • 11
  • 23
  • what exactly are "both things" and how don't they run? your quesion contains an enumeration of what works fabulously, but it lacks crucial inforamtion about what does not. it's not even clear what you mean with "individual properties". – umläute May 29 '20 at 19:09
  • Both shown v4l2 commands run on their own but when executed while the other is running they interfere with each other and seem to write to the same buffer even if (as i assume) different devices are set. – Max N May 29 '20 at 19:13
  • 1. please update the question to contain any additional information (rather than providing clarifications in the comments) 2. "interfere" is a very broad term. i don't know what you mean by it in this context. 3. which commands are you talking about? `modprobe`? this command will load a module into the kernel (possibly with some parameter). you cannot load the same module twice (without unloading it first) – umläute May 29 '20 at 19:21

2 Answers2

14

As there is an already accepted answer, I assume your problem has been solved. Yet, I was quite newbie and couldn't set the syntax even after the answer above (i.e. how to set video2)

After a bit of more search, I found the website that explains how to add multiple devices with an example.

modprobe v4l2loopback video_nr=3,4,7 card_label="device number 3","the number four","the last one" Will create 3 devices with the card names passed as the second parameter:

  • /dev/video3-> device number 3
  • /dev/video4 -> the number four
  • /dev/video7-> the last one

When I was trying to use my Nikon camera as a webcam and OBS as a virtual camera for streaming, to have full control of naming my video devices was important. I hope this answer will help some others, as well.

umläute
  • 28,885
  • 9
  • 68
  • 122
TheClem
  • 141
  • 1
  • 5
6

from your description ("the video flips back and forth between the two producers") it seems that both producers are writing to the same video-device.

to fix this, you need to do two things:

  • create 2 video-devices
  • tell each producer to use their own video device

creating multiple video-devices

as documented this can be accomplished by specifying devices=2 when loading the module.

taking your invocation of modprobe, this would mean:

modprobe v4l2loopback devices=2 video_nr=10 card_label="OBS Cam" exclusive_caps=1

this will create two new devices, the first one will be /dev/video10 (since you specified video_nr), the 2nd one will take the first free video-device. on my system (that has a webcam, which occupies both /dev/video and /dev/video1) this is /dev/video2

telling each producer to use their own device

well, tell one producer to use /dev/video10 and the other to use /dev/video2 (or whatever video-devices you got)

e.g.

gphoto2 --stdout --capture-movie | gst-launch-1.0 \
       fdsrc fd=0  \
       ! decodebin name=dec  \
       ! queue  \
       ! videoconvert  \
       ! tee  \
       ! v4l2sink device=/dev/video10

and configure obs to use /dev/video2.

or the other way round.

just don't use the same video-device for both producers. (also make sure that your consumers use the correct video-device)

umläute
  • 28,885
  • 9
  • 68
  • 122