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.
1. Clone the repository
Clone the repository from GitHub.
git clone https://github.com/canberkdurmus/pi_stream.git
2. Go to the directory and run the script
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
3. See the stream in your browser
Your stream should be visible in your browser now. Replace the ‘ip_address’ section in http://ip_address:8000/index.html
with your Raspberry Pi’s local network IP address and go to the link.
4. Stream over a socket
To make streaming over a socket (not an HTTP server) you can use the other script included in the repository.
python3 socket_h264.py
5. See the stream in VLC player
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.
tcp/h264://ip_address:8000/
When you press ‘Open’, VLC should start showing the stream.
6. Optimize resolution
The resolutions are very low right now (320×240) in order to make streams have lower latency. You can increase resolutions by changing the scripts.
To change the browser stream script:
nano stream.py
Go to line 79 and put your desired resolution.
To change the socket stream script:
nano socket_h264.py
Go to line 6 and put your desired resolution.
7. Notes for streaming performance
- 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
fps
values in the scripts. - You can lower the
bitrate
attribute of picamera objects. - You can stream a lower resolution frame and show it on a slightly bigger area to improve the watching experience.
Leave a Reply