It is coming from this line of code tfile.write(f.read())

import tempfile
import cv2
import streamlit as st
f = st.file_uploader("Choose a Video")
tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(f.read())
# Opens the Video file
cap= cv2.VideoCapture(tfile.name)
stframe = st.empty()
i=1
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
if i%1000 == 0:
cv2.imwrite('new_image'+str(i)+'.jpg',frame)
i+=1
cap.release()
cv2.destroyAllWindows()
Hi @chukypedro
I think you can put a check after f,
something like this should work,
import tempfile
import cv2
import streamlit as st
f = st.file_uploader("Choose a Video")
if f:
tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(f.read())
# Opens the Video file
cap= cv2.VideoCapture(tfile.name)
stframe = st.empty()
i=1
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
if i%1000 == 0:
cv2.imwrite('new_image'+str(i)+'.jpg',frame)
i+=1
cap.release()
cv2.destroyAllWindows()
PS. If you are just trying to play a uploaded video try this,
import streamlit as st
import io
f = st.file_uploader("Choose a Video")
if f:
st.video(io.BytesIO(f.getbuffer()))