top of page

Outside The Box : Multiple Webcam Setup with OctoPrint

Updated: Apr 24, 2019

Multiple webcams are possible with OctoPrint and there are a number of reasons to have multiple cams on your prints. I personally recommend an endoscopic camera as it gives you remarkable insight to why prints don't adhere or why they fail. It gives you the ability to adjust flow and feed rate to help your prints mid stream. This article however is going to cover only the installation of multiple webcams not specifically any type of webcam. You can apply it to virtually any number of cameras.


Before you dive into the attempting to set this up you should be aware of some challenges for multiple webcams.

  • CPU

  • Power

  • USB Bus Capacity

These three things are going to greatly impact your ability to run multiple cameras. Lets dive right into them.


CPU

If you have OctoPrint installed on a traditional PC then you're way ahead of the game and can likely just skip to the USB Bus capacity section. If you like many others are running a Raspberry PI for OctoPrint then you can likely still run a couple of web cams but the odds are stacked against you. Most modern webcams (usb type) tend to have some encoding features on them already. This is called USB Video Class or UVC. In this case the web cam does a lot of the heavy lifting and it is widely supported for Linux, Mac and Windows. Other web cams without it are going to require far more CPU from your PI. Choosing UVC webcams will allow you to have multiple cams on your Raspberry PI, maybe...


Power

The next challenge you are going to have if you're using a Raspberry PI is power. The Pi and the USB ports will likely not support 2 active web cams. I was able to successfully get 2 of them running but they ran into power drops all the time. If you run the command "vcgencmd get_throttled" and get a non zero return code you're likely running into power drops. Again hope is not lost because a good (and finding one was hard) USB hub can power the device completely. Cheap hubs don't cut it. I was able to use the RPi Powered USB Hubs list to find one that worked well.


USB Bus Capacity

Lastly you need to be concerned about the overall capacity of the USB bus for these webcams. On a traditional PC you're slightly better off because chances are you have 2 USB hubs internally. Not always the case but if you have USB 3.0 you'll get much better bandwidth. Otherwise you may max out at 2 webcams. Under Linux you'll receive a no space left on device error if you use up all the bandwidth on the bus when setting up the second cam.



Getting Started

This guide presumes you're running linux in some fashion. This guide could be applied for Mac Or Windows Octoprint installs but I wont cover them in this guide.


Once you have two cams plugged in you'll noticed at least on linux that you now have a


/dev/video1

/dev/video2


These are your respecitve webcams 1 and 2. If you have a 3rd you'll see this increase for the number of cameras installed in the system. It should be noted that these are not always assigned the way you want them to be. My previous primary camera became the second camera and that will affect the way OctoPrint operates. Once you the second camera go into OctoPrint and confirm which camera is your default camera. You'll be able to change this inside OctoPrint later if you find they are assigned to the wrong camera.


Once you know now which camera is which we need to get the second camera up and running. Before we start to setup the configuration files you'll need to test the cam. Move to the /root/bin directory and you'll find webcamd.

You now need to copy that file to webcam2d. Then you need to copy a file in /boot/ which will contain the configuration settings.

Next you're going to edit the newly created octopi-cam2.txt file


Locate the camera_usb_options line in the file and point this to your second webcam. The one that is not working yet. This will be the /dev/video2


This configuration sets the FPS on the camera to 30, and specifies the device to use. You may need to also modify the octopi.txt file to include the /dev/video1 camera. Just modify the line in the same fashion you modified this one.


Now go to the bottom and make another configuration change. The default port is 8080 you're going to add a new port for 8081 which will allow you to see the second camera.


Once this is setup, save the file.


Next you'll need to make a small tweak to the webcam2d that you created to pick up the configurations from the other file.

You need to modify the file where it loads in the configuration file. Just open the file and scroll down a little you'll see where it says octopi.txt just add the -cam2 to those file names like the example below.

Now you should have everything set to actually check if the cam is working. You should be able to run the shell script webcam2d and it should connect to everything. It should display something like the following.

You should also see a lot of other information but if you're not receiving error messages you should have it configured correctly. You are now ready to test your configuration.


This next part is going to vary greatly based on how you have your network setup and octopi setup. The easiest way is to look at the setting you have for "Webcam & Timelapse" currently in OctoPrint.


http://octo.local:8081/?action=stream


It could also have an IP address in there. Essentially you want the new port in there and the same current address. Pop that into your browser and if you have configured everything right you should see your second webcam. If you do congrats as you have two web cams working on your OctoPi. Some say it can't be done but indeed it can!


If you receive an error that says "No space left on device" that means your USB hub has not enough bandwidth. Try another USB port. On the Pi though you only have one hub so you can try lowering the framerate and resolution.



No coffee breaks yet you still need this to start automatically. You need to copy 2 files to make this happen. Then start by editing webcam2d.

In webcam2d you'll want to look for "webcamd" and replace it with webcam2d.


Then edit the file in /etc/default and do the same. Replace webcamd with webcam2d.


This should now enable the second camera at boot. You should be able to reboot and it should start up and be available.


The last piece of this is OctoPrint itself. Under the plugin manager install "MultiCam".


This plugin will allow you to setup the second camera under the "Control" section on the main OctoPrint screen. Once this is installed go setup your camera settings under MultiCam.


This is where you use the same URL you tested your your connection earlier. As you can see in my example here I have 3 cameras installed. Each one has a different port number on the same server. If you repeat the process above for a 3rd camera everything applies except adding a 3 instead of a 2.


Once you save this configuration you should have your cams listed on the control tab of OctoPrint.


You can see here I have the Top View Selected and its working perfectly.


The process can be repeated really for any number of cameras until you've used up the available bandwidth on your USB hub. USB3.0 will get more mileage than 2.0.


You can also change the filenames from the examples I gave here. I chose webcam2d simply because it was easy. Your naming can be your own. webcam3d, etc.


That's it. Some simple configuration changes and you can have multiple cameras. If you have a non-pi setup the same basically applies except that your directories are different. If you're interested in setting up OctoPrint on a regular PC then please check out

my article on Ditching OctoPi and keeping OctoPrint it is some effort but well worth it if you're linux savvy enough to complete the install.


Please let me know how this works out for you. I'm happy to answer any questions in the comments. Good luck!




19,229 views12 comments

Recent Posts

See All