Pimp my webcam (stream) project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
1.1 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
getvideobyname.py
Pick 1st video port by webcam id (requires /sys/class/video4linux layout)
History:
--------
24.05.20/KQ Initial version
27.05.20/KQ Variable naming corrected
"""
import sys # For arg passing only ...
basepath = "/sys/class/video4linux/video" # + Index (added later)
filename = "/name"
# Some argument scanning for start
if len(sys.argv) < 2:
print("usage: getvideobyname <webcam_name>",file=sys.stderr)
exit(0)
webcam_id = sys.argv[1] # Passed argument
for i in range(0, 8, 1): # First 8 video devices will be checked
try: # As it may fail ...
fullpath = basepath + str(i) + filename # Build complete path
with open(fullpath) as fr: # Try to open the actual file
current_webcam = (fr.read()).replace("\n", "") # Make it a one liner ...
print(current_webcam + " -> /dev/video" + str(i), file=sys.stderr) # Feedback: What's avail. ...
if current_webcam.find(webcam_id) >= 0: # Found!
print(str(i)) # Return Index
break # Done!
except:
pass # Skip all errors