CreatBotCrowsnest/libs/ustreamer.sh
Stephan Wendel 95c1dca13f
feat!: adds camera-streamer to crowsnest
This introduces camera-streamer as streamer option
via `mode: multi`

camera-streamer is a feature packed stream service.
It is capable to deliver mjpg/snapshots/webrtc and rtsp

Limited to raspberry pi sbc's for now.

This should also resolv
Feature request #51
Feature request #37
Fixes #83
Closes #85
Fixes #89

BREAKING CHANGES:

Dropping support for Debian Buster based images and kernels older than
5.15y

Dropping RTSP support due aler9/simple-rtsp-server

Dropping usage of ffmpeg

No support anymore for Raspicam V1 (EOL)

Signed-off-by: Stephan Wendel <me@stephanwe.de>

Signed-off-by: Stephan Wendel <me@stephanwe.de>
2023-03-11 18:57:19 +01:00

72 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
#### ustreamer library
#### crowsnest - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck enable=require-variable-braces
# Exit upon Errors
set -Ee
run_mjpg() {
local cams
v4l2_control
cams="${1}"
for instance in ${cams} ; do
run_ustreamer "${instance}" &
done
brokenfocus
return
}
run_ustreamer() {
local cam_sec ust_bin dev pt res fps cstm start_param
cam_sec="${1}"
ust_bin="${BASE_CN_PATH}/bin/ustreamer/ustreamer"
dev="$(get_param "cam ${cam_sec}" device)"
pt="$(get_param "cam ${cam_sec}" port)"
res="$(get_param "cam ${cam_sec}" resolution)"
fps="$(get_param "cam ${cam_sec}" max_fps)"
cstm="$(get_param "cam ${cam_sec}" custom_flags 2> /dev/null)"
noprx="$(get_param "crowsnest" no_proxy 2> /dev/null)"
# construct start parameter
if [[ -n "${noprx}" ]] && [[ "${noprx}" = "true" ]]; then
start_param=( --host 0.0.0.0 -p "${pt}" )
log_msg "INFO: Set to 'no_proxy' mode! Using 0.0.0.0 !"
else
start_param=( --host 127.0.0.1 -p "${pt}" )
fi
# Use MJPEG Hardware encoder if possible
if [ "$(detect_mjpeg "${cam_sec}")" = "1" ]; then
start_param+=( -m MJPEG --encoder=HW )
fi
# set max framerate
start_param+=( -r "${res}" -f "${fps}" )
# webroot & allow crossdomain requests
start_param+=( --allow-origin=\* --static "${BASE_CN_PATH}/ustreamer-www" )
# Custom Flag Handling (append to defaults)
if [[ -n "${cstm}" ]]; then
start_param+=( "${cstm}" )
fi
# Log start_param
log_msg "Starting ustreamer with Device ${dev} ..."
echo "Parameters: ${start_param[*]}" | \
log_output "ustreamer [cam ${cam_sec}]"
# Start ustreamer
echo "${start_param[*]}" | xargs "${ust_bin}" 2>&1 | \
log_output "ustreamer [cam ${cam_sec}]"
# Should not be seen else failed.
log_msg "ERROR: Start of ustreamer [cam ${cam_sec}] failed!"
}