Using the Raspberry Pi camera module, you can stream video both on your local network and across the internet. This means the video can be accessed anywhere in the world. Your Raspberry Pi will be transformed into a customisable video surveillance camera that you can place anywhere you want.
The steps to do this involve connecting the Raspberry Pi camera module to your Pi, streaming video from the camera to a web page and then making this video stream accessible from anywhere.
To start this project, you will need:
- Raspberry Pi
- Raspberry Pi camera module
- Wifi card or network adapter to connect the Raspberry Pi to the internet
Installing and configuring the Raspberry Pi camera module
The Raspberry Pi camera module has an 8 megapixel sensor and can be used to take high-definition video, as well as stills photographs. Installation of the module is relatively straightforward. You’ll need to connect the camera module to the CSI port, located behind the Ethernet port, and then enable the camera software.
Here's a video of how to install the camera:
To enable the camera, run:
in a terminal.
When your camera is selected, it is time to test the camera. To do this, type the following in a terminal:
raspistill -o cam.jpg
The camera LED should turn red, which means it is active and currently taking a picture. Then, simply check the image that was created by the command.
Local video streaming using the Raspberry Pi
The next step is to stream video locally using the mjpg-streamer application. This application is really great for video streaming, as it creates a website for you to navigate to and watch the video stream. Unfortunately, the application is not available for the Raspberry Pi camera in the official repository but a version for the Raspberry Pi camera has been created by a friendly developer. More details are available here:
To install the required software, type the following command into your Raspberry Pi's terminal:
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:
And finally type this command to start the streaming:
./mjpg_streamer -o "output_http.so -w ./www"-i "input_raspicam.so"
You will see that a lot of text will be printed inside the terminal, which means the streaming is active. Then, in a web browser on another computer, type in your Raspberry Pi's IP address (e.g. 192.168.1.4) plus a colon and 8080 (e.g. 192.168.1.4:8080). If you're not sure of your Raspberry Pi's IP address, type in
ifconfig at the terminal of your Raspberry Pi.
This is the web page you should get:
As you can see when you click "Stream" in the menu, your Raspberry Pi camera is now streaming video across your local network. To stream your video across the cloud, follow the next steps.
Video streaming across the Internet from the Raspberry Pi
To make this webpage accessible from anywhere in the world, you'll need to install some more software, namely ngrok. Ngrok is a simple utility that takes a local web server (here, the video streaming server) and makes it available on the web.
Download and unzip ngrok from the ngrok website. Make sure that streaming is still active and then type in the following at the Raspberry Pi terminal:
This tells ngrok to take the server running on port 8080 (our mjpg-streamer app) and make it available on the internet. ngrok will provide you with a few lines of information, one of which is the “Forwarding” URL.
Enter that "Forwarding" url into a web browser and you will see the stream just as before. Now test it from a computer not in your local area network (e.g. on your phone or from a friend's house) and you are good to go!
Here we have built a surveillance camera using the Raspberry Pi camera module and some open-source software. If you found this tutorial useful, then check out some of my other Raspberry Pi tutorials below.