Video surveillance with the Raspberry Pi

Eye in the Pi

© Lead Image © svedoliver, 123RF.com

© Lead Image © svedoliver, 123RF.com

Author(s):

Set up a professional video surveillance system armed with motionEyeOS and a Raspberry Pi.

Theft, vandalism, and property damage are commonplace occurrences today. Police investigations into such cases often come up empty, and the culprits escape undetected and unpunished. As a result, sales of video surveillance systems consisting of several cameras and a video recorder are booming. Here, I show you how, armed with just a Raspberry Pi and motionEyeOS, you can catch the culprits in the act.

Thanks to inexpensive IP and USB cameras, you can find numerous software packages for the home that can be used to upcycle a computer into a full-fledged video surveillance system. However, these solutions all have a serious disadvantage: They have to run constantly and require a correspondingly large amount of energy.

Professional surveillance cameras are bulky and usually attached by a cable to a control unit; just cutting the data cable will disable the camera. Video surveillance with the Raspberry Pi and the motionEyeOS [1] free operating system, on the other hand, is simple, less conspicuous, and less expensive.

Installation

MotionEyeOS is based on BuildRoot and comes as a small source tarball or as images from the developer's website [2] for various Raspberry Pis and other small board computers. After downloading and unpacking, install the system on a microSD card. For example, on Linux, enter:

dd if=<Image> of=/dev/<Device> bs=1M

Replace the device name with the name of your microSD card, which you can discover by typing the lsblk command in a terminal window. Now you can boot the Raspberry Pi from the freshly written microSD card.

Before the first startup of motionEyeOS, connect the cameras intended for video surveillance to the Raspberry Pi through a USB port or connect them to your home network. USB cameras are easier to configure over software, but they require a data cable, making wireless cameras a far better choice for surveillance purposes.

The first deployment requires a wired connection to the router: Without such a connection, the boot process aborts after the automatic network setup fails, and the operating system restarts in an infinite loop.

Once you have fulfilled all the requirements, all the services you need will start up automatically when the system is booted, and you will see a login prompt. The first time the system boots, it also creates a new data partition automatically on the memory card and formats it. This can take a long time with large memory cards; however, you should use as much memory as possible, because the recordings from all connected cameras end up on this partition.

After starting the system, you can access the IP address of the Raspberry Pi in your web browser from any workstation on your home network. The browser then opens the login screen of the motionEyeOS front end, which is written in Python and acts as the graphical interface for the Motion daemon.

The username is admin with no password. The software then prompts you to configure the cameras in an almost empty browser window. Now enter the configuration data for the individual cameras in a small dialog.

The software uses the Video4Linux API to address cameras connected to a USB port. You can connect network cameras to the motionEyeOS system by way of Motion JPEG (MJPEG) or the Real Time Streaming Protocol (RTSP) (Figure 1). To secure the connection, you also need to specify the authentication credentials used to access a wireless or wired camera or your local network.

Figure 1: In addition to webcams connected by USB, the motionEye system supports IP cameras integrated into the network.

Problematic

When setting up cameras that reside on the local network, motionEyeOS exhibits a minor error, which you can avoid by manually editing a configuration file. With careful configuration, wired and wireless cameras request authentication data during access, rather than being openly accessible in the network.

If you have secured the camera with a self-signed certificate, motionEyeOS simply denies access. In this case, log on to the Raspberry Pi as the administrator over SSH and edit the /data/etc/ file in the motioneye.conf directory. Next, add a line reading validate_certs false at the end of the file. After a reboot, the software no longer checks for certificates; the camera in question can then talk to the system, and the web browser displays the current camera image (Figure 2).

Figure 2: The system lets you integrate several cameras into the overview. MotionEyeOS automatically records when it detects motion.

Settings

If you click on the menu icon at top left in the application window, the software opens a configuration menu on the left side where you can configure the camera settings. If you have integrated several cameras into the system, select the desired model in the drop-down at the top to assign settings for that specific camera.

In the Preferences group you first need to define how many columns of camera images you want the front end to display in the overview. Use the slide control to change the number of images arranged next to each other. This setting is useful when you want to connect multiple cameras to your Raspberry Pi and display all the images on the screen.

If you are using a low-resolution display, be careful not to activate too many columns; otherwise, the camera images will not be clear because of the extreme reduction in size. In the General Settings area, you can configure basic authentication, provided you have administrative privileges. The data for the administrator and viewers can be adjusted separately.

Other groups in the left pane contain settings for the specific camera. Be sure to activate the Movies option by switching the slide control to its left to ON (Figure 3). If you keep the default OFF setting, the software will not record any video sequences.

Figure 3: MotionEyeOS supports multiple video formats and lets you customize the recording setup to suit your needs.

During activation, you also have the option of specifying in a selection box the retention period for the recordings. By default, motionEyeOS never deletes recordings, which can lead to storage space problems in the long term. That said, motionEyeOS only records video sequences and stores them on the microSD card when the program detects motion in front of the camera. Changes to the settings only take effect after pressing the Apply button that appears at the top right in the camera pane.

