How do I find out which process is using my V4L2 webcam?

59,081

Solution 1

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

Solution 2

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

Solution 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
Share:
59,081

Related videos on Youtube

Turion
Author by

Turion

Updated on September 18, 2022

Comments

  • Turion
    Turion almost 2 years

    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?

    • Dee
      Dee over 10 years
      it is a second web cam on the same USB controller ?
    • Dee
      Dee over 10 years
      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
    • Turion
      Turion over 10 years
      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.
  • panzi
    panzi almost 9 years
    I'm not getting anything for fuser /dev/video0 but I still get /dev/video0: Device or resource busy.
  • Tsan-Kuang Lee
    Tsan-Kuang Lee over 8 years
    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?
  • panzi
    panzi over 8 years
    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.
  • user3191334
    user3191334 about 6 years
    Old question but since it took me 2h... keep in mind to try sudo fuser /dev/video0in case the command without sudo is not showing a result.
  • Max N
    Max N over 4 years
    lsof /dev/video0 doesn't give me any output
  • Narcolessico
    Narcolessico over 3 years
    As a side note, ps features the option -p instead of grepping the stdout. I.e. ps -p 1871