[HOW-TO] make this rtsp stream stable?

Open
#1,037 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python, raspberry-pi

Research direction

Start with camera.py, especially FfmpegOutput, the assigned error_callback, and start_encoder; main.py shows the continuous-running entry point. Reproduce the stream interruption and inspect the complete broken-pipe exception and callback output to determine whether the failure is reported by ffmpeg or Picamera2. Done means the failure source is identified and the stream's stability issue is addressed.

Written by the indexing model from the issue text.

Description

i have a example to push rtsp stream to my server
raspberrypi 4b
picamera2 0.3.18
python 3.11.2
camera.py

from picamera2 import Picamera2
from picamera2.encoders import H264Encoder
from picamera2.outputs import FfmpegOutput
from tool.log.log_uru import Logger


class Camera(object):
    def __init__(self, sn):
        self.rtsp = None
        self.lug = Logger().get_logger
        self.picam2 = Picamera2()
        # Picamera2.set_logging(Picamera2.DEBUG)
        # rtsp推流的编码
        self.encoder = None
        resolution = (1280, 720)
        self.picam2.configure(self.picam2.create_video_configuration(main={"size": resolution}))
        self.picam2.start()
        self.lug.info("Camera initialized")
        self.start_rtsp()

    def error_callback(self, e):
        """
        picamera2异常断开的回调函数
        """
        self.lug.error("Camera Error {}", e)
        # 重连
        # self.picam2.stop_encoder(self.encoder)
        # self.start_rtsp()
        # self.lug.warning("reconnecting...")

    def start_rtsp(self):
        # self.encoder = H264Encoder(bitrate=1000000)
        self.encoder = H264Encoder(bitrate=1000000, repeat=True, iperiod=15, framerate=15)
        self.rtsp = FfmpegOutput("-f rtsp rtsp://myserverip/live/test")
        self.rtsp.error_callback = self.error_callback
        self.encoder.output = self.rtsp
        self.picam2.start_encoder(self.encoder)

    def stop(self):
        """
        停止camera
        :return:
        """
        self.picam2.stop()


i run this camera.
main.py


if __name__ == '__main__':
   Camera("camera")
   while True:
     pass

However, if he pushes the RTSP stream for a maximum of 10 minutes, a broken pipe exception will appear。i want to know this is the ffmpeg's error or picamera2's error;

Dominant language
Python
Stars
1.2k
Forks
258
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/picamera2

All issues in raspberrypi/picamera2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.