Sharing a Camera Device Among Multiple Applications on Fedora Using V4l2 and ffmpeg

There are times when multiple applications need to access the camera feed at the same time. If in this case you don’t have multiple camera devices, you will get an error someting along the lines Device or resource busy.

The solution for this is simple, you just need to add a virtual camera and redirect the feed from your physical camera device to that virtual camera device.

Now this can be done using OBS. The only problem for me in using OBS for a trivial thing such as this is

So here is how we can add a virtual device on a linux machine and redirect the video feed from a physical video camera to it using V4l2-loopback and Ffmpeg.

First install V4l2-loopback and ffmpeg

On fedora, you can do this with

$ sudo dnf install v4l2loopback ffmpeg

Once that is done, add a new virtual camera device,

$ sudo modprobe v4l2loopback

check which camera device has been added

$ ls /dev/ | grep video

At this point you should get an additional video device under /dev/. Now we need to redirect the feed coming from your webcam/video camera device to this one.

We will do this with ffmpeg,

Let’s say your physical camera device is mounted at /dev/video0 and the virtual camera device is mounted at /dev/video2, then the command line for ffmpeg would be.

$ ffmpeg -f v4l2 -i /dev/video0 -f v4l2 /dev/video2

in this case we are simply reading the video feed from the input device /dev/video0 and forwarding it as is to the device /dev/video2.

Now the good thing about this is you can use the device /dev/video2 with multiple applications at the same time and it won’t give an error saying Device or resource busy.