OctoPrint Webcam Setup - PrusaMK2Users/MK2_Tips_and_Tricks GitHub Wiki
This is a quick guide to answer some common questions on setting up webcams with OctoPrint, particularly on the Octopi image for Raspberry Pi. For now it is assumed that users who setup Octoprint on another Linux distribution or hardware have enough experience to resolve most of the questions described here. This guide will be updated in the future to more broadly cover both Octopi and Octoprint on other platforms.
Just want examples of useful configurations for your Octopi image, here are some of the common ones:
For a complete list of modes offered by the Raspberry Pi camera models refer to the picamera Python module documentation. That page has some great information about the capabilities of the Raspberry Pi camera, particularly the real resolutions and which ones crop and which do not. Here are some example configurations, in all of them we set the JPEG compression to 95%.
# Raspberry Pi Camera V2, half resolution, video mode, full field of view (4:3 aspect) at 10fps
# Notes: Good compromise between resolution and framerate, recommended for V2
camera_raspi_options="-x 1640 -y 1232 -fps 10 -quality 95"
# Raspberry Pi Camera V1, half resolution, video mode, full field of view (4:3 aspect) at 10fps
# Notes: Good compromise between resolution and framerate, recommended for V2
camera_raspi_options="-x 1296 -y 972 -fps 10 -quality 95"
# Raspberry Pi Camera V2, maximum resolution, stills mode, full field of view (4:3 aspect) at 15fps
# Notes: Very slow for streaming, large images. Less image processing, generally looks worse
camera_raspi_options="-x 3280 -y 2464 -fps 15 -usestills -quality 95"
# Raspberry Pi Camera V1, maximum resolution, full field of view (4:3 aspect) at 15fps
# Notes: Not tested, may require stills mode
camera_raspi_options="-x 2592 -y 1944 -fps 15 -quality 95"
# Raspberry Pi Camera V1/V2, 1080P, partial field of view (16:9 aspect) at 30fps
# Notes: Using 16:9 aspect crops your field of view so you will see less
camera_raspi_options="-x 1920 -y 1080 -fps 30 -quality 95"
# Raspberry Pi Camera v2, 720P, partial field of view (16:9 aspect) at 30fps
# Notes: Using 16:9 aspect crops your field of view so you will see less
camera_raspi_options="-x 1280 -y 720 -fps 30 -quality 95"
There is a wide range of USB webcams (unlike the Raspberry Pi Camera for which there are only two models and two variants of each), so there is not a single list of modes available, you need to check what works for your camera. If you have settings that you know work well with your particular camera please add them here. The UVC input module for mjpg-streamer doesn't appear to offer control over the quality setting.
# UVC Webcam, default resolution and frame rate
# Notes: this is the default, your camera can almost certainly do better
camera_usb_options="-r 640x480 -f 10"
# UVC Webcam, 720P at 15fps
camera_usb_options="-r 1280x720 -f 15"
# UVC Webcam, 1080p at 25fps with 95 JPEG quality
camera_usb_options="-r 1920x1080 -f 25"
# Logitech C270 camera known working settings
camera_usb_options="-r 1280x720 -f 30"
If you're savy enough to setup Octoprint manually rather than using the Octopi image then you likely don't need to know this or your configuration will be done by working directly on the Octoprint YAML configuration files. For those using the simple Octopi image wanting to edit your configuration there are two methods:
On your PC you can just pop in the Octopi SD card and edit the octopi.txt configuration file just like you did when you first set it up. You don't need to know anything about Linux to do it this way.
If you don't mind a little command line and know what SSH is, SSH into your device and run:
sudo nano /boot/octopi.txt
Save the file when your done and reboot your device.
If you think nano is for whimps and want to use vi then you probably don't need these instructions.
Many users get confused by the fact that there is a framerate in the octpi.txt (or Octoprint YAML configuration) as well as one in the Octoprint user interface. The Capture Frame Rate is the one in the configuration file, while the Timelapse Framerate is the one in the Octoprint user interface.
This is the frame rate seen in the octopi.txt configuration file in the camera_usb_options or camera_raspi_options lines. It controls the framerate used for the live stream, it does not affect the timelapse directly at all1. In general, higher capture rates will impose more load on your device, so if you are using an early model Raspberry Pi you might want to be conservative. Capture frame is set with the -f option for USB cameras and the -fps option for the Raspberry Pi Camera followed by the desired framerate.
This is the frame rate seen in the Octoprint web user interface. This controls the speed at which your timelapse plays back once assembled. So, for example if your timelapse is set to trigger every 10 seconds, a 1 hour print will result in 360 frames, if your timelapse frame rate is set to 25 fps you will get a 14.4s final timelapse video. If set to 10fps you will get a 36s final timelapse video. If using Z-level triggering keep in mind the number of frames will be approximately the number of layers in your print, so you may wish to adjust the frame rate to a much lower value. For example, a 50 layer print at 25 fps would only run for 2 seconds (a very smooth 2 seconds), so you may instead wish to have each frame displayed longer and run at say 5fps to get a 10 second video.
Octoprint uses mjpg-streamer for capturing video streams. There are quite a few extra options you can pass in the camera_usb_options and camera_raspi_options settings. These are passed directly to mjpg-streamer, however note that not all cameras support all options so you need to experiment. Documentation for the extra options can be found here:
- The -usestills option for the Raspberry Pi camera does work, however it tends to look worse likely because less automated processing is performed on the resulting image.
- In tests, higher framerates consumer more CPU. For example on a Raspberry Pi 3, 90fps@720 consumed 17% CPU while 10fps@720 consumed only 6%. Unless you have a really good reason to avoid motion blur there is no reason to use higher than 30fps, doing so will also introduce a lot of latency into the live stream.
- Some aspect may benefit from having the Raspberry Pi MPEG license installed on your system if you use a Raspberry Pi (TBC).
1: While framerate does not have an effect on the timelapse capture process, strictly speaking it will affect the amount of motion blur visible in images captured during the timelapse process. In practice 30fps is more than enough to reduce the effect of motion blur but keep in mind higher framerates mean shorter exposure times and therefor either more light required or more noise due to the camera increasing the gain to get the same exposure (most cameras used with Octoprint are fixed apeture).