How can I make an rtsp stream as correct as possible in a Django application?

I am writing a mini video surveillance system on Django. I want the stream to be output to the tag. now I have output to the img tag using a stream and jpeg images (using OpenCV)how to make a stream from a video, you may need to use WebRTC for the stream and somehow decode the video using ffmpeg, please tell me

def generate_frames(rtsp_url):
    cap = cv2.VideoCapture(rtsp_url)  # Замените на ваш RTSP URL

    while True:
        success, frame = cap.read()
        if not success:
            break

        # Кодируем кадр в JPEG
        ret, buffer = cv2.imencode('.mp4', frame)
        frame = buffer.tobytes()

        yield (b'--frame\r\n'
               b'Content-Type: video/mp4\r\n\r\n' + frame + b'\r\n')

i vant to stop video and start in video tag my html looks like this

  <div class="video-container">
    <img src="{% url 'video_feed' %}?rtspurl={{ rtsp_url }}" width="640" height="480" alt="{{ rtsp_url }}" />
    <div class="separator"></div>  <!-- Added separator div -->
    <p class="cam-name">Трансляция камеры: {{ cam_name }}<br>RTSP: <a>{{ rtsp_url }}</a></p>
  </div>
Вернуться на верх