Is it possible for two processes to access the webcam at the same time?
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:
$ git clone https://github.com/umlaeute/v4l2loopback.git
$ cd v4l2loopback
$ make
$ sudo make install
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!
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
as video2
. 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
$ git clone https://github.com/umlaeute/v4l2loopback.git
$ cd v4l2loopback
$ make
$ sudo make install
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)
$ sudo depmod -a
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
$ modprobe v4l2loopback devices=2
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
gst-launch-1.0 v4l2src device=/dev/video0 ! tee name=t ! queue ! v4l2sink device=/dev/video1 t. ! queue ! v4l2sink device=/dev/video2
I open 2 more tabs
In the first tab
gst-launch-1.0 v4l2src device=/dev/video1 ! videoconvert ! ximagesink
In the second tab
gst-launch-1.0 v4l2src device=/dev/video2 ! videoconvert ! ximagesink
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
gst-launch-1.0 v4l2src device=/dev/video1 ! videoconvert ! ximagesink
In the second tab
gst-launch-1.0 v4l2src device=/dev/video1 ! videoconvert ! ximagesink
In the third tab
gst-launch-1.0 v4l2src device=/dev/video1 ! videoconvert ! ximagesink
gives me three streams.