Raspberry Pi Camera Web Server: How to Stream Live Video
Updated: 18 hours ago
To build a Raspberry Pi camera web server, connect a camera module, confirm the Pi detects it, then run a short Python script that uses the Picamera2 library to serve an MJPEG stream over HTTP. Open http://<pi-address>:8000 in any browser on your network and you see live video. The whole setup takes about 15 minutes and needs no extra software beyond what ships with Raspberry Pi OS.
The trouble is that most tutorials for a Raspberry Pi camera server are out of date. They rely on raspistill, the old Raspbian camera stack, or web interface projects that no longer match the libcamera software on current Raspberry Pi OS. You follow the steps, hit "no cameras available," and end up debugging commands that were retired years ago.
This guide uses the current stack: rpicam-apps for testing and Picamera2 for streaming. You will check what hardware you need, wire up and test the camera, write and run the server, make it start on boot, and then tune, secure and troubleshoot it. Every command is copy-paste ready.
What you need before you build the Raspberry Pi Camera Web server
You need a Raspberry Pi 3 or newer, a CSI camera, a 64-bit Raspberry Pi OS (Bookworm or later) and a network connection. The Pi runs the web server itself, so no other machine is involved.
Hardware and software checklist
Gather these before you start:
Board: Pi 3, 4, 5 or Zero 2 W. A Zero 2 W handles 720p comfortably, but start small on it.
Camera: an official Raspberry Pi Camera Module, or any MIPI CSI-2 camera with libcamera driver support. For a global shutter autofocus option, the Vadzo Bolt-234CGH (1080p, from $190) is a MIPI camera that integrates with Raspberry Pi.
Cable: the Pi 5 and Pi Zero use a smaller 22-pin camera connector, so you need the matching adapter cable.
OS: Raspberry Pi OS Bookworm or newer, with SSH enabled and the Pi on your network.
USB webcam? You can connect one, but Picamera2 targets CSI cameras. A USB webcam needs a different capture tool, so this guide does not cover it.
Why MJPEG over HTTP
This setup streams MJPEG, a sequence of JPEG frames sent over a normal HTTP connection. Every browser plays it through a plain <img> tag, with no plugin, player or JavaScript. It also keeps latency low because there is no video buffering stage.
The tradeoff is bandwidth, since MJPEG compresses less than H.264. On a home or office network that rarely matters. Python's built-in http.server is enough to run the server, so you install nothing else.
MJPEG over HTTP is the simplest way to get live Pi video into a browser, and it works on every device.
Step 1. Connect and test the camera
Power the Pi off, seat the ribbon cable, boot, and run rpicam-hello --list-cameras. If the camera appears in the list, the hardware is fine and you can move on.
Connect the ribbon cable
Shut the Pi down and unplug the power. Lift the connector latch, slide the cable in fully and press the latch down. The contacts must face the connector pins, and Raspberry Pi's documentation shows the correct orientation for each board. A Pi 5 has two camera ports, and either works.
Confirm the Pi sees the camera
Boot the Pi, connect over SSH and update the system. Bookworm detects cameras automatically, so you do not need to enable anything in raspi-config.
sudo apt update && sudo apt full-upgrade -y sudo reboot
After the reboot, list the cameras and capture a test image. The -n flag skips the preview window, which you need when running over SSH.
rpicam-hello --list-cameras rpicam-still -n -o test.jpg
Older guides use libcamera-hello and libcamera-still. Those are the pre-Bookworm names for the same tools. If the list is empty, fix the cable before you write any code.
If rpicam-still cannot take a photo, the web server cannot stream video either.
Step 2. Write the streaming script
Install Picamera2 if it is missing, then save one Python file that starts the camera and serves the stream. Picamera2 is the supported Python interface to the libcamera stack, and its own examples include an MJPEG server on which this script is based.
Install Picamera2
The full Raspberry Pi OS image includes Picamera2. On the Lite image, install it with apt:
sudo apt install -y python3-picamera2 --no-install-recommends
Create stream.py
Create the file with nano stream.py and paste in the script below. It runs a threaded HTTP server so several browsers can watch at once, and it encodes each frame as a JPEG that it pushes to every connected viewer.
import io import logging import socketserver from http import server from threading import Condition from picamera2 import Picamera2 from picamera2.encoders import JpegEncoder from picamera2.outputs import FileOutput PAGE = """\ <html> <head><title>Pi camera</title></head> <body> <h1>Pi camera live stream</h1> <img src="stream.mjpg" width="640" height="480" /> </body> </html> """ class StreamingOutput(io.BufferedIOBase): def __init__(self): self.frame = None self.condition = Condition() def write(self, buf): with self.condition: self.frame = buf self.condition.notify_all() class StreamingHandler(server.BaseHTTPRequestHandler): def do_GET(self): if self.path in ('/', '/index.html'): content = PAGE.encode('utf-8') self.send_response(200) self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(content)) self.end_headers() self.wfile.write(content) elif self.path == '/stream.mjpg': self.send_response(200) self.send_header('Cache-Control', 'no-cache, private') self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME') self.end_headers() try: while True: with output.condition: output.condition.wait() frame = output.frame self.wfile.write(b'--FRAME\r\n') self.send_header('Content-Type', 'image/jpeg') self.send_header('Content-Length', len(frame)) self.end_headers() self.wfile.write(frame) self.wfile.write(b'\r\n') except Exception as e: logging.warning('Client %s disconnected: %s', self.client_address, e) else: self.send_error(404) self.end_headers() class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer): allow_reuse_address = True daemon_threads = True picam2 = Picamera2() picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)})) output = StreamingOutput() picam2.start_recording(JpegEncoder(), FileOutput(output)) try: StreamingServer(('', 8000), StreamingHandler).serve_forever() finally: picam2.stop_recording()
One Python file, one camera object and one HTTP handler are all a Raspberry Pi camera server needs.
Step 3. Run the server and open the stream
Run python3 stream.py, find the Pi's IP address with hostname -I, and browse to port 8000 on that address. To keep the stream alive after reboots, wrap the script in a systemd service.
Start the server
Run the script from the folder where you saved it:
python3 stream.py hostname -I
On another device on the same network, open http://192.168.1.50:8000, replacing the address with the one hostname -I printed. The name http://raspberrypi.local:8000 also works if your Pi uses the default hostname. Press Ctrl+C in the SSH session to stop the server.
Start it on every boot
A script tied to an SSH session dies when you disconnect. Create a service file instead:
sudo nano /etc/systemd/system/picam.service
[Unit] Description=Pi camera web server After=network-online.target Wants=network-online.target [Service] User=pi WorkingDirectory=/home/pi ExecStart=/usr/bin/python3 /home/pi/stream.py Restart=always [Install] WantedBy=multi-user.target
Change pi to your own username in both places. Then enable and start the service and check its status:
sudo systemctl daemon-reload sudo systemctl enable --now picam.service systemctl status picam.service
With Restart=always, your camera server recovers from crashes and comes back after every power cut.
Step 4. Tune, secure and troubleshoot the stream
Raise the resolution gradually, never expose port 8000 to the internet, and use the problem table below when something fails. These three habits keep a Pi camera server stable.
Adjust resolution, frame rate and orientation
Change the size value in create_video_configuration to try (1280, 720) or (1920, 1080). Raise it one step at a time and watch for stutter, because the Pi's CPU encodes every JPEG. To cap the frame rate at 15 fps, add this line before start_recording:
picam2.set_controls({"FrameDurationLimits": (66666, 66666)})
For a camera mounted upside down, import Transform with from libcamera import Transform. Then pass transform=Transform(hflip=True, vflip=True) to create_video_configuration.
Keep the stream private
The script has no password and no encryption. Anyone who reaches port 8000 sees your video. Keep the server on your local network and do not forward the port on your router. For remote viewing, connect through a VPN, or put a reverse proxy with authentication in front of it.
This setup is a live viewer, not a recorder. If you want a Raspberry Pi security camera with motion alerts and saved clips, add recording software on top of it.
Fix common problems
Symptom | Likely cause | Fix |
|---|---|---|
"no cameras available" | Loose or reversed ribbon cable, wrong adapter | Reseat the cable, check the Pi 5 or Zero cable type |
Black image or camera busy error | Another app holds the camera | Stop rpicam-hello or any older script |
"Address already in use" | Earlier copy still running | Run sudo systemctl stop picam.service or kill the old process |
Choppy video | Resolution too high or weak Wi-Fi | Lower the size or frame rate, or use Ethernet |
Page won't load on another device | Different network or wrong IP | Re-run hostname -I, check both devices share a network |
Most failures trace back to the cable or to a second program holding the camera.
Your Pi is now a camera server
You now have a Raspberry Pi camera server that streams MJPEG to any browser, restarts itself after a reboot and stays private on your network. The path is simple: confirm the camera with rpicam-hello, run the Picamera2 script, wrap it in systemd, then tune resolution and frame rate to what your Pi can handle.
If your project outgrows the stock module and needs autofocus, a global shutter or a 4K sensor, Vadzo builds MIPI cameras for Raspberry Pi 4 and Pi 5. Browse the options at Vadzo Imaging's camera range or ask the application engineering team to help you pick one.



