Shares
Basic Video Surveillance with the Raspberry Pi

Basic Video Surveillance with the Raspberry Pi

Last Update: / by Marco Schwartz

Sometimes, you would like to monitor your home from another angle that what the Raspberry Pi camera can achieve. In order to do that, you will need to use an external USB camera.

In this project we are going to see how to connect an external USB camera to your Raspberry Pi, and make a simple video surveillance system from it, allowing you to see in live what is seen by the camera.

To do that, we will first connect a USB camera to your Pi, and then test if it works correctly. After that, we will configure the Raspberry Pi so it streams the video continuously on a web page.

Hardware & Software Requirements

Apart from the Raspberry Pi itself, the most important component of this chapter will be the USB camera. You need a camera that is compatible with the UVC standard, which is the case for most of the cameras you will find today. I used a Logitech C720 HD camera for this project.

This is the list of the components you will need for this project:

Hardware Configuration

The hardware configuration is really simple: you just need to plug the camera in your Pi, using one of the USB port on the Raspberry Pi.

This is a close-up of the final result:

Basic Video Surveillance with the Raspberry Pi

Testing the Camera

We are now going to test the camera. Again this is really easy to do. Just type this in a terminal:

sudo apt-get install fswebcam

Then, take a picture with:

fswebcam -r 1280×720 image.jpg

The camera LED should turn on, which means it is active and currently taking a picture. Then, simply check the image that was created by the command.

Local Video Streaming

We will now stream video locally using the mjpg-streamer module. This module is really great for video streaming, as it will create a nice web page from which you can access the video stream.

However, the module is not available in the official Raspberry Pi Linux repository. But luckily for us, a developer made a version available for the Raspberry Pi, and we are going to install it now. You can find all the details at:

https://github.com/jacksonliam/mjpg-streamer

First type the following command in a terminal from your Pi:

git clone https://github.com/jacksonliam/mjpg-streamer

Then type this command to install required modules:

sudo apt-get install cmake libjpeg62-dev

After that, type this command to build the mjpg-streamer package:

sudo make clean all

And then type this command:

export LD_LIBRARY_PATH=.

And finally type this command to start the streaming:

./mjpg_streamer -i “./input_uvc.so” -o “./output_http.so -w ./www”

You will see that a lot of text will be printed inside the terminal, which means the streaming is active. Then, go to this URL from a computer:

http://rpi_ip_address:8080

This is the web page you should get:

Basic Video Surveillance with the Raspberry Pi

Simply go on ‘Stream’ in the menu, and you should see live streaming from the USB camera connected to your Pi!

If you just want to see the stream, go to:

http://rpi_ip_address:8080/javascript_simple.html

Basic Video Surveillance with the Raspberry Pi

How to Go Further

In this project, we built a basic surveillance camera using the Raspberry Pi camera module and some open-source software.

You can now of course add more Raspberry Pi modules in the game, to make a whole surveillance system! From the mjpg-streamer module it is easy to get a piece of code that can be embedded in another web page.

From that, it is easy to build a page where you have the pictures from all your camera modules, and monitor them from a single interface!

Want to learn more? Get my free eBook about the Raspberry Pi!
The Raspberry Pi is a powerful board that can be used for all sorts of projects. Download today my free eBook "Build a Simple Thermostat with the Raspberry Pi". Simply click on the button below!

Leave a Comment

Please enter your name.
Please enter your email.
Please enter your comment.
Craig Mullins 3 years ago
2 way audio would be awesome! What about controlling PTZ cameras? And having motion based recording and ad infrared/heat sensing recording to stop false alarms! How much you charge to help on a project like that?
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Shakeel Engy 3 years ago
Hi Marco! I have been working on the same concept of yours, Video Surveillance with the Raspberry Pi which can be streamed from anywhere i.e., local as well as remotely from anywhere... what I want to add is a 2 way audio feature . . how can I do it? If you could help me out in anyway will be a greatly appreciated.
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Marco Schwartz Shakeel Engy 3 years ago
Hi! Please reach out via email for personalised help on your projects :)
Himanshu Verma 3 years ago
i have connected raspberry pi on SSH connection and had gone through all steps clearly but finally got stuck at bash file command./mjpg_streamer -i “./input_uvc.so” -o “./output_http.so -w ./www”It is showing an error as no such file or directory
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Marco Schwartz Himanshu Verma 3 years ago
Can you reach to me directly via email for this issue?
Jove Meraveles 4 years ago
we did not get a video output :/ what could be the cause of this?
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
wrath sas 4 years ago
so, i got this error: ./mjpg_streamer: unrecognized option '-w'can u help me, pls
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Rikofranko 4 years ago
Have you tried implemeting this with the PiCamera module on a Pi2?
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Marco Schwartz Rikofranko 4 years ago
Sure, this would work as well :)