Why can’t two programs access my webcam simultaneously?

3

I first launch cheese and my webcam turns on. I then run vlc to grab the output of /dev/video0 but it fails with:

[0x7f3ea40012e8] v4l2 demux error: cannot set input 0: Device or resource busy
[0x7f3ea40012e8] v4l2 demux error: cannot set input 0: Device or resource busy
[0x7f3ea4002168] v4l2 access error: cannot set input 0: Device or resource busy
[0x7f3ea4002168] v4l2 access error: cannot set input 0: Device or resource busy
[0x7f3eb4000b78] main input error: open of `v4l2:///dev/video0' failed

Whatever pair of video programs I run (skype, cheese, vlc, etc.), the result is always the same: the second program can no longer use the webcam when the first one has already grabbed the output.

However I find it curious as video4linux states:

In general, V4L2 devices can be opened more than once. When this is supported by the driver, users can for example start a "panel" application to change controls like brightness or audio volume, while another application captures video and audio.

My webcam is seen in lspci as 058f:a014 Alcor Micro Corp. Asus Integrated Webcam, but I don’t even know what the underlying driver is, so I can’t check whether my problem is driver-related or not. Any input would be more than welcome!

qdii

Posted 2012-07-15T18:16:00.477

Reputation: 787

Answers

4

This is the same on Windows and perhaps all operating systems. The webcam is not a simple input device: to read frames from it you need to actively send commands according to some protocol. This makes it stateful and as such the application managing its state must have exclusive access to it.

On windows you can use splitcam to duplicate the feed. On Linux, you can use WebcamStudio.

billc.cn

Posted 2012-07-15T18:16:00.477

Reputation: 6 821