Introduction

In a previous post, I described how you could set up the Beaglebone Black to capture video and process video using OpenCV with the Logitech C920 camera. In this post I am going to look at how you can begin streaming data using the camera and code that I had adapted previously. The previous post is here and the final instructional page is here. I also just posted on how to stream video data using RTP.

This post looks at how you can stream video using UDP unicasting and multicasting. UDP unicasting is very similar to the RTP stream from before except there is no need to distribute a configuration file to the client via RTP or RTSP. The downside of unicasting is that the video transmitter needs to know the destination address of the receiver – kind of the opposite of what you might expect!

UDP Multicasting allows you to have many clients attach to the same video stream, which is really useful if you want to have the viewer instigate the connection and you wish to have many viewers.

Getting Started

Download the source code for my boneCV repository. This has the source code for everything that is discussed from here on down. Use:

To clone the repository to your local file system. All of the code is in this repository and the scripts necessary to stream the video are listed there too.

Next, I will look at a few different ways of streaming the video using avconv (ffmpeg) and the code that I had previously distributed through this repository.

UDP Stream – Unicast

The first way is by using UDP and unicasting to your player. I have found that VLC works very well for this. In my case I am streaming from the Beaglebone Black using the code from the repository and I am receiving the video on my Windows 7 PC which is running VLC media player version 2.0.7 and 2.0.6.

Step 1. Start the UDP Unicast

On the Beaglebone modify the  streamVideoUDP script to replace the IP address listed with the IP address of your Windows 7 machine. The code for this is:

Where the address after udp:// is the one that you need to adapt. You can see that this works by starting up the capture program from my previous post and piping the raw video output to avconv where it specifies the location of the viewing instance. In my case the IP address is 192.168.1.4 – just to be clear, this is the IP address of my PC on which VLC is running. In this case you do not need a distributed configuration file, like in the case of RTP (you will see later). You can see this running in Figure 1.

UDPUnicast

Figure 1. The UDP Stream being captured and unicasted from the Beaglebone.

Step 2. Open the Stream using VLC

Open VLC and go to Media -> Open Network Stream and under the “Network” tab enter the URL as: ”udp://@:1234″, as illustrated in Figure 2.

VLCudpconfig

Figure 2. The use of UDP unicast for viewing the video stream.

Press Play/hit enter and then after a few seconds the video stream should appear. The latency isn’t great – maybe 2 seconds but it is working very well as displayed in Figure 3. In particular, the frame rate is really excellent.

VLCPlayingVideo1to1

Figure 3. The Video Stream being played on the PC in Full HD. Click for a 1:1 Version of the image.

UDP Stream – Multicast

I had no experience of multicasting so I was surprised at how easy this step was once I had worked it out. I think you have to be lucky in this step with your network configuration and your router. Please see this links for information about multicast addresses:

Class D 1110 224.0.0.0 – 239.255.255.255 Multicast IP Addresses

On my network 226.0.0.1 is working perfectly! So, here is the script that I am using to multicast to my network:

Step 1. You can execute this by just typing ./streamVideoMulti as in Figure 4.

BeagleboneMulticasting

Figure 4. The Shell running on my Beaglebone – You can see the udp multicast address, the bitrate etc.

 Step 2. Start up VLC and open the Stream. You specify the address of the multicast stream like in Figure 5. In my case it is udp://@226.0.0.1:1234/ and all appears to work correctly

VLCMulticast

 Figure 5. Setting up the VLC to play my multicast stream from within Windows.

 I have opened this stream on 3 different machines on the same network and it works perfectly. There is approximately a 2 second lag, but once it begins all players are perfectly synchronized.

Conclusions

I hope to make a video on this shortly as there are other elements that I would like to discuss. One important feature of this type of streaming is that the C920 is taking care of all video coding, a computationally very expensive operation. This means that the load on the Beaglebone is very light, as displayed in Figure 6. For the UDP streams the total cost is about 12% of CPU and 4.1% of Memory for each stream. Since the stream is running at about 3Mbits/sec there is plenty of bandwidth for multiple USB streams via a USB hub and even over WiFi.

BeagleboneTop

 Figure 6. Top running on the machine. You can see that it is using 9.3% CPU 0.8% Memory for avconv and 2.6% of CPU and 3.3% of Memory for capture.