Setting up multiple webcams in OctoPi the right way

noway it gave me the same as before ...
when I go on http:/ipofpi/webcam i get this :

The webcam server is currently not running

on the navigator ...

I guess i will make a fresh install and do it again ...

I just feel a little bit dumb right now ... :smiley:
But thank you for that advice, I managed it to setup two camera streams and embed it into OctoPrint with the MultiCam-Plugin and a dockerized version of the ustreamer.

Here is my docker-compose.yml-file, I just added one ustreamer-instance for every camera and used different ports:

version: '2.4'

services:
  octoprint:
    image: octoprint/octoprint:latest
    restart: unless-stopped
    ports:
      - 80:80
    devices:
     - /dev/ttyACM0:/dev/ttyACM0
    # - /dev/video0:/dev/video0
    volumes:
     - octoprint:/octoprint
    #environment:
    # - ENABLE_MJPG_STREAMER=true
    # - MJPG_STREAMER_INPUT=-r 1080x720 -fps 20 -rot 180

  ####
  # uncomment if you wish to edit the configuration files of octoprint
  # refer to docs on configuration editing for more information
  ####

  config-editor:
    image: linuxserver/code-server
    ports:
      - 8443:8443
    depends_on:
      - octoprint
    restart: unless-stopped
    environment:
      - PUID=0
      - GUID=0
      - TZ=Europe/Vienna
    volumes:
      - octoprint:/octoprint

  ustreamer_USB_Cam:
    image: beholderrpa/ustreamer:latest
    ports:
      - 8080:8080
    devices:
      - "/dev/video0"
    entrypoint: [ "./ustreamer", "--device=/dev/video0", "--host=0.0.0.0", "--slowdown", "--format=JPEG", "--resolution=1080x720", "--desired-fps=20"]

  ustreamer_Pi_Cam:
    image: beholderrpa/ustreamer:latest
    ports:
      - 8090:8080
    devices:
      - "/dev/video2"
    entrypoint: [ "./ustreamer", "--device=/dev/video2", "--host=0.0.0.0", "--slowdown", "--format=JPEG", "--resolution=1080x720", "--desired-fps=20"]

volumes:
  octoprint:

Further, I just adapted the IP-Adresses in the config.yaml-file. I don't know if this is good practice, but it works for me.
I still have problems to work on:

  • I have to rotate the Pi-Camera 180 degree. Unfortunately, the rotation function from the MultiCam-Plugin is delayed and I wasn't able to make the ustreamer do the rotation.
  • I want to expose the camera stream just in a docker network and not in my local network (this is just for educational reasons, I want to expand my docker-skills :smiley:).
3 Likes

Fresh install do the thing :slight_smile: :slight_smile:
Thank you !

1 Like

Thanks for this valuable guide which got me on the right track. For me it's a raspiCam and a cheap webCam which I found listed in the ### Additional webcam devices - section. Neither camera nor camera_usb_options did any good for the second cam.
I identified the vendor:model values in the output of dmesg so the one uncommented config line was
additional_brokenfps_usb_devices=("1908:2311"), and I set camera_http_options="-n -p 8081".
Testing it in the browser it didn't seem to work but while I tried different combinations I noticed that only this setup showed two entries when checking with systemctl status webcamd. Testing it in the browser worked only after a reboot of the raspi.

you are a legend, after 4 months of headache i was able to do it in less than 1 hour, thanks a lot

2 Likes

Hey, thank you for this post! This was much more simple than those youtube videos! (especially just to get picam and webcam working)

I do want to address some snags I've encountered when trying to get this working. I don't think this is compatible with octoprint v0.17 because when I completed the steps the second camera would be just ignored. I had to flash the latest v0.18 of octoprint to get this to work. Just a heads up for those who can't seem to get this to work. After that, it just works!

Admittedly I didn't test it with 0.17, all the setups I have are 0.18. I think I just went with code review to work out when it was added. Maybe there were some small changes or bugs fixed I didn't notice.

I did everything you said.. and i'm able to see all 4 of my cameras. 3 usb cameras and 1 raspicam and all the usb cameras are on a 12v/3a powered usb hub. Now my problem. after initial connection, I can see all 4 cameras. But after about 20-30 min.. One camera stops working.. then after about 1hr or so a 3rd camera stops working. So now only 2 cameras works from then on. I know I can restart webcamd service and i'm back in business again. But just wondering is there a camera limit per service? or is there some resource I can extend so it can handle 4 cameras. I can see that i have plenty of CPU and Memory available. Or maybe I did something wrong. Thanks for the help.

RC

You're probably running into some USB based limit on throughput at some point the more cameras you add. Not sure if there would be any way to counter that outside of running the cameras off of their own separate system, utilizing something like motioneye OS. The other option would be to try ustreamer instead of mjpg. It takes a little bit to get set up, but once it is it's fairly easy to add cameras to it as well, albeit done a little differently with multiple services for each camera.

ok thanks.. I knew having a powered hub was a must.. but didn't think there would be throughput issue. I'm not a linux guru but will give a ustreamer a try.. hope they have good tutorials.

Thanks again.

If you can, check the temperatures of the USB chip on the board, on the Pi 4 particularly I have seen people put heatsinks on as they can overheat and it is possible it is cutting some of the load - I'm not entirely sure if that is the case or how that works, but maybe something to keep in mind. Some brief details on the raspberry pi documentation, the dmesg command would definitely be useful - it may provide you with errors when the cameras go down.

ok will have to take out pi4 and see if the chips are hot. And will check the logs... Thanks again

After tinkering around a bit.. no heat issue on the usb chip, but I was able to get all 3 "usb" cameras working if I disabled my raspicam. And those have been constantly streaming for about 2 days. So the raspicam is taking resources away but not sure where. I'm going to try a 4th USB camera and see how that goes. Now to find a usb camera no one will notice not being there.. hahahaha

you could try forcing your raspicam to run in usb mode by setting camera="usb" and it will still work.

I tried your suggestion but its only going back and forth of my usb cameras. Since i'm not defining a device id.. think its going from /dev/video1 or video2 or some video device but not the raspicam. In the webcamd.log shows a lot of invalid V4L2_set_control errors. so unless there is another way to specifically call the raspicam not sure if this is going to work. But please correct me.. ok gonna back to the camera hunt..

Serving multiple webcam streams with https://

I had followed Let's Encrypt on OctoPi to serve it all on https:// now how to get the additional usbCam into the scheme?

I did it thus, adding two bits to /etc/haproxy/haproxy.cfg

frontend usbcam
        bind :::8082
        bind :::8443 v4v6 ssl crt /etc/ssl/private/intern/octopi.intern-combined.pem
        use_backend usbcam


backend usbcam
        server usbcam1  127.0.0.1:8081
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

This isn't usually required, I'm not entirely sure why you have an additional frontend block outside the standard frontend public one. Editing the haproxy setup as above in the guide works for me, and uses https for every webcam I add.

thanks to this guide I was able to get both of my cameras working but every time the PI needs a reboot, refresh of octoprint or I power it down for any amount of time, I have to send ssh to restart webcamd. Does anyone have any ideas of a work around or a fix?

what does it return when you ssh into the pi and type:
systemctl status webcamd