Skip to content

Instantly share code, notes, and snippets.

@freegroup
Forked from kphretiq/find_cam.py
Created October 4, 2019 21:38
Show Gist options
  • Save freegroup/4afe3bb8ba2e48d13fc6aee7372fcdc7 to your computer and use it in GitHub Desktop.
Save freegroup/4afe3bb8ba2e48d13fc6aee7372fcdc7 to your computer and use it in GitHub Desktop.
Identify Camera Device Linux
"""
#Installing v4l-utils (debian) gives one the handy v4l2-ctl command:
$ v4l2-ctl --list-devices
HPigh Definition Webcam (usb-0000:00:14.0-11):
/dev/video2
UVC Camera (046d:0821) (usb-0000:00:14.0-13):
/dev/video0
Logitech Webcam C930e (usb-0000:00:14.0-9):
/dev/video1
. . . which can be accessed thusly:
"""
def find_cam(cam):
cmd = ["/usr/bin/v4l2-ctl", "--list-devices"]
out, err = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
out, err = out.strip(), err.strip()
for l in [i.split("\n\t") for i in out.split("\n\n")]:
if cam in l[0]:
return l[1]
return False
if __name__ == "__main__":
cam="C930e"
print(find_cam(cam))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment