Random Nerd Tutorials

Video Streaming with Raspberry Pi Camera


In this post we’re going to show you how you can do video streaming with a Raspberry Pi and a Raspberry Pi Camera – how to stream live video into a web page that you can access in any device that has a browser and is connected to the same network the Pi is. This is useful to apply to a home surveillance camera, for example.


Enable the Rasperry Pi Camera Module

If you’re using the Raspberry Pi Camera Module, you need to enable the camera software in your Raspberry Pi in order to use it. In the Desktop environment, go to the Raspberry Pi Configuration window under the Preferences menu, open the Interfaces tab and enable the Camera as shown in figure below.

Or, in the Terminal window, type the following command:

pi@raspberry:~ $ sudo raspi-config

You should see the Raspberry Pi software configuration tool. Select the Interfacing Options:

Enable the camera and reboot your Pi:

Find the Raspberry Pi IP address

To access your video streaming web server, you need to know your Raspberry Pi IP address. For that, use the following command:

pi@raspberry:~ $ ifconfig

You’ll be given a bunch of information, including your Raspberry Pi IP address. In my case, the RPi IP address is

Connect the camera

Connecting the Raspberry Pi Camera Module is easy. With the Pi shutdown, connect the camera to the Pi CSI port as shown in the following figure. Make sure the camera is connected in the right orientation with the ribbon blue letters facing up as shown in the next figure.

Writing the script

The script for video streaming is shown below. You can find this script at the official PiCamera package documentation.

Create a new file called rpi_camera_surveillance_system.py:

pi@raspberrypi:~ $ nano rpi_camera_surveillance_system.py

Copy the following code to your newly created file:

To save your file press Ctrl+X, type Y and Enter.

Accessing the video streaming

After writing the scrip, you can run it using Python 3. Run the next command:

pi@raspberrypi:~ $ python3 rpi_camera_surveillance_system.py

Once the script is running, you can access your video streaming web server at: http://<Your_Pi_IP_Address>:8000. Replace with your own Raspberry Pi IP address, in my case

You can access the video streaming through any device that has a browser and is connected to the same network that your Pi.

You can use your Pi to monitor your home as a surveillance camera:

Wrapping up

I hope this project was useful! You could easily upgrade this home surveillance device to record video or notify you when motion is detected.


Like home automation? Learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino with my course: Build a Home Automation System for $100.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Leave a Comment: