Raspi cam + USB Webcam on manually installed Octoprint

I have struggled so much to make my 2 cameras working properly with the multicam plugin that I feel like I have to share the working configuration.

Camera 1 = official Raspicam
Camera 2 = Creative Technology, Ltd Live! Cam Socialize [VF0640]
Raspbian version: Raspbian GNU/Linux 10 (buster)
Octoprint version: Version 1.3.11 manually installed using this guide
Required Plugin: Multicam 0.2.6 by Michael Morris

The main struggle is to get both camera streaming at the same time on 2 different ports then getting them being displayed in Octoprint.

I have tried a lot of tricks to start 2 streams with absolutely no luck, I don't know why if one camera USB is connected, it disconnects the raspicam and only streams the USB webcam. So my solution might look dirty but it works for now. I wish I could start both streamings using the same webcamDaemon file. If a script master is present, please give me a tip.

Here are the scripts I modified:

./scripts/webcamDaemon is left untouched

./scripts/webcam is modified as follow:

!/bin/bash
# Start / stop streamer daemon

case "$1" in
    start)
        /home/pi/scripts/webcamDaemon >/dev/null 2>&1 &
       pushd /home/pi/mjpg-streamer/mjpg-streamer-experimental
       export LD_LIBRARY_PATH=.
        ./mjpg_streamer -o "output_http.so -w ./www -p 8081" -i "input_raspicam.so -fps 10" &
       popd &
       echo "$0: started"
        ;;
    stop)
        pkill -x webcamDaemon
        pkill -x mjpg_streamer*
        echo "$0: stopped"
        ;;
    *)
        echo "Usage: $0 {start|stop}" >&2
        ;;
esac

.octoprint/config.yaml:

section multicam

multicam:
    _config_version: 1
    multicam_profiles:
    - URL: http://My_Octoprint_address:8081/?action=stream
      isButtonEnabled: false
      name: Raspi
    - URL: http://My_Octoprint_address:8080/?action=stream
      isButtonEnabled: true
      name: USB CAM

Section webcam

webcam:
  ffmpeg: /usr/bin/ffmpeg
  snapshot: http://127.0.0.1/?action=snapshot
  stream: http://My_Octoprint_address:8081/?action=stream

/etc/haproxy/haproxy.cfg

at the end of the file

frontend public
        bind :::80 v4v6
        use_backend webcam if { path_beg /webcam/ }
        use_backend webcam1 if { path_beg /webcam1/ }
        default_backend octoprint

backend octoprint
        reqrep ^([^\ :]*)\ /(.*)     \1\ /\2
        option forwardfor
        server octoprint1 127.0.0.1:5000

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam  127.0.0.1:8080

backend webcam1
        reqrep ^([^\ :]*)\ /webcam1/(.*)     \1\ /\2
        server webcam1  127.0.0.1:8081

reboot the raspberry and enjoy having 2 points of view. Switching views is not super fast but it works!!

2 Likes

Hi @ThierryC!
I took the liberty to change the title to Guide

3 Likes

Good call.
I saw the title and was about to show him/her my way :smiley:

Nice work ThierryC :slight_smile:

1 Like

Could somebody explain to me why switching cameras is super slow on Mac OS X unless I use Microsoft Edge for Mac OS Beta?

I tried the following:

Safari 12.1, Firefox 67, Google Chrome 75 on Mac OS Mojave 10.14.4 and switching cameras takes between 40 to 50 seconds.

Edge for Mac Version 77.0.197.1: switching cameras is instantaneous.
iPhone or an iPad: switching cameras is instantaneous.
Virtual machine on same Mac computer with Windows 10 and connecting with Edge or Firefox: switching cameras is instantaneous.

I'm not sure if it's still the case or even true but I have something in my mind the either the iOS or the Mac OS (maybe even both) browser are based on the same webkit as safari and are basically just an other themed safari.

Maybe Edge changed that.

But I could be totally wrong here - as I said it was something in the back of my mind.

Well... point is that, it works flawlessly in iOS but it is sluggish in Mac OS whatever the web browser, except Edge.