From c0b876653964d3b645aaca2aa87cc9fc813f397a Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Sat, 24 Nov 2018 18:08:48 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=9EwebcamDaemon=E2=80=9C=20hinzuf=C3=BCge?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webcamDaemon | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 webcamDaemon diff --git a/webcamDaemon b/webcamDaemon new file mode 100644 index 0000000..0efbe25 --- /dev/null +++ b/webcamDaemon @@ -0,0 +1,56 @@ +#!/bin/bash +# copy to /home/pi/scripts/webcamDaemon + +MJPGSTREAMER_HOME=/home/pi/mjpg-streamer/mjpg-streamer-experimental +MJPGSTREAMER_INPUT_USB="input_uvc.so" +MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so" + +# init configuration +camera="auto" +camera_usb_options="-r 640x480 -f 10" +camera_raspi_options="-fps 10" + +if [ -e "/boot/octopi.txt" ]; then + source "/boot/octopi.txt" +fi + +# runs MJPG Streamer, using the provided input plugin + configuration +function runMjpgStreamer { + input=$1 + pushd $MJPGSTREAMER_HOME + echo Running ./mjpg_streamer -o "output_http.so -w ./www" -i "$input" + LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w ./www" -i "$input" + popd +} + +# starts up the RasPiCam +function startRaspi { + logger "Starting Raspberry Pi camera" + runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options" +} + +# starts up the USB webcam +function startUsb { + logger "Starting USB webcam" + runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options" +} + +# we need this to prevent the later calls to vcgencmd from blocking +# I have no idea why, but that's how it is... +vcgencmd version + +# echo configuration +echo camera: $camera +echo usb options: $camera_usb_options +echo raspi options: $camera_raspi_options + +# keep mjpg streamer running if some camera is attached +while true; do + if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then + startUsb + elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then + startRaspi + fi + + sleep 120 +done \ No newline at end of file