56 lines
1.6 KiB
Plaintext
56 lines
1.6 KiB
Plaintext
|
#!/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
|