How to Turn Off Webcam Autofocus in Klipper (Crowsnest, 2026)

How to Turn Off Webcam Autofocus in Klipper (Crowsnest, 2026)
Thomas Admin5 min read
0 views

This guide is updated for October 2026 and rewritten for current Klipper setups.

MainsailOS and most Klipper installs now stream webcams with Crowsnest, so the fix is one line in crowsnest.conf. The old mjpg-streamer and rc.local method is still covered at the end for older installs.

Short answer: To turn off webcam autofocus in Klipper, add a v4l2ctl: line to your camera's [cam 1] section in crowsnest.conf, for example v4l2ctl: focus_automatic_continuous=0,focus_absolute=35, then restart Crowsnest. Use focus_auto=0 instead if your camera lists that control. The setting survives reboots, and no scripts are needed.

Why turn off autofocus on a 3D printer webcam?

Webcam autofocus is a problem on 3D printers because the camera keeps refocusing as the print head and bed move. The result is a stream and timelapses that pulse in and out of focus. I first ran into this with a Logitech C920 on my Klipper printer. Locking the focus at a fixed value gives a sharp, stable image of the build plate.

How to turn off autofocus with Crowsnest (MainsailOS, 2026)

Crowsnest is the webcam service used by MainsailOS and most current Klipper installs. Its v4l2ctl option passes camera controls to the V4L2 driver every time the stream starts, according to the Crowsnest documentation.

  1. List your camera's controls. Open an SSH session to the Pi and run v4l2-ctl -d /dev/video0 --list-ctrls. Install the tool with sudo apt install v4l-utils if it is missing. The same list is in crowsnest.log. Look for focus_automatic_continuous or focus_auto, and note the focus_absolute range. On my C920 the range is min=0 max=250 step=5.
  2. Find a good focus value. With an object in the middle of the bed, test values live: v4l2-ctl -d /dev/video0 --set-ctrl=focus_automatic_continuous=0, then v4l2-ctl -d /dev/video0 --set-ctrl=focus_absolute=35. Change the number until the stream is sharp. Values must be a multiple of the step (5 on a C920).
  3. Edit crowsnest.conf. In Mainsail, open Machine, then crowsnest.conf. It is in ~/printer_data/config/. Add your values to the camera section:
    [cam 1]
    mode: ustreamer
    port: 8080
    device: /dev/video0
    resolution: 1280x720
    max_fps: 15
    v4l2ctl: focus_automatic_continuous=0,focus_absolute=35
    Parameters must be separated by commas without spaces.
  4. Restart Crowsnest. Use Save & Restart in Mainsail, or run sudo systemctl restart crowsnest. Then check crowsnest.log for errors.

focus_auto or focus_automatic_continuous: which one?

The correct control name is whichever one your camera lists in v4l2-ctl --list-ctrls. Newer Linux kernels report the Logitech C920's autofocus as focus_automatic_continuous, while the Crowsnest docs example uses the older focus_auto. In Crowsnest issue #96, C920 owners report that switching from focus_auto=0 to focus_automatic_continuous=0 fixed a crash loop. Crowsnest skips controls the camera does not support and logs a warning.

What focus value should I use?

The best focus value is the one you find by testing, because it depends on the distance from the camera to the bed. On my C920, focus_absolute=35 was sharpest for my printer. I also tried letting autofocus settle on an object in the middle of the bed and reading back its value with v4l2-ctl -l. That gave 40, which was slightly soft. The textured PEI sheet probably pulled the autofocus off the object, so tuning by eye works better.

Other webcam settings worth locking

The other webcam controls worth locking are exposure, white balance and power-line frequency, which also drift during a print:

  • Exposure: automatic exposure flickers when the printer's LEDs change. On many UVC cameras, lock it with auto_exposure=1 and an exposure_time_absolute value (older kernels: exposure_auto, exposure_absolute).
  • White balance: use white_balance_automatic=0 with a fixed white_balance_temperature for consistent timelapse colour.
  • Power-line frequency: set power_line_frequency=1 (50 Hz, Europe) or 2 (60 Hz, North America) to remove banding under mains lighting.

Combine them on one line, for example v4l2ctl: focus_automatic_continuous=0,focus_absolute=35,power_line_frequency=1.

Older installs: mjpg-streamer and rc.local

The legacy method is for FluiddPi or MainsailOS images from before Crowsnest, which used mjpg-streamer. It runs the two v4l2-ctl commands at boot from /etc/rc.local, placed before the final exit 0 line:

v4l2-ctl --set-ctrl=focus_automatic_continuous=0
v4l2-ctl --set-ctrl=focus_absolute=35

Raspberry Pi OS images from April 2022 onwards no longer ship a default pi / raspberry login, according to the Raspberry Pi announcement. Log in over SSH with the user you created when you flashed the card. On Windows, the built-in ssh command in PowerShell replaces PuTTY.

FAQ

Why does my webcam keep going out of focus in Mainsail or Fluidd?

Continuous autofocus is the cause. The camera refocuses on the moving print head and bed. Disable it with focus_automatic_continuous=0 (or focus_auto=0) in the v4l2ctl line of crowsnest.conf, and set a fixed focus_absolute.

Does the autofocus setting survive a reboot?

Crowsnest settings are permanent: settings in crowsnest.conf survive reboots, because Crowsnest re-applies v4l2ctl every time it starts the stream. Commands typed directly with v4l2-ctl are lost on reboot or when the camera is unplugged.

Which webcams support manual focus?

Manual-focus webcams are the ones that list a focus_absolute control in v4l2-ctl --list-ctrls. Common examples are the Logitech C920, C922 and Brio. Fixed-focus cameras such as the Logitech C270 have no focus control, so there is nothing to turn off.

Does this work with OctoPrint?

The v4l2-ctl method is compatible with any Linux webcam, including OctoPrint on OctoPi. OctoPi has no crowsnest.conf, so apply the settings at boot instead, for example with the rc.local method above.

More Klipper builds: my Fenrir CoreXY printer runs Klipper, and you can find more printer projects on TinkerAtlas. Having print problems instead? See 30 common 3D printing problems and solutions.