Home        Store        Learn        Blog

Streaming Multiple USB Cameras at Once

Hi! I was wondering how we could stream multiple USB cameras (probably 3) at once using the Companion and Gstreamer.

I’ve covered this before here, which should be enough to get a system working :slight_smile:

I just had another look at our companion repo and realised it may be possible to set the cameras up independently by creating multiple param files that specify the different ports, and just starting separate screen sessions for them in .companion.rc instead of modifying the streamer.py and start_video.sh scripts. I believe that shouldn’t be overly difficult to get working, but I’ll try to have a play some time this week if I can.

Thank you so much! I’ll try to follow the instructions and will tell you the results!

Hi I was looking into the screen bash and I was wondering if it was possible to have 3 separate screen sessions instead of just 2 so we can stream 3 cameras. If it is, how would we go about doing that?s

That’s definitely possible, but the code example from the comment I linked you to is currently set up for just one extra camera. To add another one requires specifying another device, making the relevant parameters file for it, and specifying that as relevant within the code. I believe that should be easier to do in my proposed new approach than in the provided example code, but neither should be super challenging. I don’t have time at the moment to test the new approach idea, so it will have to wait until at least tomorrow, but possibly early next week.

If working off existing code is easier for you then I’d suggest you look through the example and try to understand what the additional lines are doing, so you can figure out the places where another line needs to be added to handle the additional camera :slight_smile:

This took longer to get back to than I’d hoped, and you might already have a working solution for your use case, but in case it’s relevant I spent some time on it today, so now have an approach that makes it easy to add extra videos. The relevant code changes are here:

After that, adding extra video streams basically just requires creating the two extra parameter files for each one, and adding a line for it in .companion.rc. As an example, for a second BR camera the H264 access is likely at /dev/video3, and if we want we can stream it to port 5610 (the default stream goes to 5600), so to add that you’d make

vidformat-extra.param

1920
1080
30
/dev/video3

gstreamer-extra.param

! h264parse
! queue
! rtph264pay config-interval=10 pt=96
! udpsink host=192.168.2.1 port=5610

and change .companion.rc to have

	...
	sudo -H -u pi screen -dm -S video $COMPANION_DIR/tools/streamer.py vidformat.param gstreamer2.param
	sudo -H -u pi screen -dm -S video2 $COMPANION_DIR/tools/streamer.py vidformat-extra.param gstreamer-extra.param
	...

And then the receiving end can be handled as in the post I linked you to in my first comment. More streams can be added in the same way, making sure to select the correct device in the vidformat parameters and set a unique port in the gstreamer ones.


@UnderseaROV If you’re still working with this stuff, this approach might be worth considering :slight_smile:

2 Likes