Install video streaming if desired

The video streaming service has to be installed manually now.
cd /tmp
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
make
sudo make install
##This is the URL of the video stream:
http://192.168.1.##:8080/?action=stream
##This can be used to take a snapshot from the camera:
wget http://192.168.1.10:8080/?action=snapshot -O snapshot.jpg

Refer here for more information on the streamer:

https://github.com/cncjs/cncjs/wiki/Setup-Guide:-Raspberry-Pi-|-MJPEG-Streamer-Install-&-Setup-&-FFMpeg-Recording

You can also refer to this page for information on how to set resolution and framerate for you camera.

https://github.com/foosel/OctoPrint/wiki/Webcams-known-to-work

In order for the camera to work, and start up on boot, there's more work to be done. We need to create a shell script:

nano /home/pi/mjpg-streamer.sh

Add the below code to ( /home/pi/mjpg-streamer.sh )

The frame rate, quality and resolution may need to be changed for your camera. these start at line 14 below.

#!/bin/bash
# chmod +x mjpg-streamer.sh
# Crontab: @reboot /home/pi/mjpg-streamer/mjpg-streamer.sh start
# Crontab: @reboot /home/pi/mjpg-streamer/mjpg-streamer-experimental/mjpg-streamer.sh start
MJPG_STREAMER_BIN="/usr/local/bin/mjpg_streamer" # "$(dirname $0)/mjpg_streamer"
MJPG_STREAMER_WWW="/usr/local/share/mjpg-streamer/www"
MJPG_STREAMER_LOG_FILE="${0%.*}.log" # "$(dirname $0)/mjpg-streamer.log"
RUNNING_CHECK_INTERVAL="2" # how often to check to make sure the server is running (in seconds)
HANGING_CHECK_INTERVAL="3" # how often to check to make sure the server is not hanging (in seconds)
VIDEO_DEV="/dev/video0"
## Pay attention to FRAME_RATE, QUALITY AND RESOLUION. You may need to modify these.
FRAME_RATE="10"
QUALITY="80"
RESOLUTION="1024x768" # 160x120 176x144 320x240 352x288 424x240 432x240 640x360 640x480 800x448 800x600 960x544 1280x720 1920x1080 (QVGA, VGA, SVGA, WXGA) # lsusb -s 001:006 -v | egrep "Width|Height" # https://www.textfixer.com/tools/alphabetical-order.php # v4l2-ctl --list-formats-ext # Show Supported Video Formates
PORT="8080"
YUV="yes"
################INPUT_OPTIONS="-r ${RESOLUTION} -d ${VIDEO_DEV} -f ${FRAME_RATE} -q ${QUALITY} -pl 60hz"
INPUT_OPTIONS="-r ${RESOLUTION} -d ${VIDEO_DEV} -q ${QUALITY} -pl 60hz --every_frame 2" # Limit Framerate with "--every_frame ", ( mjpg_streamer --input "input_uvc.so --help" )
if [ "${YUV}" == "true" ]; then
INPUT_OPTIONS+=" -y"
fi
OUTPUT_OPTIONS="-p ${PORT} -w ${MJPG_STREAMER_WWW}"
# ==========================================================
function running() {
if ps aux | grep ${MJPG_STREAMER_BIN} | grep ${VIDEO_DEV} >/dev/null 2>&1; then
return 0
else
return 1
fi
}
function start() {
if running; then
echo "[$VIDEO_DEV] already started"
return 1
fi
export LD_LIBRARY_PATH="$(dirname $MJPG_STREAMER_BIN):."
echo "Starting: [$VIDEO_DEV] ${MJPG_STREAMER_BIN} -i \"input_uvc.so ${INPUT_OPTIONS}\" -o \"output_http.so ${OUTPUT_OPTIONS}\""
${MJPG_STREAMER_BIN} -i "input_uvc.so ${INPUT_OPTIONS}" -o "output_http.so ${OUTPUT_OPTIONS}" >> ${MJPG_STREAMER_LOG_FILE} 2>&1 &
sleep 1
if running; then
if [ "$1" != "nocheck" ]; then
check_running & > /dev/null 2>&1 # start the running checking task
check_hanging & > /dev/null 2>&1 # start the hanging checking task
fi
echo "[$VIDEO_DEV] started"
return 0
else
echo "[$VIDEO_DEV] failed to start"
return 1
fi
}
function stop() {
if ! running; then
echo "[$VIDEO_DEV] not running"
return 1
fi
own_pid=$$
if [ "$1" != "nocheck" ]; then
# stop the script running check task
ps aux | grep $0 | grep start | tr -s ' ' | cut -d ' ' -f 2 | grep -v ${own_pid} | xargs -r kill
sleep 0.5
fi
# stop the server
ps aux | grep ${MJPG_STREAMER_BIN} | grep ${VIDEO_DEV} | tr -s ' ' | cut -d ' ' -f 2 | grep -v ${own_pid} | xargs -r kill
echo "[$VIDEO_DEV] stopped"
return 0
}
function check_running() {
echo "[$VIDEO_DEV] starting running check task" >> ${MJPG_STREAMER_LOG_FILE}
while true; do
sleep ${RUNNING_CHECK_INTERVAL}
if ! running; then
echo "[$VIDEO_DEV] server stopped, starting" >> ${MJPG_STREAMER_LOG_FILE}
start nocheck
fi
done
}
function check_hanging() {
echo "[$VIDEO_DEV] starting hanging check task" >> ${MJPG_STREAMER_LOG_FILE}
while true; do
sleep ${HANGING_CHECK_INTERVAL}
# treat the "error grabbing frames" case
if tail -n2 ${MJPG_STREAMER_LOG_FILE} | grep -i "error grabbing frames" > /dev/null; then
echo "[$VIDEO_DEV] server is hanging, killing" >> ${MJPG_STREAMER_LOG_FILE}
stop nocheck
fi
done
}
function help() {
echo "Usage: $0 [start|stop|restart|status]"
return 0
}
if [ "$1" == "start" ]; then
start && exit 0 || exit -1
elif [ "$1" == "stop" ]; then
stop && exit 0 || exit -1
elif [ "$1" == "restart" ]; then
stop && sleep 1
start && exit 0 || exit -1
elif [ "$1" == "status" ]; then
if running; then
echo "[$VIDEO_DEV] running"
exit 0
else
echo "[$VIDEO_DEV] stopped"
exit 1
fi
else
help
fi

Make the file executable.

chmod +x /home/pi/mjpg-streamer.sh

Then add a line to Cron so that the streamer will be started on boot.

Open Cron (accept the default editor)

crontab -e

Add the following line to the end of the file:

@reboot /home/pi/mjpg-streamer.sh start

Reboot the PI and you're finished!