Skip to content

Instantly share code, notes, and snippets.

@kphretiq
Created March 16, 2016 14:49
Show Gist options
  • Save kphretiq/e5b95e7fc2b11819121e to your computer and use it in GitHub Desktop.
Save kphretiq/e5b95e7fc2b11819121e 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