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
python3-picamera2 library should already be pre-installed.
3.) Create and edit
5.) Edit the
The main thing that needs to be changed is the section under
Additionally I’ve disabled RTMP and HLS support since I don’t need it.
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:
Some additional optional steps
apt remove dphys-swapfile
Save logs to RAM disk to reduce SD card writes.
Install nginx to serve jpg snapshot