Camerastreamer (#159)

* toward camera-streamer integration

* various fixes

* fix menu entry

* fedora 3.10

* perpare to merge
This commit is contained in:
paukstelis
2024-03-11 15:25:14 -04:00
committed by GitHub
parent 1c77eada39
commit b68ea01d0c
6 changed files with 91 additions and 23 deletions

View File

@@ -1,11 +1,11 @@
Updated January 19, 2024.
Updated March 11, 2024.
Want to support this work? Buy Me a Coffee. https://www.buymeacoffee.com/ppaukstelis.
Need help with octoprint_deploy? Visit support-octoprint-deploy on the OctoPrint Discord: https://discord.com/invite/yA7stPp
# octoprint_deploy 1.0.9
# octoprint_deploy 1.0.10
* These files provide a bash script for quickly deploying multiple octoprint instances on a single computer. For Linux systems (Ubuntu, Fedora, etc.) it will also install OctoPrint and a video streamer (ustreamer). No need for lots of file editing or complicated Docker compose scripts! A background video on how it generally works from my ERRF2022 talk can be found here: https://www.youtube.com/watch?v=q0iCNl8-kJI&t=15378s
* octoprint_deploy and octoprint_install are being merged! Maintaining two separate scripts was close to twice the amount of work. By merging the scripts many new features have been included, while also providing greater simplicity in setup.
@@ -63,18 +63,12 @@ Need help with octoprint_deploy? Visit support-octoprint-deploy on the OctoPrint
* Restart all instances from the command line: `sudo octoprint_deploy/octoprint_deploy.sh restart_all`
* You can inject any function at start using the command line with the first argument `f` and the second argument the function name.
# Recent Changes
* Add camera-streamer as an option. This is also coupled with adding PiCam from the menu. __THIS IS EXPERIMENTAL and NEEDS TESTING__
* Fix an issue with Fedora python versioning.
* Fix change for ustreamer executable being renamed ustreamer.bin
* Improve Instance Status function.
* Remove octoprint_deploy backup technique and move entirely to native OctoPrint backups. Backups made in this way are moved to /home/$USER/instance_backup to make them easier to sort.
* Camera settings written to separate env file. This can be found and edited at `/etc/cam_instancename.env`.
* Fixes for shared uploads function.
* Command-line function injection. Will be useful in some cases.
* Allow first instance creation without udev rule
* Fixed dialout permissions.
* Lots of changes, now octoprint_deploy 1.0.0
* Udev utility menu
* Diagnostic information from menu provides a variety of useful information about the system.
* Cameras have additional fallback detection (/dev/v4l/by-id entries)
# TODO
* Integration with OctoPi new camera stack. This may or may not happen.
* Detection of existing instances/binaries that can be used instead of a full install (preserves plugins)

View File

@@ -72,10 +72,29 @@ write_camera() {
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
fi
#camera-streamer
if [ "$STREAMER" == camera-streamer ]; then
if [ "$PICAM" == true ]; then
cat $SCRIPTDIR/picam_camstream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
else
cat $SCRIPTDIR/octocam_camstream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
fi
fi
#convert RES into WIDTH and HEIGHT for camera-streamer
CAMWIDTH=$(sed -r 's/^([0-9]+)x[0-9]+/\1/' <<<"$RESOLUTION")
CAMHEIGHT=$(sed -r 's/^[0-9]+x([0-9]+)/\1/' <<<"$RESOLUTION")
sudo -u $user echo "DEVICE=$CAMDEVICE" >> /etc/$OUTFILE.env
sudo -u $user echo "RES=$RESOLUTION" >> /etc/$OUTFILE.env
sudo -u $user echo "FRAMERATE=$FRAMERATE" >> /etc/$OUTFILE.env
sudo -u $user echo "PORT=$CAMPORT" >> /etc/$OUTFILE.env
sudo -u $user echo "WIDTH=$CAMWIDTH" >> /etc/$OUTFILE.env
sudo -u $user echo "HEIGHT=$CAMHEIGHT" >> /etc/$OUTFILE.env
cp $SCRIPTDIR/$OUTFILE.service /etc/systemd/system/
echo "camera:cam${INUM}_$INSTANCE port:$CAMPORT udev:true" >> /etc/octoprint_cameras
@@ -145,14 +164,6 @@ add_camera() {
CAMHAPROX=''
get_settings
if [ "$STREAMER" == camera-streamer ]; then
echo "You are using OctoPi with camera-streamer."
echo "This is not compatible with octoprint_deploy."
echo "Use the camera-streamer scripts to install your cameras,"
echo "or change the streamer type in the Utilties menu."
main_menu
fi
if [ "$STREAMER" == none ]; then
echo "No camera streamer service has been installed."
echo "Use the utilities menu to add one."

10
menu.sh
View File

@@ -9,7 +9,7 @@ yellow=$(echo -en "\e[93m")
main_menu() {
VERSION=1.0.9
VERSION=1.0.10
#reset
UDEV=''
TEMPUSB=''
@@ -26,7 +26,7 @@ main_menu() {
echo
PS3="${green}Select operation: ${white}"
if [ -f "/etc/octoprint_deploy" ]; then
options=("Add instance" "Delete instance" "Add Camera" "Delete Camera" "Utilities" "Backup Menu" "Update" "Quit")
options=("Add instance" "Delete instance" "Add USB Camera" "Add PiCam" "Delete Camera" "Utilities" "Backup Menu" "Update" "Quit")
else
options=("Prepare system" "Update" "Quit")
fi
@@ -46,10 +46,14 @@ main_menu() {
remove_instance_menu
break
;;
"Add Camera")
"Add USB Camera")
add_camera
break
;;
"Add PiCam")
add_camera true
break
;;
"Delete Camera")
remove_camera_menu
break

26
octocam_camstream.service Normal file
View File

@@ -0,0 +1,26 @@
[Unit]
Description=camera-streamer web camera for USB camera on Generic platform
After=network.target
[Service]
User=OCTOUSER
EnvironmentFile=/etc/OCTOCAM.env
ExecStart=/home/OCTOUSER/camera-streamer/camera-streamer \
--camera-path=${DEVICE} \
--camera-format=JPEG \
--camera-width=${WIDTH} -camera-height=${HEIGHT} \
--camera-fps=${FRAMERATE} \
--camera-nbufs=3 \
--http-listen=0.0.0.0 \
--http-port=${PORT} \
--camera-video.disabled
Restart=always
RestartSec=10
Nice=10
IOSchedulingClass=idle
IOSchedulingPriority=7
MemoryMax=250M
[Install]
WantedBy=multi-user.target

33
picam_camstream.service Normal file
View File

@@ -0,0 +1,33 @@
[Unit]
Description=camera-streamer libcamera
After=network.target
StartLimitIntervalSec=120
StartLimitBurst=10
[Service]
User=OCTOUSER
EnvironmentFile=/etc/OCTOCAM.env
ExecCondition=/bin/sh -c "/usr/bin/libcamera-hello --list-cameras | grep -o '/base/soc/[^)]*'"
ExecCondition=/bin/sh -c "! ss -ltn src :$PORT | grep -q LISTEN"
ExecStart=/bin/sh -c "exec /usr/bin/camera-streamer \
--http-port=${PORT} \
--camera-type=libcamera \
--camera-path=$(/usr/bin/libcamera-hello --list-cameras | grep -o '/base/soc/[^)]*' | head -n1) \
--camera-format=MJPG \
--camera-width=${WIDTH} --camera-height=${HEIGHT} \
--camera-video.height=${VIDEO_HEIGHT} \
--camera-snapshot.height=${SNAPSHOT_HEIGHT} \
--camera-fps=${FRAMERATE} \
--camera-nbufs=${NBUFS:-2} \
${OPTIONS}"
Restart=always
RestartSec=10
Nice=10
IOSchedulingClass=idle
IOSchedulingPriority=7
MemoryMax=250M
[Install]
WantedBy=multi-user.target

View File

@@ -284,7 +284,7 @@ new_install() {
fi
systemctl enable sshd.service
PYV=$(python3 -c"import sys; print(sys.version_info.minor)")
if [ $PYV -eq 11 ]; then
if [ $PYV -gt 10 ]; then
dnf -y install python3.10-devel
PYVERSION='python3.10'
fi
@@ -381,7 +381,7 @@ haproxy_install() {
streamer_install() {
PS3="${green}Which video streamer you would like to install?: ${white}"
options=("ustreamer (recommended)" "None/Skip")
options=("ustreamer (recommended)" "camera-streamer" "None/Skip")
select opt in "${options[@]}"
do
case $opt in