Camera won't autostart at reboot

Hi i am new to octoprint. I have a new install of Octoprint on my Linux Mint intel Nuc. I have manage to get my Logitech c920 to work but i my restart the camera each time i reboot. I must run this command to get my webcam to work sudo /home/chris/scripts/webcam start. Can anyone help me figure out what is wrong?? This is a guide i followed because i am pretty new with linux.

cd ~
sudo apt install subversion libjpeg8-dev imagemagick ffmpeg libv4l-dev cmake
git clone GitHub - jacksonliam/mjpg-streamer: Fork of http://sourceforge.net/projects/mjpg-streamer/
cd mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
make

Test mjpg streamer:
sudo ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so"

Create webcam startup scripts don’t use sudo:
cd ~
mkdir scripts
nano /home/chris/scripts/webcam

#!/bin/bash

Start / stop streamer daemon

case "$1" in
start)
/home/chris/scripts/webcamDaemon >/dev/null 2>&1 &
echo "$0: started"
;;
stop)
pkill -x webcamDaemon
pkill -x mjpg_streamer
echo "$0: stopped"
;;
*)
echo "Usage: $0 {start|stop}" >&2
;;
esac

Create webcam Daemon script don’t use sudo:
nano /home/chris/scripts/webcamDaemon

#!/bin/bash

MJPGSTREAMER_HOME=/home/chris/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

Edit webcam file startup permissions:
sudo chmod +x /home/chris/scripts/webcam
sudo chmod +x /home/chris/scripts/webcamDaemon

Add webcams to startup:
sudo nano /etc/rc.local

#!/bin/sh -e

rc.local

This script is executed at the end of each multiuser runlevel.

Make sure that the script will "" on success or any other

value on error.

In order to enable or disable this script just change the execution

bits.

By default this script does nothing.

/home/chris/scripts/webcam start

exit 0

Start webcam:
sudo /home/chris/scripts/webcam start

Change rc.local permissions:
sudo chmod +x /etc/rc.local

Any help would be greatly appreciated
Thanks
Chris

The text did not copy like I wanted it to. But the link to the guide I used is Octoprint on Linux - Google Docs

If you scroll down to the mjpg streamer section you will see what I used.

Any reason you didn't use the official guide for this, which is known to work well? It should be applicable to most Linux distributions.

The section for getting the webcam to autostart: Setting up OctoPrint on a Raspberry Pi running Raspbian or Raspberry Pi OS

Hi i tried following the guide. It is very similar to the one i used to install webcam. If i run {sudo /home/chris/scripts/webcam start} the camera works but it will not autostart on reboot. Any other ideas where i can go from here? I really appreciate the help!

Thanks
Chris

Hi all! I have a similar issue following the same process. However, my webcam stream isn't loading. I've connected a Logitech C270 to my linux box, and it works while using a webcam app, but I can't get a stream or snapshot to work. Any ideas?

I get this when I run sudo ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so"
MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39

  • i: Using V4L2 device.: /dev/video0*
  • i: Desired Resolution: 640 x 480*
  • i: Frames Per Second.: -1*
  • i: Format............: JPEG*
  • i: TV-Norm...........: DEFAULT*
    ERROR opening V4L interface: No such file or directory
  • i: init_VideoIn failed*

I’m still trying to figure this out I’ll let you know if I fix it.

No I tried that and no luck

You shouldn't need to run this as sudo. If so your user may need to be added to the video group. Check what group owns the appropriate /dev/videoN device, if it's not video then you have other issues...

Also, you need to make sure that you've replaced the user pi with your user, in this case chris where specified in the guide.

Hi TTalkington

You were right about the sudo. Also right about adding my user to video group. i used command usermod -aG video chris is that the right way to do it?