Multiple usb webcams Ubuntu

C920 & C270

I’ve followed a YouTube guide:

https://docs.google.com/document/u/0/d/1AqtBhPTZOei1bds82Q2bN_Hy5QSHhvsh3vqAmPzSiJo/mobilebasic

To install virtual machine Ubuntu Desktop on a TrueNas server, I’ve got a usb card pass through to the virtual Ubuntu desktop which works perfectly. The webcams are being picked up by Ubuntu and I can run the script to run the webcams, but only one can be enabled. I would prefer to have two or more webcams running, but can’t work out how to have multiple cameras.

If I run the temp command for running two cameras, it works perfectly, but I just can’t work out how to have 2 enabled with the script.

What did you already try to solve it?
Adding the temp line within the script or adding in /dev/video0 & /dev/video2 but doesn’t work

Logs:
Unfortunately I don’t have any logs due to other apps that contain sensitive info.

Additional information about your setup
TrueNas running Ubuntu on a virtual machine, octoprint installed.

Hello @Victor76 !

Now I'm curious: What OctoPrint plugins contain sensitive info?
You are aware that OctoPrint runs in a virtual environment and only OctoPrint specific data is logged?

It’s not within OctoPrint, the logs I have are mixed logs, so the octoprint logs are mixed in between my syslogs which contains logs from other apps like my cctv etc.

Setting up multiple webcams really depends on how you setup one. If you aren't on OctoPi, then you would probably just have to do exactly what you did for the first webcam with the second. How have you set it up?

OctoPrint logs to it's own file, octoprint.log. You can download this from the logging panel in settings. It's not required for this question, since we are dealing with webcams and OctoPrint doesn't deal with webcams. Just for future, if you have more problems.

I’ve tried doing the same process for a 2nd webcam.

The guide has you installing the mjpg-streamer and then making two scripts within the /home/user/ folder, namely webcam & webcamDaemon.

When I’ve tried making a 2 version of webcam & webcamDaemon then editing these files to point to the 2nd webcam. Once this was done I tried running the 2nd one and it just refuses to work, but as soon as I stop the first webcam the 2nd one works.

In the 2nd webcam config I’ve pointed to the 2nd webcam and to different ports etc.

I did read on one site that the 2nd one would need to be changed to camera1_usb_options for the 2nd to work, but I’ve tried that.

Cheers for any help.

You would also need to change the port (mjpg-streamer/mjpg-streamer-experimental/plugins/output_http at master · jacksonliam/mjpg-streamer · GitHub), otherwise both are trying to bind to 8080 which won't work. edit: just saw your comment that you did try a different port. There may be some other similar conflict going on by the sounds of it though.

Sometimes linux got issues with more than one USB cam. I didn't test it with mjpg streamer, but with OBS. I guess you got the same problem.

Try it on different USB busses - one on USB 2 and one on USB 3 for example - so there is only one cam per bus.
That didn't work on my board tho. It somehow mixed USB 2 devices on USB 3 ports with devices on USB 2 ports.
The solution was to use an USB 3 hub.
-> one cam on USB 2 and one cam on a USB 3 hub and the USB 3 hub in a USB 3 port.

for the cam's you can follow the udev section in this pdf
octoprinten.pdf.zip (330,1 KB)

My thing may not apply for mjpg streamer. I would try @danielkrah s solution first

maybe the cams get mixed up so set a udev rule for each is always a good thing

Cheers for all the help, I’ll give them a try tomorrow.

Just to update, I’ve got the webcams all working perfectly now. I stumbled across this old guide on YouTube.

Cheers for all the advice and help.

I followed Chris’s guide too but there is one thing you might want to add. Copy the mjpg-streamer-experimental folder to numbers 2, 3, 4, etc. in each of those folders copy the mjpg_streamer file to the number of the folder (mjpg_streamer2 for example). Check permissions. Then in each webcam and webcamDaemon file change each pointer to the folders and executable to the correct one. In webcam file make sure to change the pkill line as well.

This will start a new mjpg_streamer pid for each camera and the beauty is if you kill one camera it doesn’t affect the other ones. The way Chris does it if you have to restart one camera it kills mjpg_streamer which kills them all.

1 Like