Setting up multiple webcams in OctoPi the right way

Hello @Cruel !

Would you mind sharing this?

I'm not sure if I understand why the guide wouldn't work if you had two USB cameras? You should be able to use as many as you like. If you had problems I would love to know to improve it.

Great Guide based on the the very first post, that worked fin for me in the end.

I struggled for an hour or so, but it all came back to one simple thing.

I was editing the files from both FileZilla or WinSCP with NotePad++ & on uploading the changes they we not sticking due to a permissions issue; no SUDO passed on.

Could not work out how I'd previosly edited the same Root file from a PC a few weeks back successfully, so just fell back to Nano & pasted inside Putty & Lo & behold it all worked.

Cam1 is a Logitech C922 set @ 1920x1080 10 fps
& Cam2 is a Generic Endodoscope @ 1280x960 10 fps.

Moral of the story is Question your own interpretation & means of following a guide before pointing out to the Author that it did not work.
(32 Years in IT here & can assure all I still slip up).

Cheers
PS.
One Question,

Is a 3rd Cam too much of an Ask?
If they are present but not being viewed do they still consume resources?

Ran into the same problem as @Kumuddel, two identical cams showing up with the same id. Using his solution I used path instead for the config files.

I still can't view the feed from the second camera.

octopi.txt

camera="usb"
camera_usb_options="-r 640x480 -f 30 -d platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-video-index0"`

webcam2.txt

camera="usb"
camera_usb_options="-r 640x480 -f 30 -d platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-video-index0"
camera_http_options="-n -p 8081"

haproxy.cfg added
use_backend webcam2 if { path_beg /webcam2/ }

and

backend webcam2
        reqrep ^([^\ :]*)\ /webcam2/(.*)     \1\ /\2
        server webcam2  127.0.0.1:8081
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

Edit: No matter what I put as the device it keeps going to the same camera.

Using -d platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-video-index0 is not a valid way of specifying the device, you'll need to give it the full path to the camera not just some name.

In the guide, it gets you to use /dev/v4l/by-id/yourLongCameraIDHere, I suspect if you are using by-path it should be /dev/v4l/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-video-index0 for example instead - note I haven't verified that, but that's what my memory would suggest. If it is located somewhere else adjust the path as necessary.

You could use this script by Paul P to automatically create rules by USB port location.

So I've changed the config files as suggested, adding /dev/v41/by-id/<device id> and still no joy.

As you can see below by-id only outputs a single device. Not sure how to procede from here.

pi@octopi:~ $ ls /dev/v4l/by-id
usb-HD_USB_Camera_HD_USB_Camera-video-index0
usb-HD_USB_Camera_HD_USB_Camera-video-index1
pi@octopi:~ $ ls /dev/v4l/by-path
platform-bcm2835-codec-video-index0
platform-bcm2835-isp-video-index0
platform-bcm2835-isp-video-index1
platform-bcm2835-isp-video-index2
platform-bcm2835-isp-video-index3
platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-video-index0
platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-video-index1
platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-video-index0
platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-video-index1

Will this just create rules or does this do a completely new install?

I didn't say use by-id, use by-path as that's where you've found the device. You have to be precise about what path you give it.

that script specifically just creates the udev rules. you would then be required to use the -d /dev/cam_<instance_name> in your config.

Correction, I used by-path

camera_usb_options="-r 640x480 -f 30 -d /dev/v41/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-video-index0"

It's a lowercase letter L, not the number one for v4l your friend looks like the number.

Not sure if it has been addressed but if anyone is using the newer version of OctoPrint Version 1.8.6 running on OctoPi Version 1.0.0, the Haproxy configuration may fail based on the fact 'reqrep' directive is no longer supported since HAProxy 2.1. The solution is to change the second line from the settings:

+ backend webcam2
+        reqrep ^([^\ :]*)\ /webcam2/(.*)     \1\ /\2
+        server webcam2  127.0.0.1:8081
+        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

Make sure it read as below:

+ backend webcam2
+        http-request replace-path /webcam2/(.*) /\1\ /\2
+        server webcam2  127.0.0.1:8081
+        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

Of course, remember the lines above MUST be added WITHOUT the + symbol! :slight_smile:

Always be careful when editing the haproxy.cfg file.

Cheers!

1 Like

That's a good point to raise - I'll try and update the guide ASAP with the updated configurations.

This did not work for me, the /\1\ /\2 needed to be changed to just /\2 for it to function.

Okay back at it. I ran the script recommended by @jneilliii and here's where I'm at

ls /dev/v4l/by-id output

usb-HD_USB_Camera_HD_USB_Camera-video-index0  usb-HD_USB_Camera_HD_USB_Camera-video-index1

/boot/octopi.txt

camera="usb"
camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/usb-HD_USB_Camera_HD_USB_Camera-video-index0"

EDIT
/boot/octopi.conf.d/webcam2.txt

camera="usb"
camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/usb-HD_USB_Camera_HD_USB_Camera-video-index1"
camera_http_options="-n -p 8081"

I can't get any video output from either cam

Edit
So after running the script I can only get octoprint to run by starting the service from cmd line, and only after a couple tries, it doesn't start at boot.

You don't make any mention of the 2nd config file; webcam2.txt

the http options belongs in the 2nd file.

I have this in each file

#Camera 1 - Octopi.txt

#Cam1 - Logitech C922
camera="usb"
camera_usb_options="-r 1920x1080 -f 10 -d /dev/v4l/by-id/usb-046d_C922_Pro_Stream_Webcam_1DA9D3AF-video-index0"



#Camera 2 - in Webcam2.txt
#Digitech Inspection Camera

#Cam2 - Digitec Endoscope
camera="usb"
camera_usb_options="-r 1280x960 -f 10 -d /dev/v4l/by-id/usb-Generic_USB_Camera_200901010001-video-index0"
camera_http_options="-n -p 8081"


Edited my post. second txt file was webcam2.txt

Please add major additions/changes to a new post. Especially for such long threads.
Frequent readers always get their newest post.
So if you edit a post in the past, the readers have to search the a lot of posts.

1 Like

#Camera 1 - octopi.txt