Created
September 12, 2014 21:55
-
-
Save rjlzaitz/78f42d4baabfccb65ac6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MJPGSTREAMER_HOME=/home/pi/mjpg-streamer | |
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 -br 60" | |
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 | |
else | |
echo "No camera detected, trying again in two minutes" | |
fi | |
sleep 120 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment