# Streaming Multiple USB Cameras at Once

**URL:** <https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479>\
**Category:** Companion (Retired)\
**Created:** [August 25, 2021, 1:52am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479 "2021-08-25T01:52:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelo\_miller](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@marcelo\_miller](https://discuss.bluerobotics.com/u/marcelo_miller)\
**Post date:** [August 25, 2021, 1:52am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/1 "2021-08-25T01:52:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [August 25, 2021, 2:33am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/2 "2021-08-25T02:33:33Z")

</div>

I’ve covered this before [here](https://discuss.bluerobotics.com/t/how-to-stream-another-cameras-video/9573/3), which should be enough to get a system working 🙂

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`](https://github.com/bluerobotics/companion/blob/master/.companion.rc#L18) 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.

---

<div class="post-metadata">

**Author:** ![marcelo\_miller](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@marcelo\_miller](https://discuss.bluerobotics.com/u/marcelo_miller)\
**Post date:** [August 25, 2021, 4:18am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/3 "2021-08-25T04:18:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcelo\_miller](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@marcelo\_miller](https://discuss.bluerobotics.com/u/marcelo_miller)\
**Post date:** [August 25, 2021, 7:12pm UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/4 "2021-08-25T19:12:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [August 26, 2021, 6:50am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/5 "2021-08-26T06:50:45Z")

</div>

> [@marcelo\_miller](#):
>
> 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 🙂

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [September 9, 2021, 8:22am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/6 "2021-09-09T08:22:30Z")

</div>

**EDIT:** this comment applies to Companion 0. The new [BlueOS](https://discuss.bluerobotics.com/t/companion-1-0-beta-testing/10830) uses a different camera manager, and supports multiple h264 camera streams without modification.

* * *

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:

> **[Comparing bluerobotics:master...ES-Alexander:video-N · bluerobotics/companion](https://github.com/bluerobotics/companion/compare/master...ES-Alexander:video-N)**
>
> Companion computer startup scripts and examples. Contribute to bluerobotics/companion development by creating an account on GitHub.

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

```auto
1920
1080
30
/dev/video3

```

#### gstreamer-extra.param

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

```

and change `.companion.rc` to have

```auto
	...
	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 🙂

---

<div class="post-metadata">

**Author:** ![marcelo\_miller](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@marcelo\_miller](https://discuss.bluerobotics.com/u/marcelo_miller)\
**Post date:** [September 26, 2021, 3:17am UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/7 "2021-09-26T03:17:24Z")

</div>

Hi! We have attempted to use your code, but it hasn’t worked well for us. Do you have an example of what companion.rc should look like? Thanks.

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [September 26, 2021, 12:22pm UTC](https://discuss.bluerobotics.com/t/streaming-multiple-usb-cameras-at-once/10479/8 "2021-09-26T12:22:56Z")

</div>

The `.companion.rc` file should be pretty much the same, but with the specified `video` line changed, and any extra video streams added beneath it. [The one in my video-N branch](https://github.com/ES-Alexander/companion/blob/video-N/.companion.rc#L18) has the normal video line updated, but doesn’t have any extras added (since they depend on the additional vidformat and gstreamer files that you choose the names for yourself).

I took another quick look at the comparison link in my previous comment, and it seems like I forgot a bracket at the end of line 22 in `streamer.py`, which I’ve now added in - hopefully that was the cause of your issue 🙂
