Setting up multiple webcams in OctoPi the right way

Thank you!

This really works, simple and easy.
Looking forward to that Haproxy guide ^.^

@PrintedWeezl , Yes. it show up very nice.

3 Likes

Hello @Charlie_Powell,

I am searching for a way to connect two cameras to my octoprint docker container. Unfortunately there is no Octoprint.txt-file. There is just a config.yaml, but I wasn't able to make this work.

Can you give me any advices on this topic?

Thanks!

Hi, this guide only works on OctoPi installs since it takes advantage of the code for multiple cameras that already exists.

If you are already using docker, why not create another dedicated streamer container? There's loads out there that use mjpg streamer, or some of the other streamers. Using containers is designed to split up tasks rather than one container to do everything (which would be a whole OS I guess.... :wink:)

Hi there,

Thank you for that tip. I was wondering to find something easy for set up my second usb camera but seems to do not work...
I have strictly followed your instructions but the second camera seems to do some issues.

On the Rpi3b i have one picam that works well. I wanted to add some more with an usb camera.
when i try to go to http://mypi:8080 there is blank page but i got the stream on the 8081 withe the picam ?!

Any idea for get it out of there ?

By default on OctoPi, the first instance of mjpg streamer (on port 8080) is only available through haproxy, so under /webcam/ there.

What i understood is to go http://ipofpi:8080 for see the picam and going further to http://ipofpi:8081 for get the stream from my webcam ...
I just roll back the whole thing and try to setup again ... passed my whole day on it ...

This setup does not change the original camera you had setup. So don't change the URL it is using. Nowhere in this guide does it say use :8080 for the first camera, just for the second. I suppose I could make it clearer that the existing camera streaming does not change.

Use http://ipofpi/webcam

Correct

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