CreatBotCrowsnest/libs/ustreamer.sh
Stephan Wendel 24f9257a47
FIX: Mark as executable.
* ustreamer.sh, v4l2_control.sh and v4l2rtspserver.sh

Signed-off-by: Stephan Wendel <me@stephanwe.de>
2021-12-13 22:19:23 +01:00

62 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
#### ustreamer library
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
#### written by Stephan Wendel aka KwadFan
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# Exit upon Errors
set -e
function run_ustreamer {
local cam_section ustreamer_bin device port resolution fps custom
local raspicam start_param wwwroot
cam_section="${1}"
ustreamer_bin="$(whereis ustreamer | awk '{print $2}')"
device="$(get_param "cam ${cam_section}" device)"
port=$(get_param "cam ${cam_section}" port)
resolution=$(get_param "cam ${cam_section}" resolution)
fps=$(get_param "cam ${cam_section}" max_fps)
custom="$(get_param "cam ${cam_section}" custom_flags 2> /dev/null)"
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}')"
check_section "${cam_section}"
wwwroot="$(dirname $(readlink -qe $(whereis webcamd)))/ustreamer-www"
#Raspicam Workaround
if [ "${device}" == "${raspicam}" ]; then
start_param=(
--host 127.0.0.1 -p "${port}" -m MJPEG --device-timeout=5
--buffers=3 -r "${resolution}" -f "${fps}" --allow-origin=\*
--static "${wwwroot}"
)
else
start_param=(
-d "${device}" -r "${resolution}" -f "${fps}"
--host 127.0.0.1 -p "${port}" --allow-origin=\*
--device-timeout=2 --static "${wwwroot}"
)
fi
# Custom Flag Handling
if [ -n "${custom}" ]; then
start_param=(${start_param[@]} "${custom}" )
fi
log_msg "Starting ustreamer with Device ${device} ..."
echo "Parameters: ${start_param[*]}" | \
log_output "ustreamer [cam ${cam_section}]"
# Ustreamer is designed to run even if the device is not ready or readable.
# I dont like that! ustreamer has to exit if Cam isnt there.
if [ -e "${device}" ]; then
"${ustreamer_bin}" ${start_param[*]} 2>&1 | \
log_output "ustreamer [cam ${cam_section}]"
else
log_msg "ERROR: Start of ustreamer [cam ${cam_section}] failed!"
fi
}