Last active
November 8, 2022 09:13
-
-
Save pabsan-0/fa5011fc76192597b4e2719f36826a8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/bash | |
# | |
# This bash quickie lists your connected v4l2 cameras by parsing the output of `v4l2-ctl --list-devices`. | |
# Useful when playing w/ external cameras since replugging will usually modify its /dev/videoX location | |
# | |
# Example output | |
# ``` | |
# C: | |
# | |
# #define CAM_0 "/dev/video2" | |
# #define CAM_1 "/dev/video0" | |
# | |
# Bash: | |
# | |
# CAM_0="/dev/video2" | |
# CAM_1="/dev/video0" | |
# ``` | |
echo C: | |
echo | |
v4l2-ctl --list-devices \ | |
| awk '/usb/{getline; print}' \ | |
| awk '{str=$0} {printf "#define CAM_%d \"%s\"\n", idx, str} {idx+=1}' \ | |
| tr -d '\t' | |
echo | |
echo Bash: | |
echo | |
v4l2-ctl --list-devices \ | |
| awk '/usb/{getline; print}' \ | |
| awk '{str=$0} {printf "CAM_%d=\"%s\"\n", idx, str} {idx+=1}' \ | |
| tr -d '\t' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment