Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webcam picker #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions image-toolkit/bin/vnoiconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ EOM
# EOM
# fi
# ;;
set_video_device)
# Get device path at the first argument and replace the VIDEO_DEVICE_SOURCE in config.sh with it
if [ "$#" -ne 2 ]; then
echo "No device specified"
exit 1
fi
# Matches whole line starting with "VIDEO_DEVICE_SOURCE="
sed -i "s#VIDEO_DEVICE_SOURCE=.*#VIDEO_DEVICE_SOURCE=\"$2\"#" /opt/vnoi/config.sh
# Restart stream
if [[ -f "/run/icpc-webcam-stream.pid" ]]; then
kill -9 $(cat /run/icpc-webcam-stream.pid) 2> /dev/null
fi
;;
set_audio_device)
# Get device name at the first argument and replace the AUDIO_DEVICE_NAME in config.sh with it
if [ -z "$2" ]; then
Expand Down
4 changes: 4 additions & 0 deletions image-toolkit/config.sh.sample
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ AUDIO_DEVICE_NAME="any"

# If AUDIO_DEVICE_SOURCE is provided, AUDIO_DEVICE_NAME check is bypassed and AUDIO_DEVICE_SOURCE will be used directly
# AUDIO_DEVICE_SOURCE="alsa://plughw:1,0"

# If VIDEO_DEVICE_SOURCE is not empty, VIDEO_DEVICE_SOURCE will be used as the webcam device path for streaming
# Example: "/dev/v4l/by-id/usb-mywebcam-video-index0"
VIDEO_DEVICE_SOURCE=""
18 changes: 17 additions & 1 deletion image-toolkit/sbin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ webcam_stream_loop() {
do
echo "Looking for video devices"

local VIDEO_DEVICE_SOURCE
source /opt/vnoi/config.sh

if [[ -n "$VIDEO_DEVICE_SOURCE" ]] ; then
echo "VIDEO_DEVICE_SOURCE provided"
if [[ -e "$VIDEO_DEVICE_SOURCE" ]] ; then
echo "Using $VIDEO_DEVICE_PATH"
VIDEO_DEVICE_PATH="$VIDEO_DEVICE_SOURCE"
return
else
echo "$VIDEO_DEVICE_SOURCE not found"
sleep 3
fi
continue
fi

local VIDEO_DEVICES
mapfile -t VIDEO_DEVICES < <(find /dev/v4l/by-id -regex ".*/usb-.*-video-index0")

Expand Down Expand Up @@ -191,9 +207,9 @@ webcam_stream_loop() {
sleep 0.1
}

webcam_pick_devices
while :
do
webcam_pick_devices
echo "Checking video device at $VIDEO_DEVICE_PATH"
if [[ -e $VIDEO_DEVICE_PATH ]]; then
echo "Video device found"
Expand Down