I uploaded a video using streamlit but when I tried to read the video into Using OpenCV I get an error. Streamlit Code
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# To read file as bytes:
bytes_data = uploaded_file.read()
st.write(bytes_data)
print(bytes_data)
**OpenCV**
import CV2
# Opens the Video file
cap= cv2.VideoCapture(uploaded_file)
i=1
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
if i%100 == 0:
cv2.imwrite('house'+str(i)+'.jpg',frame)
i+=1
cap.release()
cv2.destroyAllWindows
The API reference states that UploadedFile class is a subclass of BytesIO, and therefore it is “file-like”. This means you can pass them anywhere where a file is expected.