For my project, I need to get the feed (preferably simultaneousely) of 2 pi cameras (one on each pi 4).

As of now, both are communicating through ssh over wifi. It's very slow, not reliable and very complicated to get the feed of the second pi into a kivy app.

I intend to create a NFS server between the 2 through Ethernet.
First, can one of them still access Internet over wifi?
And, can I access to the second camera with opencv?

# camera connected to the first raspberry
cam_1 = cv.VideCapture(0)
# camera connected to the second raspberry
cam_2 = cv.VideoCapture(1) # can I do that?

I also saw I could replace 0 with /dev/video0. If it's possible to access the second camera, which path would it be?

1 Answer 1


Part 1: Networking

You should be able to directly connect two Pis together with an Ethernet cable for high-speed data transfers between them. In that scenario the Pis should still have internet access over Wi-Fi in addition to being able to talk directly over Ethernet.

After connecting the Ethernet, each Pi needs a static IP address for its Ethernet adapter. You should be able to configure this through dhcpcd by running sudo nano /etc/dhcpcd.conf from the terminal. The following configuration options should be added

interface eth0
static ip_address=192.168.14.X/24

where X is 1 on the first Pi and X is 2 on the second Pi. Press CTRL-X, Y, Enter to save and exit. (Note that the 14 can be changed if it conflicts with some other IP address.) After rebooting each Pi should be able to ping the other on its 192.168.14.X address.

Part 2: Cameras

There's not really a practical way to share generic /dev/ devices over a network connection. Each class of device is unique and tends to have specific ways of dealing with sharing it over a network. For a video camera you'd usually use network streaming. The most convenient way to do that would be to run an RTSP stream on one Pi and open that stream with OpenCV on the second Pi.

To stream video from the camera on a Pi, make sure VLC is installed then run:

raspivid -o - -t 0 -w 800 -h 600 -fps 12  | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8080/}' :demux=h264

from a terminal. The arguments for raspivid can be tweaked to change resolution (-w for width and -h height) and frame rate (-fps).

The video stream can be opened from Python/OpenCV using the code:

cam_2 = cv.VideoCapture("rtsp://")

Part 3: Other thoughts

If your application is particularly sensitive to Latency, video over a network may not be ideal. There may be some slightly more complicated ways of dealing improving latency if a little latency is still OK.

Alternatively, using the Raspberry Pi 4 Compute Module with a [Compute Module 4 IO Board], two cameras can be hooked up to the same Pi, completely eliminating the need for networking.

  • Thanks! I was able to share the /home folder of the second pi over NFS. I'll try to share its /dev as well. Else I'll try your streaming solution.
    – Sanico
    Apr 30, 2022 at 11:40
  • Can you say where the out.h264 part of the URL comes from please in the line cam_2 = cv.VideoCapture("rtsp://") May 4, 2022 at 15:55
  • 1
    Good spot, the /out.h264 in the URI was left over from some other code. A VLC RTSP stream is accessible just from the root of the URI. I've edited the answer to correct this.
    – Fred
    May 6, 2022 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.