Low-level RTSP video streamer for Raspberry Pi 5
A highly reliable background system service based on Python has been developed and successfully deployed for the Raspberry Pi 5 platform running Linux OS.
The main task of the software is high-speed capture of raw MJPEG video streams from USB ports (external HDMI capture cards and webcams) and stable streaming via RTSP protocol to static addresses on the local network with minimal latency.
Key technical solutions and features of the project:
1. Hardware optimization of the video pipeline: Fine-tuning of FFmpeg buffering parameters. As a result, the network video latency has been reduced to a physical minimum (less than 100-150 ms).
2. Dynamic hardware detection: Integration with the v4l2-ctl utility at the Linux kernel level. The script automatically scans the ports, recognizes connected capture boards, and dynamically incorporates them into operation. A cross-platform compatible fallback has been implemented to simulate devices in a Windows environment.
3. Extreme fault tolerance: The architecture is built on isolated StreamWorker threads managed by a central supervisor StreamManager. An automatic recovery mechanism for the video core has been implemented in case of stream failure or cable disconnection using exponential backoff delays.
4. Safe OS process management: Proper cleanup of zombie processes at the Linux operating system level has been implemented through the creation of isolated process sessions and the application of system signals to process groups (os.killpg with SIGTERM/SIGKILL flags). This completely eliminates memory leaks during restarts.
5. Built-in hardware telemetry: Continuous non-blocking monitoring of CPU load has been configured, along with direct reading of temperature sensor metrics from the Raspberry Pi chip in the system kernel zone (/sys/class/thermal/thermal_zone0/temp) to prevent throttling.
The project is fully autonomous, designed as a background daemon, and starts automatically upon device boot or after power interruptions.
#Python #Linux #FFmpeg #RaspberryPi #RTSP #StreamingVideo #SystemProgramming #Subprocess #Architecture
The main task of the software is high-speed capture of raw MJPEG video streams from USB ports (external HDMI capture cards and webcams) and stable streaming via RTSP protocol to static addresses on the local network with minimal latency.
Key technical solutions and features of the project:
1. Hardware optimization of the video pipeline: Fine-tuning of FFmpeg buffering parameters. As a result, the network video latency has been reduced to a physical minimum (less than 100-150 ms).
2. Dynamic hardware detection: Integration with the v4l2-ctl utility at the Linux kernel level. The script automatically scans the ports, recognizes connected capture boards, and dynamically incorporates them into operation. A cross-platform compatible fallback has been implemented to simulate devices in a Windows environment.
3. Extreme fault tolerance: The architecture is built on isolated StreamWorker threads managed by a central supervisor StreamManager. An automatic recovery mechanism for the video core has been implemented in case of stream failure or cable disconnection using exponential backoff delays.
4. Safe OS process management: Proper cleanup of zombie processes at the Linux operating system level has been implemented through the creation of isolated process sessions and the application of system signals to process groups (os.killpg with SIGTERM/SIGKILL flags). This completely eliminates memory leaks during restarts.
5. Built-in hardware telemetry: Continuous non-blocking monitoring of CPU load has been configured, along with direct reading of temperature sensor metrics from the Raspberry Pi chip in the system kernel zone (/sys/class/thermal/thermal_zone0/temp) to prevent throttling.
The project is fully autonomous, designed as a background daemon, and starts automatically upon device boot or after power interruptions.
#Python #Linux #FFmpeg #RaspberryPi #RTSP #StreamingVideo #SystemProgramming #Subprocess #Architecture