A webcam can not be accessed by two or more applications simultaneously. The solution is you can duplicate the video stream and make it available for any application. In short, you create a virtual webcam.
First, a webcam is commonly detected on
If it doesn't work, you can try to change its mode to 0777 and make sure there are no other applications accessing it. If it still doesn't work, you can buy a new webcam. Seriously. Don't buy a cheap and unknown-brand webcam. I have $5 webcam and it had wasted my time.
FFmpeg is the main application that will access your webcam and duplicate its video stream. V4L2loopback is needed to create multiple virtual capture devices (loopback devices) in Linux, which FFmpeg uses to store duplicated video streams and be accessed by other applications. For example, I want to enable two loopback devices. The new devices will be available on
Then, you can duplicate your webcam.
Or, you can also set the video resolution.
After you don't need the loopback devices, you can remove them.
If there are any questions or suggestions about this article, just leave them in the comment field below. If you think this article is useful, please share it with your colleagues.
First, a webcam is commonly detected on
/dev/video*
. Before you go through the steps to duplicate video stream, you should check whether your webcam is working. You can try to capture video using VLC by this command. (For example, your webcam is on /dev/video0
)$ vlc v4l2:///dev/video0
If it doesn't work, you can try to change its mode to 0777 and make sure there are no other applications accessing it. If it still doesn't work, you can buy a new webcam. Seriously. Don't buy a cheap and unknown-brand webcam. I have $5 webcam and it had wasted my time.
$ apt-get install ffmpeg linux-generic v4l2loopback-dkms
FFmpeg is the main application that will access your webcam and duplicate its video stream. V4L2loopback is needed to create multiple virtual capture devices (loopback devices) in Linux, which FFmpeg uses to store duplicated video streams and be accessed by other applications. For example, I want to enable two loopback devices. The new devices will be available on
/dev/video*
in a sequence.$ modprobe v4l2loopback devices=2
Then, you can duplicate your webcam.
$ ffmpeg -f v4l2 -i /dev/video0 -f v4l2 /dev/video1 -f v4l2 /dev/video2
Or, you can also set the video resolution.
$ ffmpeg -f video4linux2 -s 800x600 -i /dev/video0 -codec copy -f v4l2 /dev/video1 -codec copy -f v4l2 /dev/video2
After you don't need the loopback devices, you can remove them.
$ modprobe -r v4l2loopback
If there are any questions or suggestions about this article, just leave them in the comment field below. If you think this article is useful, please share it with your colleagues.
Comments
Post a Comment