Create your own live stream from a Raspberry Pi using the Pi camera module. Build your own applications from here.
The Pi streams the output of the camera module over the web via Flask. Devices connected to the same network would be able to access the camera stream via
<raspberry_pi_ip:5000>
![]() |
![]() |
|---|---|
| Pi Setup | Pi - Live Stream |
- Raspberry Pi 4, 2GB is recommended for optimal performance. However you can use a Pi 3 or older, you may see a increase in latency.
- Raspberry Pi 4 Camera Module or Pi HQ Camera Module (Newer version)
- Python 3 recommended.
Make your Raspberry Pi is up to date and has the required libraries installed.
sudo apt-get update
sudo apt-get upgradeInstall the following dependencies to create camera stream.
sudo apt-get install libatlas-base-dev libjasper-dev libqtgui4 libqt4-test libhdf5-dev python3-picamera2Then install openCV
sudo apt install build-essential cmake git libgtk-3-dev libavcodec-dev libavformat-dev libswscale-devNote: This installation of opencv may take a while depending on your pi model.
OpenCV alternate installation (in the event of failed opencv builds):
sudo apt-get install libopencv-dev python3-opencvOpen up terminal and clone the Camera Stream repo:
cd /home/pi
git clone https://github.com/EbenKouao/pi-camera-stream-flask.gitI like to use a virtual environment for my projects, so I can keep the dependencies separate. You can skip this step if you do not want to use a virtual environment.
cd /home/pi/pi-camera-stream-flask
python3 -m venv --system-site-packages venv--system-site-packages allows the virtual environment to access the system's site-packages directory, such as OpenCV
and picamera2.
source venv/bin/activatecd /home/pi/pi-camera-stream-flask
pip install -r requirements.txtor if you are not using the virtual environment:
sudo python3 -m pip install -r requirements.txtNote: Creating an Autostart of the main.py script is recommended to keep the stream running on bootup.
sudo python3 /home/pi/pi-camera-stream-flask/main.pyOptional: A good idea is to make the camera stream auto start at bootup of your pi. You can add a systemd service to do this.
If you do not use a virtual environment or installed the project outside of /home/pi, you will have to modify launch_service.sh.
chmod +x /home/pi/pi-camera-stream-flask/launch_service.shsudo nano /etc/systemd/system/pi-camera-stream.servicepaste the following content into the file:
[Unit]
Description=My Python Startup Script
After=network.target
[Service]
User=pi
WorkingDirectory=/home/pi/pi-camera-stream-flask
ExecStart=/home/pi/pi-camera-stream-flask/launch_service.sh
Restart=always
[Install]
WantedBy=multi-user.targetsave and exit the file (Ctrl + X, then Y, then Enter).
sudo systemctl daemon-reload
sudo systemctl enable pi-camera-stream.service
sudo systemctl start pi-camera-stream.serviceYou can check the status of the service with:
sudo systemctl status pi-camera-stream.serviceIf everything is working, you should see a green "active (running)" message. Using services allows you to manage the camera stream easily, start on startup (if network is available) and restart the service if it fails.
View the latest Build: Pi Smart Cam with Motion Sensor
Alternatively, view more projects that build on the Pi Camera on smartbuilds.io.

