Microcontrollers and IoT

Menu

Video Stream

In part 1 of this series I demonstrated how ffmpeg can be used to dump live video streams from IP cameras to a hard drive. In this post I will show how a Beaglebone Black board can be used to build a cheap and energy efficient video recorder.
Given that the recorder is not re-coding any of the camera streams the CPU requirements are quite moderate. The processor only collects the streaming data and copies them to a hard drive. Hence using a Mac or PC as a host platform is quite an over-kill. Also from an energy and cost point of view a smaller size computer is a much better fit. Embedded systems like the Rasberry Pi or Beaglebon Black should be perfectly capable of handling this task at a fraction of the cost. So in the next few section I am going to walk you through the process of setting up such a IP-DVR system.

The Beaglebone Black (BBB) comes with a single USB 2.0 host and Ethernet port. For our setup we need at least 2 x Ethernet ports. One to connect the camera (LAN Port) and one for the connection to the internet (WAN port). The easiest way to add the second Ethernet port is the buy a USB-RJ45 Ethernet adapter. However this would occupy the USB 2.0 port so we also need a USB hub to add an additional port for the hard drive.
Fortunately there are combined 3-Port USB 2.0 Hub with RJ45 Port offered at your local computer store or on-line. They give you flexibility as you will have spare USB ports to add WIFI or other USB devices in the future.

Software

The following description assumes the latest BBB Debian Linux installation. If you are still using Angstrom please install the Debian Linux. No worries, it is very easy to do and there are many description out there that walk you through the steps. I just give an outline here assuming you use a Windows machine to write the Micro SD card.
Pull the lates image from the official site: http://beagleboard.org/latest-images. Then unpack the image with 7-Zip. You can now write the img-file with a utility like Win32DiskImager or WinFlashTool to your microSD card. Once the memory card is written you insert it into the BBB. Connect a USB hub with a keyboard and mouse and hook a Monitor to it. You are now ready to power the BBB up.
After a while the Linux environment should be visible on the screen.
If you use a SD card that offers more than 4GB of space like me you also want to increase the BBB Image Disk Space. First make sure you boot from the mircoSD card, then adjust the Linux partition with fdisk.

fdisk /dev/mmcblk0p

execute the following single letter commands inside the fdisk utility:
1) Delete the second partition: d, 2
2) Create New Primary Linux Partition: n, p, 2
3) Write new partition table to disk: w
4) Exit fdisk: q
reboot and then adjust file system to use the extended partition:

resize2fs /dev/mmcblk0p2

reboot a second time so the change can take effect. You should now see the difference using the disk free utility:

df

Connect the BBB to the internet and update the package list:

sudo apt-get update

Before we start to install additional drivers we need to make sure the build tools and header files are installed:

USB-Ethernet Driver

Now that we have an up-to-date Linux system we can start to install the drivers of the additional hardware. I will start with the USB-Ethernet interface first. My 3-Port USB 2.0 Hub with Ethernet Port uses the ASIX controller. To install the drivers follow the steps outlined below. Download the driver source from the ASIX’s web site, unpack the source code and compile it. Then install the driver:

Plug in an Ethernet cable connected to your network and activate the interface:

ifup eth1

The device should now fetch an IP address and once successful you are connected to the Internet.

The USB-WiFi Driver (optional, only required if you need support for WIFI)

The next driver we are going to install is for the USB TP-LINK TL-WN725N Wifi Dongle.
Important to know: there are TWO versions of the “TL-WN725N”, one needs the RTL8188CUS driver, the other needs this RTL8188EU. See wikidevi.com/wiki/TP-LINK_TL-WN725N_v1 and wikidevi.com/wiki/TP-LINK_TL-WN725N_v2 for differences.
These instructions are for the RTL8188EU version. Before you start confirm that your TP-LINK adapter is based on a RTL8188EU Realtek controller. Plug in the adapter and checkwith the following command:

The system is now configured such that we can bring up the wireless connection:

ifup wlan2

You can take down eth1 (ifdown eth1) before bring up (ifup) wlan2.

Webmin

I was looking for a tool similar to OpenWRT’s LUCI that allows me to administrate the BBB Debian Linux from a web browser. I settled on Webmin. Please leave a comment if you have a better recommendation.
Webmin allows you to manage all to most common Linux services like retworks, firewalls, routing, sql, HTTP……. from simple web forms.
We are going to install Webmin via APT. The first step is to edit the /etc/apt/sources.list file on your system and add the lines :

Now that all the tools are in place you can just follow the instruction of part 1 to capture and dump the video to the hard drive.

Conclusion

In this blog we learned to build a simple BBB based IP video recorder. With Debian Linux as the baseline I demonstrated how to install all the additional hardware drivers, tools and software such that the resulting server is able to record IP based video streams to a hard drive for a cost of less than $100 dollars.

Credits

To all the web sites, blog and forum posts I missed to record so that I could credit them here. To debian.org, elinux.org, webmin.com, ffmpeg.org, firehol.org and all the other contributing opensource communities that jointly created all the software used in this post.