Skip to content

Instantly share code, notes, and snippets.

@kphretiq
Created March 16, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kphretiq/c8b7acd7888298b1e30f to your computer and use it in GitHub Desktop.
Save kphretiq/c8b7acd7888298b1e30f 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 1.0MP H
. . . 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