I would like to try using Cheese in Google+ Hangouts, and similar configurations, and I would like to know if it is possible for the webcam to be used by two processes to have access to the webcam at the same time. I have not tried it as yet, but before I do, I figured I would ask.
So, is it possible?
Happily, now, YES!
There is currently a project on GitHub that can show not only two, but an infinite (limited only by system capacity) number of video devices from a single source.
The project is called
v4l2loopback
. (Check the link and scroll down to view the README for instructions.)You can install
v4l2loopback
by cloning its GitHub and running these commands:Examples
For samples on how to use it with GStreamer, FFmpeg, MPlayer, and Skype, check their small wiki. Hopefully you could find the right settings to fit your needs.
Enjoy tweaking around!
Since there is no answer using
ffmpeg
, this is it.Explanation
While
v4l2loopback
creates virtual video devices, they are not associated with anything by default. To make them useful, you have to send streams to them via external applications such asffmpeg
.First load the module
and then send your webcam's input to the virtual device.
Now
/dev/video5
works as a pseudo-webcam. Note, unlike a physical webcam, a single virtual video device can be accessed from multiple applications simultaneously. Thus, in this case, you don't have to create many virtual devices.I wrote a script to wrap these steps: v4l2_webcam - GitHub.
Application
You can send any (raw) video to a virtual video device. This means, for example, it is possible to use a complicatedly mixed video by OBS as a camera input to a Web meeting (e.g. Skype, Zoom, etc.).
Here is a relatively complex but very practical example:
Structure
Result
Well I just tried. Interesting results.
I have got skype and cheese and webcam toy and hangouts (which all do work) and tried them together.
Results:
You can't use the same webcam on 2 things at once.
Cheese (Working) + Webcam Toy (Not working) + Skype (Small, top right. Not working).
You can use 2 webcams on 2 things though. (Cheese + Webcam Toy).
Hangouts (Not working) + Cheese (Working)
Hangouts (Working on it's own).
Cheese broken when I opened Hangouts first. It did the same with the others, but my internet is too slow to upload every single screenshot (and I doubt you'd appreciate 30+ screenshots)...
I even tried making a symbolic link to
/dev/video0
and saving it in/dev
asvideo2
. That didn't work.I also can't run 2 cheese processes at once.
If you had to, I would advise making it full screen and doing 2 screen recordings. I doubt that would work for what you want though.
Based on @The Eye answer
I first installed gstreamer packages on Ubuntu 18.04 https://gstreamer.freedesktop.org/documentation/installing/on-linux.html
I got warning message as here on Ubuntu 18.04 LTS https://github.com/umlaeute/v4l2loopback/issues/139 (but it didn't prevent me from loading v4l2loopback driver)
I just have 1 webcam on my laptop /dev/video0 and I wanted to get 2 streams from the same hardware. Based on https://github.com/umlaeute/v4l2loopback/blob/master/README.md
There should now be
/dev/video1
and/dev/video2
created assuming/dev/video0
was the only video device.Now I run the following in one terminal window
I open 2 more tabs
In the first tab
In the second tab
Now one should see 2 video streams
UPDATE
Even if I use the same
/dev/video1
device multiple times it all gives me that many stream. example.In the first tab
In the second tab
In the third tab
gives me three streams.
The answer is no with a maybe... The Library, "Video 4 Linux" detects whether a device is being used, and will not initiate. However; if you wish to download libv4l-dev and edit it manually, you can edit the code to get rid of this check and then just recompile it. I imagine you could get this to work, but it would be extremely unstable. May be worth checking out though.
TLDR: Anything is possible if you are a programmer with some elbow grease handy. Don't want to go that far? Then no; its not possible.
I has success using OBS Open Broadcast Software after the following steps:
Install video4linux loopback device (v4l2loopback as suggested by others)
(I am on Ubuntu 18.04 and had to install a newer version as suggested here: https://github.com/CatxFish/obs-v4l2sink/issues/30)
Install OBS
(Again I had to install a newer version and ffmpeg as per these instructions: https://itsubuntu.com/install-obs-in-linux-operating-system/)
Install OBS-v4lsink
(go to https://github.com/CatxFish/obs-v4l2sink, then to "releases", download and install de .deb file, version 0.1.0 was the only deb file there)
Start v4l2loopback:
In OBS and select a source
Under "sources" click on "+", give your new layer a name, select your (real) webcam
In OBS select a sink
In the top menu go to tools > v42lsink, select the virtual webcam (/dev/videoX, with X being the highest number available), click start
In your applications select the virtual webcam
I had Zoom and Discord both using the same new virtual webcam and was also able to record from the camera using OBS