Setting up multiple webcams in OctoPi the right way

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!

With the advent of the new camera stack for OctoPi it's not top of my priorities to get out my RPi cam & the old stack now to figure out what it should be. If it's simple and takes me 5 mins (or if someone else knows the answer) that would be good. I can't do it at the moment as I don't have the hardware accessible.

I can definitely recommend the new camera stack, which also makes adding new cameras even easier - it's available in the RPi imager as an additional option.

Has this plugin died :man_shrugging:

Not that I'm aware of. You have to manually install since it's unlisted. Go to plugin manager > get more and at the bottom in the ...from URL field copy/paste this url and click install.

https://github.com/jneilliii/OctoPrint-MultiCamView/archive/refs/heads/master.zip
1 Like

I did as resort from a backup and the plugin didn't reconfigure, try to install it manually, but that also failed.

Forgot about

Cheers works perfectly again :+1:

Is there an updated version for the new stack yet?

It's documented in the FAQ at the bottom.

Thanks for the documentation, unfortunately it doesn't work on the latest nightly octopi image (based on raspian bookworm). I get the error "The webcam server is currently not running".

The reason might be that they changed /boot to /boot/firmware (octopi.txt is also found there). So i tried to place the octopi.conf.d directory also there but it ignores it. Trying to place it in /boot does also not work.

Do you have any hint what should be modified to get it running on bookworm (cam1 is working well here)
I need to use bookworm since it has proper pi5 support and octoprint works there flawlessly.

1 Like

hello everyone, i try follow all the steps , but both cameras never work same time one work the other one just said server error, when i swap the cameras same thing only front camera or nozzle camera but never together

Same issue for me, I do not find working solution... Maybe there is a configuration to define file location for second camera.

I found a solution to get both cameras working.

  1. sudo service webcamd stop
  2. sudo nano /root/bin/webcamd
    Find:
    config_dir="${CONFIG_FILE}/octopi.conf.d"
    Replace:
    config_dir="/boot/firmware/octopi.conf.d"
  3. Save and Exit
  4. sudo service webcamd start

You made my day thanks a lot ! It works nice with this workaround.

Seem to have a number of Issues getting things going on the latest release with Bookworm.

Over previous days I have setup 3 Cameras Successfully on an older Test Version.
(Octopi 0.18.0, OctoPrint 1.8.7 & Multicam Plugin).

Currently working on a Clean Blank Install on the Same Pi with Same 3 Cameras.
Have done nothing but step thru the Wizzard & then log in.

In the interface I see the Logi C922 Working fine.
In my Browser I get the following issue.

http://192.168.59.27/webcam/?action=stream working OK, but
http://192.168.59.27:8080/?action=stream gets a "Connection Refused" Error.

To this point I have not proceeded at all regards adding the other Cams.
Just how it is straight off the freshly written SD card.

I have read the Thread Multiple Times & am aware of others posts, including the different location of Octopi.txt now being in /boot/firmware/ & the additional changes required for webcam2.txt

Almost seems like the Proxy is now blocking external access to the direct port URL.

Any further thoughts?

That seems close, but I suspect the mjpg-streamer config is locking connectivity to the port directly instead of going through haproxy (that's the one you say is working). So the streamer is configured to only accept connections from localhost and haproxy configuration is working correctly.

You could continue to setup the additional cameras and just make sure to update the haproxy to route /webcam1, /webcam2, etc....

Ok,
So I have all 3 working now on the latest version that I restored a backup to a few days ago.
(Not using the Clean Build SD Card right now).

All Visible on my PC at:-
http://192.168.59.27/webcam/?action=stream but not http://192.168.59.27:8080/?action=stream
http://192.168.59.27/webcam2/?action=stream and http://192.168.59.27:8081/?action=stream
http://192.168.59.27/webcam3/?action=stream also http://192.168.59.27:8082/?action=stream

But,

In Octoprint Multicam, I can't access them at 127.0.0.1 or localhost.
They do work there though if I specify the Pi's IP address in the URL.

Edit:- I do wonder if the behaviour is related to the code in haproxy.txt,
While I don't quite understand it, I see things like forwardfor,
and v4v6, which I presume references IPV6, which I've seen cause other local issues in different cases.

frontend public
        bind :::80 v4v6
        bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem
        option forwardfor except 127.0.0.1
        use_backend webcam if { path_beg /webcam/ }
        use_backend webcam_hls if { path_beg /hls/ }
        use_backend webcam_hls if { path_beg /jpeg/ }
        default_backend octoprint

This is what I was referring to when I mentioned adding the relative URLs, see the section from the original post OPTIONAL: Haproxy configuration.

I Do Believe I have haproxy setup fine as it appears to be working as mentioned above.
(Note:- I haven't edited the Snapshot URL's & they do not work).

Cameras available as /webcam/, /webcam2/ etc in my PC's Browser.

It's the fact that the Pi can't see its own cameras on 127.0.0.1 or localhost that is different.
Yet it can see them addressing it's own IP address.

My Full haproxy.cfg is as follows.

global
        maxconn 4096
        user haproxy
        group haproxy
        log /dev/log local1 debug
        tune.ssl.default-dh-param 2048

defaults
        log     global
        mode    http
        compression algo gzip
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        option http-server-close
        option forwardfor
        maxconn 2000
        timeout connect 5s
        timeout client  15m
        timeout server  15m

frontend public
        bind :::80 v4v6
        bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem
        option forwardfor except 127.0.0.1
        use_backend webcam if { path_beg /webcam/ }
        use_backend webcam2 if { path_beg /webcam2/ }
        use_backend webcam3 if { path_beg /webcam3/ }
        use_backend webcam_hls if { path_beg /hls/ }
        use_backend webcam_hls if { path_beg /jpeg/ }
        default_backend octoprint

backend octoprint
        acl needs_scheme req.hdr_cnt(X-Scheme) eq 0

        http-request replace-path ^([^\ :]*)\ /(.*) \1\ /\2
        http-request add-header X-Scheme https if needs_scheme { ssl_fc }
        http-request add-header X-Scheme http if needs_scheme !{ ssl_fc }
        option forwardfor
        server octoprint1 127.0.0.1:5000
        errorfile 503 /etc/haproxy/errors/503-no-octoprint.http

backend webcam
        http-request replace-path /webcam/(.*) /\1
        server webcam1  127.0.0.1:8080
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

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

backend webcam3
        http-request replace-path /webcam3/(.*) /\1
        server webcam3  127.0.0.1:8082
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http


backend webcam_hls
        server webcam_hls_1 127.0.0.1:28126
        errorfile 503 /etc/haproxy/errors/503-no-webcam-hls.http