Advertisement
FireEagle244

Fix Camera Disconnect and Reconnect Issue OctoPrint Install Ubuntu

Jun 21st, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #!/bin/bash
  2. # make sure to change the username from "alex" to your username
  3.  
  4. MJPGSTREAMER_HOME=/home/alex/mjpg-streamer/mjpg-streamer-experimental
  5. MJPGSTREAMER_INPUT_USB="input_uvc.so"
  6. MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"
  7.  
  8. # init configuration
  9. camera="auto"
  10. camera_usb_options="-r 640x480 -f 10"
  11. camera_raspi_options="-fps 10"
  12.  
  13. if [ -e "/boot/octopi.txt" ]; then
  14. source "/boot/octopi.txt"
  15. fi
  16.  
  17. # runs MJPG Streamer, using the provided input plugin + configuration
  18. function runMjpgStreamer {
  19. input=$1
  20. pushd $MJPGSTREAMER_HOME
  21. echo Running ./mjpg_streamer -o "output_http.so -w ./www" -i "$input"
  22. LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w ./www" -i "$input" &
  23. popd
  24. }
  25.  
  26. # starts up the RasPiCam
  27. function startRaspi {
  28. logger "Starting Raspberry Pi camera"
  29. runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
  30. }
  31.  
  32. # starts up the USB webcam
  33. function startUsb {
  34. logger "Starting USB webcam"
  35. runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options"
  36. }
  37.  
  38. # we need this to prevent the later calls to vcgencmd from blocking
  39. # I have no idea why, but that's how it is...
  40. vcgencmd version
  41.  
  42. # echo configuration
  43. echo camera: $camera
  44. echo usb options: $camera_usb_options
  45. echo raspi options: $camera_raspi_options
  46.  
  47. # keep mjpg streamer running if some camera is attached and restart if one disconnects and reconnects
  48. while true; do
  49. if ! pgrep -x "mjpg_streamer" > /dev/null
  50. then
  51. if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then
  52. startUsb
  53. elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then
  54. startRaspi
  55. fi
  56. elif ! [ -e "/dev/video0" ]; then
  57. pkill -x "mjpg_streamer"
  58. fi
  59. sleep 1
  60. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement