Getting linux webcam state via command line or API

I would, preferably, like to know of a command I can run that will let me know whether a webcam is on/off or recording/not recording, etc. Maybe a way to see if any programs are currently accessing it would work as well. If there is no command line option, I’m not opposed to writing a small c or c++ program to do this, but I haven’t been able to find a way to do that either.

Asked By: studio


I think lsof /dev/video0 should find the process which has the webcam (the first webcam should default to /dev/video0 but if you have more then one you may have a /dev/video1 /dev/video2 and so on, also some errors may cause 0 to be skipped).`

Answered By: Roman A. Taycher

Video devices in Linux are accessed using v4l interface(Video 4 Linux). There’s a library and a command line tool called v4l2-ctl in the v4l-utils package. However, I don’t think there’s a way to tell if a process is recording from it, just whether a process is connected, as described by @RomanA.Taycher

Answered By: Alastair McCormack
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.