Trick #8: Create commands to start the webcam in low & high quality

Printoid PRO and PREMIUM allow you to see what’s happening in front of your camera.

  • When you are connected to your local network, you probably want to have the best quality possible.
  • When you are connected ‘outside’ of your network, for example on the 3G/4G, you probably want to have a lower quality in order to preserve your data usage
  • Or you probably simply want to switch OFF your camera during the night

/!\ This tutorial is made for  the users who have installed Raspbian, then OctoPrint on it, following this tutorial: Setting up OctoPrint on a Raspberry Pi running Raspbian

It is not directly applicable to OctoPi.

You can create three custom SSH commands in Printoid to achieve that. Read how to create custom SSH commands in Printoid first 🙂

Here are my own scripts in my Raspberry Pi.

  • The both are stored in /home/pi/scripts/ in this example
  • The script webcamDaemon is available for USB webcam and Raspi Camera




# init configuration
camera_usb_options_low_quality="-r 640x480 -f 10 -q 85"
camera_usb_options_high_quality="-r 1080x720 -f 15 -q 100"
camera_raspi_options_low_quality="-fps 10 -quality 100 -x 1080 -y 720 -rot 270"
camera_raspi_options_high_quality="-fps 10 -quality 100 -x 1080 -y 720 -rot 270"

if [ -e "/boot/octopi.txt" ]; then
  source "/boot/octopi.txt"

# runs MJPG Streamer, using the provided input plugin + configuration
function runMjpgStreamer {
  echo Running
  ./mjpg_streamer -o " -w ./www" -i "$input"

# starts up the RasPiCam
function startRaspi {
  logger "Starting Raspberry Pi camera"
  case "$1" in
      runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options_high_quality"
      runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options_low_quality"
      echo "usage: startRaspi {high|low}"

# starts up the USB webcam
function startUsb {
  logger "Starting USB webcam at $1 quality"
  case "$1" in
      runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options_high_quality"
      runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options_low_quality"
      echo "usage: startUsb {high|low}"

# 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 LQ: $camera_usb_options_low_quality
echo usb options HQ: $camera_usb_options_high_quality
echo raspi options LQ: $camera_raspi_options_low_quality
echo raspi options LQ: $camera_raspi_options_high_quality

# keep mjpg streamer running if some camera is attached
while true; do
  if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then
    startUsb $1
  elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then

  sleep 120



# Start / stop streamer daemon

case "$1" in
    /home/pi/scripts/webcamDaemon $2 >/dev/null 2>&1 &
    echo "$0: started with quality $2"
    pkill -x webcamDaemon
    pkill -x mjpg_streamer
    echo "$0: stopped"
    echo "Usage: $0 {start|stop} {low|high}" >&2


How to use these scripts?

  • To start your streaming in low quality (LQ): /home/pi/scripts/webcam start low
  • To start your streaming in high quality (HQ): /home/pi/scripts/webcam start high
  • To stop your streaming: /home/pi/scripts/webcam stop

Finally in Printoid, you can do something like that:



  • Don’t forget to specify the full path of the script: webcam start high is not sufficient
  • If you wanna switch from LQ to HQ, you have to stop the webcam server first


Download links



3 thoughts on “Trick #8: Create commands to start the webcam in low & high quality

  1. Are the resolution / frame rate only limited by the camera or does printoid have limits for the max?


    1. Hello,
      Resolution and frame rate are limited by the camera, then by the video server, then by the app (especially because of the network connection).
      If you have a 4k camera, but the mjpeg-streamer server is configured to stream at 640×480, then Printoid will show the video at 640×480 max


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s