SHARE
TWEET

Untitled

eta4ever Sep 4th, 2018 471 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. MJPGSTREAMER_HOME=/home/opi/mjpg-streamer/mjpg-streamer-experimental
  4. MJPGSTREAMER_INPUT_USB="input_uvc.so"
  5. MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"
  6.  
  7. # init configuration
  8. camera="auto"
  9. camera_usb_options="-r 640x480 -f 10"
  10. camera_raspi_options="-fps 10"
  11.  
  12. if [ -e "/boot/octopi.txt" ]; then
  13.     source "/boot/octopi.txt"
  14. fi
  15.  
  16. # runs MJPG Streamer, using the provided input plugin + configuration
  17. function runMjpgStreamer {
  18.     input=$1
  19.     pushd $MJPGSTREAMER_HOME
  20.     echo Running ./mjpg_streamer -o "output_http.so -w ./www" -i "$input"
  21.     LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w ./www" -i "$input"
  22.     popd
  23. }
  24.  
  25. # starts up the RasPiCam
  26. function startRaspi {
  27.     logger "Starting Raspberry Pi camera"
  28.     runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
  29. }
  30.  
  31. # starts up the USB webcam
  32. function startUsb {
  33.     logger "Starting USB webcam"
  34.     runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options"
  35. }
  36.  
  37. # we need this to prevent the later calls to vcgencmd from blocking
  38. # I have no idea why, but that's how it is...
  39. vcgencmd version
  40.  
  41. # echo configuration
  42. echo camera: $camera
  43. echo usb options: $camera_usb_options
  44. echo raspi options: $camera_raspi_options
  45.  
  46. # keep mjpg streamer running if some camera is attached
  47. while true; do
  48.     if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then
  49.         startUsb
  50.     elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then
  51.         startRaspi
  52.     fi
  53.  
  54.     sleep 120
  55. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top