Hey, guys!
I’m trying to display a realtime video in a streamlit application from an RTSP link. I know I can use opencv to process it, but I can’t display it. Do you have any idea how I can do this? Below is a code I’ve already tried.
import cv2
import numpy as np
import streamlit as st
# Function to capture frames from an RTSP stream
def capture_frames(rtsp_url):
cap = cv2.VideoCapture(rtsp_url)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# You might want to resize the frame here if it's too large for display
frame = cv2.resize(frame, (640, 480))
yield frame
cap.release()
# Streamlit app
def main():
st.title('RTSP Stream Player')
rtsp_url = st.text_input('Enter RTSP stream URL')
if rtsp_url:
st.text('Streaming from: ' + rtsp_url)
# Create a VideoCapture generator
frame_gen = capture_frames(rtsp_url)
# Display the frames using Streamlit
while True:
frame = next(frame_gen)
st.image(frame)
if __name__ == '__main__':
main()