Real-Time Video Streaming with Raspberry Pi
Jun 20, 2023
Stream Real-Time Video Over Local Network with Raspberry Pi.
Jul 1, 2023 06:16 PM
Streaming live video with Raspberry Pi over the local network can come in handy in different cases. You can use your Raspberry Pi as a security camera, and IP video source for your computational heavy processes that run on a local server, or maybe on a remote-controlled robot.
This post aims to make you able to set up a live-streaming Raspberry Pi just in minutes.
Clone the repository from GitHub.
git clone https://github.com/canberkdurmus/pi_stream.git
The requirements are included in the Raspberry Pi OS and Python, so if you made the installation right everything should be working out of the box. If you have any problems with installation you can check Headless Raspberry Pi Installation for Beginners post.
cd pi_stream python3 stream.py
Your stream should be visible in your browser now. Replace the ‘ip_address’ section in
http://ip_address:8000/index.htmlwith your Raspberry Pi’s local network IP address and go to the link.
To make streaming over a socket (not an HTTP server) you can use the other script included in the repository.
To see the socket stream over the VLC, open the VLC and press ‘Open Media’, go to the ‘Network’ tab. Enter the address below but of course, replace the IP with your Raspberry Pi’s local network IP.
When you press ‘Open’, VLC should start showing the stream.
The resolutions are very low right now (320x240) in order to make streams have lower latency. You can increase resolutions by changing the scripts.
To change the browser stream script:
Go to line 79 and put your desired resolution.
To change the socket stream script:
Go to line 6 and put your desired resolution.
- You can provide a better network connection for your Raspberry Pi (maybe with an ethernet cable or a better wireless router).
- If latency is important for your use case, you can use lower resolutions. If details are more important, you can use higher resolutions.
- You can lower the
fpsvalues in the scripts.
- You can lower the
bitrateattribute of picamera objects.
- You can stream a lower resolution frame and show it on a slightly bigger area to improve the watching experience.