Check if v4l2 device has video inputs
This commit is contained in:
parent
9f81008a74
commit
09a2404fc3
24
stream.sh
24
stream.sh
|
|
@ -5,6 +5,11 @@ if ! command -v inotifywait >/dev/null 2>&1; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! command -v v4l2-ctl >/dev/null 2>&1; then
|
||||||
|
echo "Please install v4l-utils"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
declare -A STREAMS
|
declare -A STREAMS
|
||||||
|
|
||||||
failed() {
|
failed() {
|
||||||
|
|
@ -28,13 +33,21 @@ streaming() {
|
||||||
) || failed "$1"
|
) || failed "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_initial_devices() {
|
check() {
|
||||||
for file in /dev/video*; do
|
file=$1
|
||||||
file="${file##*/}"
|
|
||||||
echo "Found $file"
|
echo "Found $file"
|
||||||
|
|
||||||
|
if v4l2-ctl -n -d "/dev/$file" | grep -q 'Input'; then
|
||||||
(streaming "$file") &
|
(streaming "$file") &
|
||||||
STREAMS[$file]=$!
|
STREAMS[$file]=$!
|
||||||
echo "$file PID ${STREAMS[$file]}"
|
echo "$file PID ${STREAMS[$file]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_initial_devices() {
|
||||||
|
for file in /dev/video*; do
|
||||||
|
file="${file##*/}"
|
||||||
|
check "$file"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,16 +55,13 @@ listen_for_new_devices() {
|
||||||
inotifywait -m /dev --format "%f" -e create |
|
inotifywait -m /dev --format "%f" -e create |
|
||||||
while read -r file; do
|
while read -r file; do
|
||||||
if [[ "$file" =~ video[0-9]+$ ]]; then
|
if [[ "$file" =~ video[0-9]+$ ]]; then
|
||||||
echo "Found $file"
|
|
||||||
|
|
||||||
if ! ps -p "${STREAMS[$file]}"> /dev/null; then
|
if ! ps -p "${STREAMS[$file]}"> /dev/null; then
|
||||||
unset "STREAMS[$file]"
|
unset "STREAMS[$file]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -v "STREAMS[$file]" ]]; then
|
if [[ ! -v "STREAMS[$file]" ]]; then
|
||||||
(streaming "$file") &
|
check "$file"
|
||||||
STREAMS[$file]=$!
|
|
||||||
echo "$file PID ${STREAMS[$file]}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue