OctoPrintLab
A 3D printer with a blue cube on its bed, wired to a Raspberry Pi-style board connected to a USB webcam and a ribbon-cable Pi camera module.
how-to

How to Add a Webcam to OctoPrint: USB and Pi Camera

Set up a USB webcam or Raspberry Pi Camera Module 3 in OctoPrint. Choose the right OctoPi image, find the stream and snapshot URLs, and fix a blank feed.

By OctoPrintLab Editorial · ·Updated · 5 min read

To add a webcam to OctoPrint on a Raspberry Pi, plug in a compatible USB webcam and boot the stable OctoPi image. OctoPi starts the stream when it detects the camera and supplies the stream and snapshot URLs. For a Raspberry Pi Camera Module 3, connect the ribbon cable while the Pi is powered off and boot an OctoPi build with camera-streamer. OctoPi README, Raspberry Pi camera installation, OctoPi camera stack

Which OctoPi image do you need for your camera?

These image choices are for OctoPi 1.1.0 with OctoPrint 2.0.1. The stable image’s MJPG-Streamer lacks libcamera support. Camera-streamer supports USB webcams and libcamera cameras, including the Camera Module 3. OctoPi 1.1.0 release notes, camera stack announcement, OctoPi-UpToDate camera-streamer release

CameraImage to flashWhere to find it
Compatible USB webcamOctoPi stable with MJPG-StreamerIn Raspberry Pi Imager, select Choose OS → Other Specific Purpose OS → 3D printing → OctoPi, then choose the stable image. OctoPrint setup guide
Raspberry Pi Camera Module 3OctoPi with camera-streamerDownload the image for the 2.0.1 build marked from branch camera-streamer and Pre-release. In Imager, select Use Custom to flash the downloaded image. OctoPi-UpToDate camera-streamer release, Raspberry Pi Imager instructions

For a ribbon camera, match the cable to the board. The Raspberry Pi 5 and Pi Zero series use the smaller board-side connector. With power disconnected, open the connector latch, seat the cable straight with the contacts facing away from the latch, and close it. Raspberry Pi camera installation

Setting up a webcam on the stable (mjpg-streamer) image

Open http://octopi.local/webcam/?action=stream in a browser. You can also try the streamer directly at http://octopi.local:8080/?action=stream. If you chose another hostname, use it in place of octopi.local. OctoPi README

On OctoPi 1.1.0, edit /boot/firmware/octopi.txt to change the USB camera’s resolution or frame rate. The webcam service uses /boot/octopi.txt as a fallback if the first file is absent. OctoPi 1.1.0 webcamd

The USB default is 640 × 480 at 10 fps. Replace the commented camera_usb_options example with an active line like the one below. Set -r for resolution and -f for frame rate to values your camera supports. Save the file and restart the Pi. OctoPi USB camera options, OctoPi restart configuration

camera_usb_options="-r 640x480 -f 10"

Some USB webcams produce no image when given -f. If that’s the symptom, use lsusb to find the camera’s vendor and product ID, then add it in octopi.txt using this line. Replace aabb:ccdd with the ID you found. OctoPi USB camera options

additional_brokenfps_usb_devices=("aabb:ccdd")

Setting up a webcam on the new camera stack

Edit usb-default.conf for a USB webcam or libcamera.conf for a Pi camera. On the SD card, both are in the camera-streamer directory of the boot partition. On a running Pi, the installer links that directory to /etc/camera-streamer.conf.d/. OctoPi-UpToDate installation script

These are the values in the stack’s USB configuration and libcamera configuration.

SettingUSBlibcamera
Primary camera port (PORT)80808080
Capture size (WIDTH × HEIGHT)1280 × 7201920 × 1080
Frame rate (FRAMERATE)15 fps15 fps
USB pixel format (FORMAT)YUYV—
Live view height (VIDEO_HEIGHT)—720
Snapshot height (SNAPSHOT_HEIGHT)—1080

Change the values in the file for your camera, save it, and restart the Pi. After it boots, check the feed in OctoPrint. OctoPi restart configuration

