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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.