[WIP] Multiple Webcam streams in Control (Multicam)

Well, I also have a separate standalone camera

It's a foscam, but, I've not yet been able to just pluck out only the cam stream

I'll try adding the URL, and see what happens, but, I'm pretty sure I've already been down this road with this particular item

It may not be a mjpeg format. That seems to be the requirement at the moment for octoprint. I would like to add more support for other streams to my plugin in the future as well. However that is going to be way more work and might take some time to get it all setup correctly.

I can't seem to find the filetype at the moment. So I tried doing a send from the cam to the RPi, but, unfortunately, the cam is so old it only uploads via ftp. I tried changing the port to 22, but, it didn't like that either

I did find a MUX tho, but, sadly, it's a separate addon board

Lemme try a few more things...

Okay, first off, I can't see how my foscam will work, since you'd need username password just to get to it in the first place. Secondly, it looks like it's being output in cgi (I think)

But, I think I found some code to get 2 USB cams to load at the same time, and you should be able to switch between them with this...

camswap6

But, instead of loading different streams from different IP's using the interface you created, you'll be using python to switch the streams internally to the PI itself, then outputting a single mjpeg from a single PI

Wanted to share that i just pushed a new version. However there seemed to be an issue with my migration code for a small addition to the data. If you are seeing errors in the console about a missing isButtonEnabled function you will either have to add 'isButtonEnabled: true' to each profile, or removing everything under multicam and reload octoprint, which will fix the issue. Anyone who is installing for the first time should not have this issue, uninstalling and reinstall does not fix it.

I took a look at how a few other plugins are handling migration to get an idea of how to fix this, however nothing seems to work. Anyone have any idea what may be going wrong? Here is a snipplet from my _init_.py to show what i already tried.


    def on_settings_migrate(self, target, current=None):
        if current is None or current < 1:
            # Reset plug settings to defaults.
            self._settings.set(['multicam_profiles'], self.get_settings_defaults()["multicam_profiles"])

    def get_settings_defaults(self):
        return dict(multicam_profiles=[{'name':'Default','URL':octoprint.settings.settings().get(["webcam","stream"]), 'isButtonEnabled':'true'}])

@Spyder hmm, ok. im going to have to work with python more. Most my issues seem to stem from not understanding how to use it completely. Im mostly work with html, php, and javascript at my company, so some of this is a little new to me.

It may be possible to hardcode the username/password in a pull from your foscam, maybe something like http://username:password@192.168.1.29/videostream.cgi or perhaps videostream.cgi?user=username&pwd=password.

I'll give that a shot in a little bit

Just did a nuke & pave on both printers and I haven't got my plugins plugged in yet

Okay, that was a good idea. Didn't work tho

And my nuke didn't seem to help my problem either.

I used to have the temp for the hotend and bed listed on the navbar, and they vanished after I installed the multicam plugin. I nuked them both, reinstalled the navbar temp plugins (without the multicam plugin) and it's still gone on both printers

I didn't do a restore from a saved copy, I did a fresh load with tonights daily 15.1 so I guess a restore is in order... once the current prints I've got going finish

Did you define get_settings_version in your init file? Something like this.

2 Likes

I had not, that seems to have fixed the issue though. Thank you!

@Spyder Im not sure if it was my plugin that caused that, but with the data migration issues there were quite a few issues in the console so its not impossible. The new update (0.2.2) should have that all fixed now though if you want to try to update and see if it fixes your issue before completely restoring. Otherwise you may have something else that is causing the problem.

I did a fresh load and didn't install your plugin. I'm not sure I see how your plugin could have affected the fresh load

I havent installed this plug in yet and am already thankful. Thanks so much for tackling this. You are awesome!

AHA !!

I got something. Now, it's not exactly a solution to the project you were working on, but, it does do something neat

Here's the setup... I have 2 printers
Each running Octopi and Octoprint
Each has it's own camera
I installed your plugin
Then I installed a program called "motion" ON THE REMOTE MACHINE (target)
(where's the "code" button ?)
sudo apt-get install motion
then, edit the motion.conf
sudo nano /etc/motion/motion.conf
We're editing this... DAEMON = OFF (change to ON)
Save, then we wanna edit this...
sudo nano /etc/default/motion
And you wanna change this start_motion_daemon = no (change to yes)
The default port is 8081, but, that's not what we really want. All we want is the stream from the camera, so we want port 8080

Now, here's an issue I ran into. I inputted the address into the multicam plugin by clicking on the plus sign, which gave me a new place to add another camera, and I plugged in the direct address to the camera stream, then clicked the save button.

BUT, for some reason, I don't know if it's the plugin, or an issue with Octoprint itself, but, it automatically added /webcam/?action/stream to the URL I typed, and that just wasn't what I wanted. BUT, I found out that if you enter the URL, then click on the plus sign again, it opens a new option to add another cam, but, it leaves the URL I typed in the first block alone.

After that, I can click save, and go back, and delete the empty slot

Whoo Hoo !

Now I can do this...

and this...

Not sure if you can tell from the pictures, but, that's two different printers on the same instance of Octoprint

Not exactly what you wanted, but, it's a step in the right direction :slight_smile:

I'm trying to get this working by adding a second mjpg_streamer instance, (which is working fine) but for some reason haproxy's config won't add a new forward to the second camera:

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam1  127.0.0.1:8080
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

backend webcam-alt
        reqrep ^([^\ :]*)\ /webcam-alt/(.*)     \1\ /\2
        server webcam-alt  127.0.0.1:8081
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

then I'm trying to access it with http://localhost/webcam-alt/?action=stream which doesnt work, however http://ip_of_octoprint:8081/?action=stream does work. Just to be clear I have restarted haproxy service multiple times while trying to figure this out

Have you also added something in your frontend to tell haproxy to use the alternative webcam backend when encountering the webcam-alt prefix? The config snippet you shared only shows that you configured a backend, but not that you also added a rule to the frontend.

Nope, I hadn't done that yet. I've never worked with haproxy before, just apache and nginx for reverse-proxy stuff. I'll go look at the config file again. Thanks for the tip!

edit: tadaaaaa, that did it. Config for anyone else who might need it:

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/ }
        default_backend octoprint