Camera Module 3 focus. The default OPTIONS line enables continuous autofocus when supported. To see the controls your running camera exposes, open http://<ip>:8080/option with your Pi’s IP address. libcamera configuration, camera-streamer configuration guide

OPTIONS='--camera-options="AfMode=2" --camera-options="AfRange=2"'

Add a second USB webcam. Plug it in and run the command below on the Pi. Select the new camera when prompted. The script picks the first port unused by the camera configs starting at 8080, writes /etc/camera-streamer.conf.d/usb-bedcam.conf, and starts or restarts that camera. OctoPrint add-usb-camera script

sudo add-usb-camera bedcam

Use WebRTC. Install Camera-Streamer Control through OctoPrint’s plugin manager, then select WebRTC in the plugin’s settings. The plugin can fall back to the MJPEG stream if WebRTC fails to connect. Camera-Streamer Control plugin guide

Configuring the webcam in OctoPrint’s settings

OctoPrint moved webcam settings to individual plugins in 1.9.0. Open Settings → Classic Webcam to check the bundled plugin’s live-view and snapshot URLs. OctoPrint 1.9.0 release notes, official OctoPrint Docker README

FieldOctoPi 1.1.0 valueWhat to check
Stream URL/webcam/?action=streamSelect Test to check the live feed. OctoPrint stream control
Snapshot URLhttp://127.0.0.1:8080/?action=snapshotSelect Test to check that OctoPrint can fetch a still for timelapses. OctoPrint snapshot control

The relative stream path and loopback snapshot address are the OctoPi 1.1.0 image defaults. For timelapses, OctoPrint also needs the FFmpeg executable set in webcam.ffmpeg. OctoPrint configuration reference

If the image is upside down or mirrored, use the Classic Webcam orientation controls. They can flip the feed horizontally or vertically, or rotate it 90 degrees counterclockwise. OctoPrint orientation controls

To switch between cameras in OctoPrint, register each feed through a webcam provider. When multiple views are registered, switch between them in the Control tab. OctoPrint 1.9.0 release notes

Why is my OctoPrint webcam stream black or not showing?

If prints stall after adding a camera, see the mid-print disconnect guide. For a feed that works locally, see the OctoPrint remote access guide for remote viewing or the OctoPrint plugin guide for camera integrations.

The setup is based on the OctoPi 1.1.0 and OctoPrint 2.0.1 sources, the camera-streamer stack configuration, and Raspberry Pi’s camera documentation. The steps were not run on hardware.

Sources

  1. OctoPrint.org: Download and setup OctoPrint
  2. Raspberry Pi: Installing an image with Imager
  3. OctoPrint.org: OctoPi release 1.1.0
  4. OctoPi-UpToDate: OctoPi 1.1.0 with OctoPrint 2.0.1 (camera-streamer)
  5. OctoPrint.org: A new camera stack for OctoPi
  6. Raspberry Pi: Camera Module software and installation
  7. OctoPi README
  8. OctoPi 1.1.0: webcamd
  9. OctoPi 1.1.0: octopi.txt
  10. OctoPi 1.1.0: default OctoPrint configuration
  11. OctoPi-UpToDate: camera-streamer installation script
  12. OctoPrint camera-streamer stack: USB defaults
  13. OctoPrint camera-streamer stack: libcamera defaults
  14. camera-streamer: Configuration
  15. OctoPrint camera-streamer stack: add-usb-camera
  16. OctoPrint Plugin Repository: Camera-Streamer Control
  17. OctoPrint.org: OctoPrint 1.9.0 release
  18. Official OctoPrint Docker README: Classic Webcam settings path
  19. OctoPrint 2.0.1: Classic Webcam stream field
  20. OctoPrint 2.0.1: Classic Webcam snapshot field
  21. OctoPrint 2.0.1: Classic Webcam orientation controls
  22. OctoPrint: config.yaml reference
  23. OctoPi-UpToDate: camera-streamer troubleshooting logs
  24. OctoPrint camera-streamer stack: camera detection utility

Related