I’ve been using Streamlit for a real time dashboard, and while data has been fast, video has been really slow. When I say video, I mean frames, because this would be reading from a camera or server providing images. Another way of framing this question is “can st.image be run 60 times per second?”
For a while, I blamed factors like network for the slow video speed, but I tested it today and it seems like even the most bare bones st.image display loop only gets around 14 fps for a 480p video. (It’s 70ms step time, 1000/70 ~=14). Code to recreate:
import streamlit as st
from timeit import default_timer as timer
import cv2
vid_area = st.empty()
data_area = st.empty()
step_time = st.empty()
old_time = timer()
cap = cv2.VideoCapture("480.mp4")
while cap.isOpened():
time = timer()
step_time.write(f"Step time: {time - old_time:.3f}")
old_time = time
ret, image = cap.read()
vid_area.image(image, channels='BGR')
I know it’s not opencv’s fault because imshowing it with opencv is very fast:
cap = cv2.VideoCapture("480.mp4")
while cap.isOpened():
ret, frame = cap.read()
cv2.imshow("hi", frame)
cv2.waitKey(1)
I recognize that st.image is probably not built for this purpose, but I’m wondering what my optoins are as I really enjoy working with streamlit but I need the faster fps to use it for my use case.