The Working Schedule section lets you switch video surveillance on or off on a daily basis. As soon as you use the slide control to enable the system for a specific day of the week, two additional selection fields open where you can enter times.

At the same time, a selection field appears in the lower part of the window. You can use this to enable or disable motion detection. Motion detection ensures that video streams are not displayed on the monitor without motion in the image.

Assuming you have defined a meaningful retention period for your video recordings, the software ensures that a medium-sized microSD card is all you need as a storage medium for the videos. MotionEyeOS saves the videos in the /data/output/ directory and creates a separate subdirectory for each installed camera.

The settings dialog also has an option to change the directory for the recordings so that the system automatically stores sequences, for example, on the second partition that was created by the operating system when first launched.

Advanced

Under General Settings, you will see an Advanced Settings slide control that opens a camera-specific advanced settings dialog for highly granular configuration, such as camera resolution. This section also has basic options for the network and various services such as SSH, FTP, and Samba, which you can enable to store your video recordings on the intranet.

If you use a Raspberry Pi with a built-in WiFi module, it can be connected wirelessly at this point to the local network by enabling the WiFi module. In the other dialogs, which previously only allowed basic settings, you will now find various additional options. For example, the Movies group lets you define the quality at which recordings are saved (Figure 3); the format can be defined separately here, as well.

In the Motion Detection section, you can configure various settings for the built-in motion detection feature that compares images and fires up the recording function as soon as it detects changes. In this area, you define the extent to which the image must change to trigger recording, and you can even tell the system to respond to changes in lighting conditions.

When certain motion patterns are detected, the Motion Notifications group lets you execute defined actions, such as sending email to an address stored on the system and running a defined command. In this way, motionEyeOS notifies you when it senses unusual events, and the system can respond automatically (e.g., by shutting down devices to protect data against spying).

Playback

The videos recorded by motionEyeOS can be downloaded from the Raspberry Pi's memory card in a dialog on the system's web front end. In the default setting, the system adds the time and duration of the recording in the file name, along with current date, so that the most important data can be traced immediately.

To open the dialog, click on the desired camera in the monitoring display on the right side of the browser window. The software then displays a horizontal button bar in the camera image at the top of the window, where you can press the open movies browser button. An overlapping window then displays the available recordings sorted by day, with Download and Delete buttons to the right of the respective data (Figure 4).

Figure 4: The images created by the software can be downloaded directly to your computer from the web front end.

If you find a large number of very short recordings of just a few seconds duration in the list view, you need to adjust the Motion Detection settings in the administration menu. The correct setting can prevent motionEyeOS from starting a new recording with every miniscule movement it detects in an image.

Network Configuration

After commissioning motionEyeOS, you should enable the WiFi option. After the initial configuration, you no longer need the wired connection. The wireless connection lets you position the management computer freely and it no longer has to be located right next to the router. This setup allows the computer to be removed from view of unauthorized persons, which significantly improves data security.

You can activate WiFi in the Network section by switching the Wireless Network slide control to ON and entering the SSID of the desired network and the matching authentication key in the fields that appear. Next, press the Reboot button in the General Settings section to restart the system and integrate the Rasp Pi into your infrastructure wirelessly.

The connected WiFi cameras and the Raspberry Pi should also have assigned static IP addresses, so you will have a working system immediately after any power failures and avoid device connection failures from incorrect IP addresses.

All you have to do is change the IP Configuration selection boxes in the Network group from the default DHCP address assignments to Manual (static IP). Then, switch from DHCP to the static IP address configuration in the configuration dialogs of the connected terminal devices. Alternatively, you can assign static IP addresses to all nodes in the router's web front end, removing the need for any configuration on the systems themselves.

Up To Date

If you are looking to add new cameras to a system that you operate on a Video4Linux basis, you will want to update the software up front. Because motionEyeOS is under constant development, the developers not only add new driver modules, but also frequently extend the system, adding new functions and fixing bugs.

To let you update the system, the General Settings group contains the Check button for the Software Update option, which motionEyeOS uses to search for updates and automatically install, if necessary (Figure 5).

Figure 5: An integrated update routine keeps the software up to date.

Backup

Configuring motionEyeOS can be quite complex, especially if you are using several cameras with different interfaces. To avoid losing the setup you have established in the event of an accident or theft of the control computer, the General Settings | Configuration | Backup button lets you save all the settings.

The software prompts you for the target path; by default, this is the computer on which you access the motionEyeOS computer. The software stores the configuration files there as a tar.gz archive (Figure 6). The Restore button on the motionEyeOS computer's dashboard lets you restore the configuration files later on if need be.

Figure 6: All the critical data in a single archive: the motionEyeOS config content.

Conclusions

MotionEyeOS gives you a complete, well-thought-out, and logical video surveillance solution for your Raspberry Pi. The package also impresses with its excellent stability, great flexibility for setups that use different types of surveillance cameras, and feature set that satisfies even professional requirements. The software's intuitive operating philosophy rounds off the package. For safety-conscious users, motionEyeOS provides an excellent and efficient way to monitor exposed locations.

The Author

Erik Bärwaldt is a self-employed IT-admin and technical author living in Scarborough (United Kingdom). He writes for several IT-magazines.