31

I tried to run the following:

$ vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path webcam.png --scene-prefix image_prefix --scene-format png vlc://quit --run-time=1                                                     
VLC media player 2.0.7 Twoflower (revision 2.0.6-54-g7dd7e4d)                                                                                                                                                                                                             
[0x1f4a1c8] dummy interface: using the dummy interface module...                                                                                                                                                                                                          
[0x7fc19c001238] v4l2 demux error: VIDIOC_STREAMON failed                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
libv4l2: error setting pixformat: Device or resource busy                                                                                                                                                                                                                 
[0x7fc19c007f18] v4l2 access error: cannot set input 0: Device or resource busy                                                                                                                                                                                           
[0x7fc19c007f18] v4l2 access error: cannot set input 0: Device or resource busy                                                                                                                                                                                           
[0x7fc1a4000b28] main input error: open of `v4l2:///dev/video0' failed                                                                                                                                                                                                    
[0x7fc1a4000b28] main input error: Your input can't be opened                                                                                                                                                                                                             
[0x7fc1a4000b28] main input error: VLC is unable to open the MRL 'v4l2:///dev/video0'. Check the log for details.                                                                                                                                                         
[0x7fc19c007cc8] idummy demux: command `quit'    

So I'm assuming that there is a program currently accessing my webcam, which is cumbersome since its light is off and lsof | grep /dev/video returns nothing. Is there another, proper way to check what processes are currently using my webcam? Or is the problem of an entirely different nature?

Turion
  • 482
  • 1
  • 4
  • 9
  • it is a second web cam on the same USB controller ? – Dee Feb 06 '14 at 20:06
  • helpfull would be if you describe your camera type, linux distro etc. Maybe debianic `dmesg | grep -i 'warn|fail|error|usb|video'` can give you some glue – Dee Feb 06 '14 at 20:11
  • It's a BisonCam as far as `lsusb` is concerned, using the usb video module. I'm running Gentoo. I'll post more info when the error occurs next time, but actually I'm just interested in how to find out which processes are using the cam. – Turion Feb 07 '14 at 15:43

3 Answers3

47

I was having the same problem and the solution at http://www.theoutpost.org/8-nslu2/open-devvideo0-device-or-resource-busy/ (EDIT: url updated) helped me.

$ fuser /dev/video0
/dev/video0: 1871m
$ ps axl | grep 1871
$ kill -9 1871
Tsan-Kuang Lee
  • 601
  • 5
  • 8
  • 6
    I'm not getting anything for `fuser /dev/video0` but I still get `/dev/video0: Device or resource busy`. – panzi Sep 27 '15 at 14:23
  • I updated the URL (the blog author moved it) -- perhaps you can see whether that post helps you. Otherwise, could it be the process occupying the device non-continuously so when fuser checks it's already released? Could you put fuser in a background loop and try to re-produce the error? – Tsan-Kuang Lee Sep 28 '15 at 15:51
  • After a reboot the error was gone. Don't want to force the error again. All the GUI apps failed to record audio and/or video in one or the other way (hang, crash, black image, no audio, or blocking /dev/video0) so I now use ffmpeg on the shell. Horrible UX but at least it works. – panzi Sep 28 '15 at 19:08
  • 2
    Old question but since it took me 2h... keep in mind to try `sudo fuser /dev/video0`in case the command without sudo is not showing a result. – user3191334 Apr 06 '18 at 21:15
  • 1
    As a side note, `ps` features the option `-p` instead of grepping the stdout. I.e. `ps -p 1871` – Narcolessico Nov 24 '20 at 14:26
6

For some reason /dev/video* from Tsan-Kuang's answer didn't work for me. Here's another way you could reach your device: ls /dev/input/by-id/. For example:

$ fuser /dev/input/by-id/usb-Microsoft_Microsoft®_LifeCam_HD-5000-event-if00

3

This command will return all processes which are using the device:

$ lsof /dev/video0
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME
cheese  31526 kirill  mem    CHR   81,0          18321 /dev/video0
cheese  31526 kirill   23u   CHR   81,0      0t0 18321 /dev/video0

Having PID you can kill the process, in this sample:

$ kill 31526