backend webcam2
        reqrep ^([^\ :]*)\ /webcam2/(.*)     \1\ /\2
        server webcam2  127.0.0.1:8081
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

Also if anyone else is interested in using mjpg_streamer for both cameras:

#!/bin/sh
export LD_LIBRARY_PATH="$(pwd)"
./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -r 1920x1080" -o "./output_http.so -p 8080 -w ./www/" & ./mjpg_streamer -i "./input_uvc.so -d /dev/video1 -r 640x480" -o "./output_http.so -p 8081 -w ./www/"

I haven't yet figured out how to use the octopi.txt config to allow multiple instances to run, so for now I'm using a cron to kill the original mjpg_streamer instance and run this script

Edit2:

Found a more acceptable way to configure the second stream: https://printoid.net/2017/04/29/trick-12-support-two-cameras-in-printoid-premium/

Edit3:
looks like in the current iteration of Octopi, the above linked method is depreciated. Instead it's invoked from webcamd: https://github.com/guysoft/OctoPi/blob/91380e2a12b96f5bcbf9314fcaf1f0c04b830f49/src/modules/octopi/filesystem/home/root/bin/webcamd

Hi All,

Based on Alan_Weinstocks Edit1, I hacked the /root/bin/webcamd to play with the dual instance of mjpg-streamer. That way OctoPi starts up as normal but both webcams are working. Just a sloppy hack for now to see if it'd work and if it'll affect my print work stability. In my case I know my cams are without issues and that they were at /dev/video0 and /dev/video1.

Seems to work at least for playing around. Printing a few tests to see if anything happens weird.

My edits for those interested:

pi@octopi:/root/bin $ diff webcamd xxx_webcamd.orig 
60,70c60,61
< #        echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input"
< #        LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input" &
< 
< 
<         LD_LIBRARY_PATH=. 
<         echo Running ./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -r 1920x1080" -o "./output_http.so -p 8080 -w $camera_http_webroot" &
<         ./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -r 1920x1080" -o "./output_http.so -p 8080 -w $camera_http_webroot" &
< 
<         echo Running ./mjpg_streamer -i "./input_uvc.so -d /dev/video1 -r 1920x1080" -o "./output_http.so -p 8081 -w $camera_http_webroot" &
<         ./mjpg_streamer -i "./input_uvc.so -d /dev/video1 -r 1920x1080" -o "./output_http.so -p 8081 -w $camera_http_webroot" &
< 
---
>         echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input"
>         LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input" &
198d188
< 

I configure the multicam plugin to find the streams as follows:

http://[octopi.ip.address]:8080/?action=stream

and

http://[octopi.ip.address]:8081/?action=stream

I'll send a pull request to OctoPi/src/modules/octopi/filesystem/home/root/bin/webcamd with a real "fix"/Feature-add in a bit, I need some time to think about it.

Thanks Guys!

don't mind my noobness, but as I understand it.

basically for a 2nd camera to work I will need to assign it to a "video1" with the hardware number xxxx:xxxx? im guessing in the dev/video1 folder?

then assign it in mjpg streamer.?

I feel im understanding the process, but not sure.

Bonjour,
Débutant dans le domaine, je serais intéressé de pouvoir obtenir le même résultat (deux webcam, avec deux boutons comme sur votre exemple)
(ou deux écrans simultanés, côte à côte)
J'essaie d'utiliser le plugins ( multicam) et à l'action sur le bouton, l'écran de la webcam affiche
"" peut ne pas être configuré correctement ou nécessiter une authentification. Vous pouvez modifier l'URL du flux sous "Paramètres"> "Webcam & Accéléré"> "Webcam"> "URL du flux". Si vous n'avez pas de webcam, vous pouvez également désactiver la prise en charge de la webcam.""
"http://192.168.0.26/webcam/?action=stream"

Merci
de m'éclairer
2020-05-28T22:00:00Z

I recently ran the update on multicam that popped up on my browser in Octopi. It never ran correctly so figured I would try it out. After the update, and reboot Octopi browser takes FOREVER to load on a Pi 3b. WinSCP times out..