-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Simplify multiple webcam handling and number of mjpg-streamer instances #750
base: devel
Are you sure you want to change the base?
Conversation
…he same output stream. This enhancement relies on the v4l-utils package providing the v4l2-ctl command to determine wether a video device offers Video capture capabilities, and so can be used as an input stream for mjpg-streamer.
Nice! have you tested it? |
Unfortunately I haven't tested it on real hardware as stated in my message, I don't own a Raspberry Pi, nor a RaspiCam. I've just tested that the script calls the correct commands with different situations I'm able to reproduce on a Linux (Fedora) machine. What prompted this PR was that I'd seen my father struggle with his own Rpi setting up multiple webcams months ago. He switched to a full blown computer with Fedora, and I installed OctoPrint on it, and fiddled with |
This would make my guide https://community.octoprint.org/t/setting-up-multiple-webcams-in-octopi-the-right-way/32669 easier, as we could skip the haproxy step, one less thing to break for sure! I will try and test/review this at some point, but I'm not a script-person so it would mostly be from a potential user's point of view. |
@cp2004 Any chance you could test it before I merge? I just dont want to ship it unless someone tests it |
I can try and give it a go over this weekend. |
Sorry, haven't been able to test this yet. Slightly forgot about it and made a new OctoPrint plugin instead. Will get on to it! |
Hmm, this doesn't entirely work on my Pi. Currently, it has no webcams plugged in, and with and without webcamd output
As you can see in the final line, it seems to pick up both
|
Thanks a lot for the test feedback.
|
Adding multiple webcams to a single mjpg-streamer process does and doesn't make sense, here's what I thought of. For:
Against:
Might also need clarification where |
|
Thanks for the command's output. As for the current logic of the script, it's expected behavior those devices get added to the list of input streams... I'm relying on this command to output something which contains more than 3 lines ( Concerning the multi-core support, a cursory look at the mjpg-streamer source code shows the use of pthreads so it would stand to reason that we're not sacrificing multi-core support, but I'd like a second look to be sure. As for the event of one camera stopping working, would it stop the entire streaming process, my guess would be no, as both streams are presented by differents URLs... but I'd rather have a real test confirming that. As for the |
I have no idea of the first part - it's out of my knowledge of how this stuff works.
That's definitely good to hear, 👍
I don't currently have the cameras wired up to test that... but I know the process ends when one camera stops streaming, if you are just streaming one camera. |
Could you be so kind as to provide the output of Looking deeper in the source code of mjpg-streamer, especially in input_uvc.c file, line 494, the It also seems that each camera stream can be stopped at will, at least from the source code point of view... So perhaps the removal of one webcam wouldn't impact the streaming process... But as said earlier, a test in real conditions is the only proof I'd find acceptable |
1st one
2nd one:
|
This is getting somewhere, I hadn't thought that the hardware encoder/decoder would be presented as a video device... Well... sorry to ask again, but what is the output of |
|
OK, this is something that I can work with to filter both of this devices... The
Looking back at the script, that's a behavior I didn't change... The I'll try to commit changes to assess what has been discussed here, but I might not be able to do it before next week. Thanks again @cp2004 for the help provided, and for taking the time to test this. |
OK, that makes sense - I should really have tested it with something that actually existed! Seems like you've got a good idea of how we can get this into shape & ready to merge. Let me know if you need any more info. |
As an improvement, a message stating that the device doesn't exist can be added to the script. I can do it in this PR, but it does seem that it would need its own PR as it is not related to the problem this PR is trying to solve... |
@cp2004, sorry to bother you again, but could you please provide the output of the following commands:
They might be easier to parse than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that a review from me was requested here, however I can't do a proper one at the moment. A quick look over the code however raised my suspicions regarding this possibly running into issues with the encoding devices present on all Pis (which btw also caused the issues I recently fixed with the endlessly looping webcamd process), which @cp2004 confirmed.
… encoding devices present on Pis
Hi everyone, I have changed the logic behind device detection. It now relies on a regex matching for the output of I also took the liberty to introduce a message telling if a device isn't found, instead of silently skipping the non-existent device, so that configuration errors may be easier to find. Please feel free to review these new changes and test them. |
Hi, Has anyone been able to review of test the change I made ? |
Hey, sorry for this hanging, didn't get to it, and no one else seems to be testing it. I will try find time but I am really swamped with other stuff. |
Hi, thanks for the test. In order to see what went wrong, I would also need the contents of the |
Hey, sorry I didn't get back to you with a log, life got in the way. I think that month in particular I was a week away. |
mjpg-streamer is able to handle multiple input and/or output streams (by specifying multiple
-i
or-o
flags). In order to reduce the overhead created by spawning multiple instances ofmjpg-streamer
, as well as simplifying the reverse proxy configuration (either HAProxy or other reverse proxy software), I've modified thewebcamd
script to be able to allow for multiple input streams.If multiple input streams are available, a setting in
octopi.txt
or any supplementary*.txt
config file is introduced, which will cap the maximum input streams to 2 so that the pi doesn't suffer too much strain. The default value is now 2, but that can be reduced or increased, I just thought it would be a sensible default.Also, this modification removes the limitation of offering either USB or Raspicam support, both should be available with this modification. The script is now able to add multiple stream input automatically, not limited to the first
/dev/video
device encountered. It also relies on thev4l2-ctl
command (available through thev4l-utils
package) to determine whether a/dev/video*
device offers Video Capture capabilities and so can be used as an input stream formjpg-streamer
.Unfortunately, I don't own an Rpi device nor a Raspicam, so I'm not able to test those functionalities on real hardware, though the script runs the appropriate commands in a similar Linux environment.
This would actually solve #677.
I welcome any feedback you might have regarding this PR.
Best regards