Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ########################################################################
- ### DO NOT EDIT THIS FILE TO CHANGE THE CONFIG!!! ###
- ### ---------------------------------------------------------------- ###
- ### There is no need to edit this file for changing resolution, ###
- ### frame rates or any other mjpg-streamer parameters. Please edit ###
- ### /boot/octopi.txt instead - that's what it's there for! You can ###
- ### even do this with your Pi powered down by directly accessing the ###
- ### file when using the SD card as thumb drive in your regular ###
- ### computer. ###
- ########################################################################
- MJPGSTREAMER_HOME=/home/pi/mjpg-streamer
- MJPGSTREAMER_INPUT_USB="input_uvc.so"
- MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"
- # init configuration - DO NOT EDIT, USE /boot/octopi.txt INSTEAD!
- camera="auto"
- camera_usb_options="-r 1280x720 -f 10"
- camera_raspi_options="-fps 10"
- camera_http_webroot="./www-octopi"
- camera_http_options="-n"
- additional_brokenfps_usb_devices=()
- if [ -e "/boot/octopi.txt" ]; then
- source "/boot/octopi.txt"
- fi
- brokenfps_usb_devices=("046d:082b" "${additional_brokenfps_usb_devices[@]}")
- # cleans up when the script receives a SIGINT or SIGTERM
- function cleanup() {
- # make sure that all child processed die when we die
- local pids=$(jobs -pr)
- [ -n "$pids" ] && kill $pids
- exit 0
- }
- # says goodbye when the script shuts down
- function goodbye() {
- # say goodbye
- echo ""
- echo "Goodbye..."
- echo ""
- }
- # runs MJPG Streamer, using the provided input plugin + configuration
- function runMjpgStreamer {
- input=$1
- pushd $MJPGSTREAMER_HOME > /dev/null 2>&1
- echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot$
- LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_we$
- wait
- popd > /dev/null 2>&1
- }
- # starts up the RasPiCam
- function startRaspi {
- logger -s "Starting Raspberry Pi camera"
- runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
- }
- # starts up the USB webcam
- function startUsb {
- options="$camera_usb_options"
- device="video0"
- extracted_device=`echo $options | sed 's@.*-d /dev/\(video[0-9]+\).*@\1@'`
- if [ "$extracted_device" != "$options" ]
- then
- # the camera options refer to another device, use that for determining $
- device=$extracted_device
- fi
- uevent_file="/sys/class/video4linux/$device/device/uevent"
- if [ -e $uevent_file ]; then
- # let's see what kind of webcam we have here, fetch vid and pid...
- product=`cat $uevent_file | grep PRODUCT | cut -d"=" -f2`
- vid=`echo $product | cut -d"/" -f1`
- pid=`echo $product | cut -d"/" -f2`
- vidpid=`printf "%04x:%04x" "0x$vid" "0x$pid"`
- # ... then look if it is in our list of known broken-fps-devices and if$
- # the -f parameter from the options (if it's in there, else that's just$
- for identifier in ${brokenfps_usb_devices[@]};
- do
- if [ "$vidpid" = "$identifier" ]; then
- echo
- echo "Camera model $vidpid is known to not work with -f paramet$
- echo
- options=`echo $options | sed -e "s/\(\s\+\|^\)-f\s\+[0-9]\+//g"`
- fi
- done
- fi
- logger -s "Starting USB webcam"
- runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $options"
- }
- # make sure our cleanup function gets called when we receive SIGINT, SIGTERM
- trap "cleanup" SIGINT SIGTERM
- # say goodbye when we EXIT
- trap "goodbye" EXIT
- # echo configuration
- echo "Starting up webcamDaemon..."
- echo ""
- echo "--- Configuration: ----------------------------"
- echo "camera: $camera"
- echo "usb options: $camera_usb_options"
- echo "raspi options: $camera_raspi_options"
- echo "http options: -w $camera_http_webroot $camera_http_options"
- echo "-----------------------------------------------"
- echo ""
- # 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 > /dev/null 2>&1
- # keep mjpg streamer running if some camera is attached
- while true; do
- if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" $
- startUsb
- sleep 30 &
- wait
- elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera$
- startRaspi
- sleep 30 &
- wait
- else
- echo "No camera detected, trying again in two minutes"
- sleep 120 &
- wait
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement