capture videos with beaglebone black

Capture Videos using BeagleBone Black

Over the last decade,  there have been immense advancements in video and image processing technologies. This has enabled us to build camera vision systems. A lot of R&D is being carried out in the industries for building driverless vehicles, robots, security systems, medical systems etc. And having camera vision capability is an integral part of these systems.

This post describes how to capture real time videos using the BeagleBone Black(BBB) and C310 Logitech Webcam. To proceed further we will have to first install some libraries.

1. Install OpenCV and V4L Libraries

Install OpenCV libraries, V4L and its dependencies using the commands shown below.

2. Setup the Hardware

Capture Videos using BeagleBone Black
Fig1. BeagleBone Black Video Capture Hardware Setup

Setup the hardware connections as shown in Fig 1. And make sure that you use a 5V, 2A adapter to power the BBB. So that, the BBB can provide sufficient current to the Webcam. To SSH into your BBB, you can either use an ethernet cable or log in using a USB cable.  To log in via USB cable, the IP address of the BBB is generally I’d suggest folks to use an ethernet cable so that they can have access to the internet which will help to proceed with this tutorial.

You can use a WiFi adapter as well to connect to the internet, as described in one of my posts here. But, unfortunately, the BBB has just one USB port which will be used by the Webcam. If you still want to go wireless with your BBB, then you will need a USB hub. Using the USB hub you can connect both the Webcam as well as the WiFi adapter.

After connecting the Webcam to the BBB, we have to check if the BBB is able to detect the Webcam. And if it’s able to identify it as a video capturing device. We can check this by running the commands shown below.

In the above, It can be seen that the BBB is successfully able to detect the Logitech, Inc. Webcam C310 :). And “/dev/video0” indicates as a video capture device has been detected.

3. V4L Commands

We can use some v4l2 commands to check the type of formats supported by the camera and the current properties of the camera.The below commands can be used for checking the formats and properties of the camera.

You can also use the “v4l2-ctl –list-formats-ext” command to get a much more detailed information about formats supported by the camera.

4. Modifications in Source Code and Issues Encountered

The source code comprises of calls to the V4L API’s to capture videos in real time. I decided to take the source code from D. Molloy’s blog. I had to slightly modify the code to match with my webcam. When I ran the program on the BBB I got stuck with an issue, caused due to the select() call timing out. I started digging into the great internet and came across several folks facing the same issue. However, I did not find any useful information to understand why the select() call was timing out.

After a couple of hours of sniffing around the internet with no luck, I decided to take a look at the source code and especially the select() system call. In the source code, I came across a “timeout” parameter that is passed as an argument to the select() API. This timeout parameter was set to 2 seconds. Then I presumed that the case may be such that, the select() is timing out and returning before the data is even ready or available for the BBB from the webcam.  So, whenever I tried to capture the video using a 2 seconds time out value, the select() timeout error used to occur as shown below.

Hence, In the source code, I simply increased this timeout value to 30 seconds(this was just a random selection) as shown below.

This resolved the select timeout issue and I was able to capture the video properly. Another issue I have encountered is that for some reason, the BBB is unable to capture YUV videos for resolutions >= 640×480. I haven’t still figured out why this is happening as it may have something to do with usage of the V4L drivers. However, I am able to capture videos of resolution 320×240 and the video quality is pretty decent for a start. I am currently also looking into the issue of not being able to capture HD videos of resolutions > 640×480 and will keep you posted.

You can get the source code and build script by cloning from my Github repository as shown below or download it from here.

The below describes the instance where the source code has been changed to capture videos of resolution 320×240.


5. Build Program and Capture Video

Run the build script to generate the binary within the source directory as shown below.

Passing an argument of -h will display all possible command options you can pass to the program as shown below.

We can start the video capture by running the below command. The video output generated by the program will be in raw format.

The raw output video is converted to mp4 format using FFmpeg as shown below with a frame rate of 30fps.

From your host machine(PC or Laptop) fetch the output.mp4 video from the BBB using sftp as shown below. You can then view the captured video on your laptop.


The below video will walk you through the entire build and video conversion process described above. The video also shows a live demo of the capture process and the quality of the captured video. You can find all the relevant details of the V4L API’s used in the source code here. I shall continue to research and figure out a way to capture high-resolution YUV videos using the C310. And will keep updating this post accordingly as an when there are incremental improvements.

In the next week, I will probably look on how to capture and process images using some image processing techniques with the BBB. And once I am done, I will share the same with you. So, see you soon in our next session at DeeplyEmbedded.


Leave a Reply

Your email address will not be published. Required fields are marked *