Setting up multiple webcams in OctoPi the right way

Greetings,
Thanks for the write up. Unfortunately it is not working for me.
I have a PS3 eye camera for overall print monitoring and am trying to add an endoscope camera for the nozzle.
After following the guide and restarting the service all appeared to work correctly, however after a reboot the nozzle camera is my default and my PS3 eye is unreachable.
I have included my webcamd.log file.
Any help would be greatly appreciated.
webcamd.log (1.5 MB)

The OP methods have never worked for me using a logitech c920 & raspi cam. I previously setup a bunch of custom bash scripts using screens and streamer script calls that encoded all the related device information. Upgrading my pi w a fresh octoprint install I figured I'd try the status quo methods again and though initially just the raspi cam was working, after trying to add the usb then only the usb cam was shown and not the pi. The logs showed that "device was not set" for the USB (even though it explicitly was by id in the options). What I DID find worked for a simple setup is 1) do not put "raspi" in the octopi.txt at the top for the camera, 2) do not use by-id for the USB but rather use /dev/video# after finding the specific number. Adding camera="raspi" in the main config or using by-id breaks things for me (for whatever reason, since I didn't find the logs illuminating, as least not quickly so). Adding the usb device by OP's method also breaks things. Obvious drawbacks to not using device by id is that inevitably the devices will change and you'll have to remap. If anyone can shed light on why the OP method doesn't work, it'd be appreciated. Could the device-by-id string just be too long for whatever scripts this is feeding into (the c920 name is quite long)?

camera="raspi" will not work on OctoPi 1.0.0 (& this should be documented in the octopi.txt file, although this guide still alludes to using it), since support for that driver was removed by upgrading to Bullseye. It's on my list to update this guide, but it will also need updating again for the new webcam stack that's under development so I have been putting it off.

Without actually seeing your configuration files and webcamd.log, it is impossible to say why it doesn't work for you.

Is there something different that's needed to be done when using a powered USB hub for your webcams?

I'm not getting any output from my Raspberry Cam only from USB.

I have an IMX219, so I added the following to config.txt


dtoverlay=imx219

and changed camera_auto_detect=1 to

camera_auto_detect=0

as for octopi.txt

camera_usb_options="-r 640x480 -f 10"

camera_http_webroot="./www-octopi"
camera_http_options="-n -p 8080"

and for webcam2.txt

camera="usb"
camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/usb-Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001-video-index0"

camera_http_webroot="./www-octopi"
camera_http_options="-n -p 8081"

Webcam Log.log (9.0 KB)

How do I specify raspicam without "raspi" being an option for to set for camera="raspi" ? It's just autodetecting the USB webcam, unless there's something that I'm doing wrong?

The IMX219 sensor is not supported by the current webcam stack. Please try the new one that is in testing from the below issue:

Note: this is a complete rewrite of webcam support, so this guide does not apply.

I'm not getting any output from my Raspberry Cam only from USB.

I have an IMX219, so I added the following to config.txt


dtoverlay=imx219

and changed camera_auto_detect=1 to

camera_auto_detect=0

as for octopi.txt

camera="usb"
camera_usb_options="-r 640x480 -f 10"

Ah, yes. Sorry I forgot I had used that before working on this. Thank you.

Tried to set up my usb cam but this guide does not work with octopi 1.0 as it looks like. Cam ID command does not work anymore and not able to setup my USB cam. Any information when you will rework this guide for 1.0?

Not sure what you mean by this - it should work fine on OctoPi 1.0.0. The camera="raspi" mode no longer exists, but otherwise it works the same. Can you provide some more details of what is not working? What output do you get when trying to set it up?

ls /dev/v4l/by-id when running this I get the message no such file or directory

That indicates that your camera is not recognised by the system. When there are no cameras to be found, you get 'no such file or directory'. Upon plugging in the camera, it is created. I would probably recommend opening your own topic to debug why your camera is not recognised, but have a look at commands such as lsusb and dmesg to help.

Hi,

I'm having the problem with multiple cam. One is a normal webcam and another is endoscope.

Haven't had luck for them to work at the same time. After every boot it seems random which camera works. And if I reboot without making any configuration change, then it might be the another camera that works.
I have the MultiCam plugin added and I can switch between cameras with the buttons (but just that only one works at the time).

What could cause this kind of behaviour and is there something that could be changed in config for both of them to work?

I have not done the Haproxy configuration part.

