Whilst 3D printing I often check up on the print from another location and rely on being able to get a clear, high definition and sharp image. The C920 webcam from Logitech delivers great image quality but unfortunately the auto focus algorithm almost always choose the wrong focal point.

Today, I'll show you how to set a fixed auto focus point in Octoprint.

A beautifully crisp and well focused image for this print

It's actually a relatively straight forward thing to set the focus manually. We will use v412-ctl to do so.

Login to the Octoprint instance via SSH and execute the following commands. You can tune the final value 32 to set the focal length of the camera.

sudo v4l2-ctl --set-ctrl=focus_auto=0
sudo v4l2-ctl --set-ctrl=focus_absolute=32

A value of 1 focuses far away and 255 so close as to be all but useless for our purposes. I found a good range was in the 25-40 range, tweak it as you see fit.

Making things permanent

In order for the auto focus to be set to your preferred value above every time we must edit the mjpg-streamer startup file.

Again we being by SSH'ing into the Octoprint instance and then changing into the mjpg-streamer directory with

cd /home/pi/mjpg-streamer
vi start.sh
  • Note I used vi above which is my preferred text editor. You can replace vi with nano if you prefer.

Now we add the two lines to the top of the file, save and close. That's it.