v4l2 Identifizieren von / dev / video * über lsusb

1422
lysdexia

Ich schreibe ein Skript, das eine bestimmte an mein System angeschlossene Kamera verwenden muss.

$ lsusb|grep C930e Bus 001 Device 011: ID 046d:0843 Logitech, Inc. Webcam C930e 

Wie kann man programmatisch das / dev / video * -Gerät ermitteln, das einer gegebenen Geräte-ID aus der lsusb-Ausgabe entspricht?

Es scheint, dass dies einfach sein sollte, aber mir fehlt anscheinend ein Stichwort. :-D

1
`/ sys / class / video4linux` ist wahrscheinlich reich an Informationen als lsusb. Aber ich kann mir keine Beispiele vorstellen, die Ihnen eine echte Antwort geben infixed vor 8 Jahren 1
Du hast Recht. Ich habe hier einen Hinweis gefunden: http://stackoverflow.com/a/4290924/218732 lysdexia vor 8 Jahren 1

2 Antworten auf die Frage

1
lysdexia

I decided on what I think is a much better answer, despite requiring the installation of another package. 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 

Gist here.

0
lysdexia

As mentioned by @infixed above, the /sys/class/video4linux directory contains what I needed. This is a brittle example:

#!/usr/bin/env python import sys import os def find_cam_dev(cam): v4l2path = "/sys/class/video4linux" for base, subs, filenames in os.walk(v4l2path, followlinks=True): for filename in filenames: if filename == "name": pth = os.path.join(base, filename) with open(pth, "r") as f: name = f.read() if cam in name: return os.path.split(base)[1] if __name__ == "__main__": cam = "C930e" print(find_cam_dev(cam))