Good day Charlie
I am apealing to you as the "go to guy" for all things webcam related on the Raspberry Pi 4+ / Octopi :grin:
After running Octopi for a couple of years using a script provided by Chris Riley who managed to get my Pi cam, Logitech 270 & Logitech C920 running via multi-cam in octoprint. I ran across a problem where after a new SD card was needed i found i could no longer use the same script. Now i have tried following Chris's updated youtube instructions but some of the part he refers to no longer seem to be present in the "Octopi.Txt" file, such as "default camera" and i also see a comment saying RaspiCam is no longer in theOctopi.Txt file but is reffered to in something called the UVC folder!!!!
Being a complete novice to the Octopi language i am at a complete loss.
This is where i come cap in hand to your good self for pointers and directions to get my setup running again! Does the thing about RaspiCam & UVC get dealt with in [latest camera-streamer based webcam stack build (20230328122604) ??? Or am i barking up the wrong tree??
Please, any pointers would be greatly appreciated, and appologies if i have contacted you in the wrong way! Thanks

Open a new topic if your questions are not related to this guide

Done that Charlie

What i have done to "fix" this is i added a restart of the service after boot inside the crontab.

sudo crontab -e

in the crontab file at the end of the file add the following.

@reboot sleep 30 && sudo service webcamd restart

The command will be executed after every boot with a delay of 30 seconds.

you could probably also use event manager in OctoPrint to do the same command on server startup.

It seems that I removed everything according to the instructions.
But the second camera did not start.

sudo service webcamd status
● webcamd.service - the OctoPi webcam daemon with the user specified config
   Loaded: loaded (/etc/systemd/system/webcamd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2023-05-07 01:16:44 MSK; 1s ago
  Process: 2136 ExecStart=/root/bin/webcamd (code=exited, status=0/SUCCESS)
    Tasks: 6 (limit: 1939)
   CGroup: /system.slice/webcamd.service
           β”œβ”€2179 ./mjpg_streamer -o output_http.so -w ./www -n -p 8082  -i input_uvc.so -r 1280x720 -d /dev/video0
           └─2197 ./mjpg_streamer -o output_http.so -w ./www -n --listen 127.0.0.1 -i input_uvc.so -r 1280x720 -f 10 -d /dev/video2

May 07 01:16:43 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: Format............: JPEG
May 07 01:16:43 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: TV-Norm...........: DEFAULT
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: www-folder-path......: ./www/
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: HTTP TCP port........: 8080
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: HTTP Listen Address..: 127.0.0.1
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: username:password....: disabled
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: commands.............: disabled
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: starting input plugin input_uvc.so
May 07 01:16:44 octopi mjpg_streamer[2197]: MJPG-streamer [2197]: starting output plugin: output_http.so (ID: 00)
May 07 01:16:44 octopi systemd[1]: Started the OctoPi webcam daemon with the user specified config.

hi ive tried and its not working when i test. http://192.168.0.107:8082

for some reason i dont seem to have a /var/webcamd.log so cannot look in there, i would realy apreciate some help.
thanks
martin
my webcam2 file

### Configure which camera to use
#
# Available options are:
# - auto: tries first usb webcam, if that's not available tries raspi cam
# - usb: only tries usb webcam
# - raspi: only tries raspi cam
#
# Defaults to auto
#
camera="usb"

### Additional options to supply to MJPG Streamer for the USB camera
#
# See https://github.com/foosel/OctoPrint/wiki/MJPG-Streamer-configuration
# for available options
#
# Defaults to a resolution of 640x480 px and a framerate of 10 fps
#
camera_usb_options="-r 1080x720 -f 10 -d /dev/v4l/by-id/usb-Huawei_HiCamera_12345678-video-index0"



### additional options to supply to MJPG Streamer for the RasPi Cam
#
# See https://github.com/foosel/OctoPrint/wiki/MJPG-Streamer-configuration
# for available options
#
# Defaults to 10fps
#
#camera_raspi_options="-fps 10"

### Configuration of camera HTTP output
#
# Usually you should NOT need to change this at all! Only touch if you
# know what you are doing and what the parameters mean.
#
# Below settings are used in the mjpg-streamer call like this:
#
#   -o "output_http.so -w $camera_http_webroot $camera_http_options"
#
# Current working directory is the mjpg-streamer base directory.
#
camera_http_webroot="./http://192.168.0.107"
camera_http_options="-n -p 8082"

# Configuration of network monitoring
#
# This enables network monitoring for wifi connections with a simple ping test.
# If connection terminates by variable reasons system tries to restart the wifi connection to reestablish a connection.
# The connection test is done every minute.
# By default it is disabled (0 = off / 1 = on)
# destination_host can be an ip address or a hostname (for hostname ensure dns resosultion is working correctly)
#enable_network_monitor=0
#destination_host=192.168.1.1

### EXPERIMENTAL
# Support for different streamer types.
#
# Available options:
#   mjpeg [default] - stable MJPG-streamer
#   hls - experimental FFMPEG HLS streamer
#camera_streamer=mjpeg

An update to this guide would be so helpful!

I can no longer have 2 cameras.

I see my USB Camera but I cannot use my raspicam anymore when I try to use multiple cameras since the camera="raspi" has been removed and I don't know which device I have to add to the "camera_usb_options=" via parameter "-d" because this is simply not in the not updated yet guide.
I tried to use the -d dev/v4l/by-path/platform-bcm2835-isp-video-index0 but it doesnt work.

So long I have to go with 1 camera but 2 cameras are so convinient and maybe there could also be a UI within OctoPrint for this instead of having to fiddle around with the files (just a wish for the future).

Thank you for all the great work so far. Enriches my 3D printing life so much!