How to access uploaded video in streamlit by open cv?

Seems wasteful, but if OpenCV really requires a file, I wonder if this will be acceptable:

import streamlit as st
import cv2 as cv
import tempfile

f = st.file_uploader("Upload file")
tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(f.read())
vf = cv.VideoCapture(tfile.name)
1 Like