This is an update to my previous blog post where I wrote about how to stream a high and low resolution hardware encoded H.264 video feed from a Raspberry Pi and Camera Module over RTSP.
With the release of Raspberry Pi OS based on Debian Bullseye in November 2021, there were some significant changes to the camera driver that deprecated1 the Picamera V1 Python library that I had been using in my previous code. At the time of publishing this post, Picamera2, which is the new library that is compatible with the Bullseye based OS is still a Beta release. With the release of version 0.3.10, the library finally has support for running “multiple encoders, either on the same or different streams”2. This seemed like an appropriate time upgrade the OS on the Pi and redo the script to work with the new Python library.
Below are my setup notes for a new script using the Picamera2 library, FFmpeg (instead of gstreamer) and MediaMTX (formerly rtsp-simple-server).
1.) Start with a clean install of Raspberry Pi OS Lite - Debian version: 11 (bullseye)
2.) Install FFmpeg
|
|
The python3-picamera2
library should already be pre-installed.
3.) Create and edit /root/picam_stream.py
Review the Picamera2 Library manual and Github project page for additional documentation.
4.) Download and install MediaMTX (formerly rtsp-simple-server). Have a look at the Systemd setup instructions in the project README.
5.) Edit the /usr/local/etc/mediamtx.yml
configuration. My example below is based on MediaMTX v1.8.3
You’ll want to update the section under authInternalUsers:
. Under user: any
I removed the publish
action and added the following user config:
|
|
Then at the bottom of the example config file I added the following to the paths:
section:
|
|
Additionally I’ve disabled RTMP and HLS support since I don’t need them.
My complete config is available in the GitHub Gist.
Then enable and start the systemd service:
|
|
6.) Access the RTSP stream.
If everything goes well you should be able to access two streams at the following URLs:
rtsp://IP_Address_OF_PI:8554/hqstream
and
rtsp://IP_Address_OF_PI:8554/lqstream
Some additional optional steps
-
Disable swap
apt remove dphys-swapfile
-
Save logs to RAM disk to reduce SD card writes.
Install log2ram -
Install nginx to serve jpg snapshot
|
|
Revised article on 2024-06-17 with updated MediaMTX config