Ubuntu – how to create a duplicate of /dev/video0

webcam

I have 1 webcam connected to my computer but I want to use it in multiple programs.
The problem is when I launch a second program, it tells me the webcam is already used.

The programs which will use the webcam are : motion, pam_face_authentification, and some communication software like skype, google hangout …

How can I duplicate the flow of my webcam to simulate a second webcam?

Best Answer

My first thoughts were, I wonder if anyone has come up with a way to have a video appear as a webcam (e.g. I'm skyping with someone, but the video and audio they see is some video I chose instead). After searching around a bit, it looks like people have done this video piping (as discussed on Manipulating Dev Video and Fake a webcam using a video loopback device?

As mentioned in your comment, gst-launch v4l2src device=/dev/video0 ! v4l2sink device=/dev/video1 allows you to duplicate video0 to video1, and video1 is readable by some software.

In order to have this run when your computer starts, you can follow the UbuntuBootupHowto to come up with something like:

# /etc/init/videocloner.conf
description "VideoCloner"
start on runlevel [2345]
stop on runlevel [06]
respawn
exec gst-launch v4l2src device=/dev/video0 ! v4l2sink device=/dev/video1

This script should start when the computer boots and also allows you to run sudo service videocloner start|stop (Note: if my example script doesn't work, try moving gst-launch v4l2src device=/dev/video0 ! v4l2sink device=/dev/video1 into a shell script, and changing the exec line to call your shell script instead).

Related Question