I would like to preview a recorded video (using OpenCV) in the webpage but keep getting this error.
Knowing that I can read on my laptop both videos, the original, and the recorded one.
I have tested on Firefox and Chromium.
On top, I display the original video et on the bottom of the processed one.
Here is a code I used:
import cv2
import streamlit as st
cap = cv2.VideoCapture("demo.mp4")
st.video("demo.mp4")
ret = True
record =None
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
while ret:
ret, frame = cap.read()
if record is None:
(H, W) = frame.shape[:2]
out = cv2.VideoWriter('demo_.mp4',fourcc, 10, (W, H))
record = True
if ret==True:
frame = cv2.flip(frame,0)
out.write(frame)
cap.release()
out.release()
video_byte = open("demo_.mp4", 'rb').read()
st.video(video_byte)
what if i am making a kind of an interface to allow users to input a video file which gets processed with OpenCv and stored in a local directory.
I now want to use this local file to show on the streamlit app.
But for this fix i need to change file format normally?
what should i do to make it an automated pipeline?
Hi @AbhinavKoul, welcome to the Streamlit community!
From what you’ve written, I don’t think there are any issues. A user can upload any video file that OpenCV can handle, which will come in as Bytes from the file_uploader Streamlit widget. When it’s time to write it back to a file post-processing, then you export it using H.264, which will allow it to be shown in the browser/Streamlit.
Thanks a lot @randyzwitch. Was able to successfully do this.
While doing this i faced one issue that it takes a lot of time to process the entire length of video(basically exactly the same time as video length)
Is there any way to fix this or a way where i can show the live changes in file as seen by openCV