Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import io | |
| import cv2 | |
| st.title("Play Uploaded File") | |
| uploaded_file = st.file_uploader("Choose a video...", type=["mp4"]) | |
| temporary_location = False | |
| def capture_video_frames(): | |
| video_file = st.file_uploader('video', type = ['mp4']) | |
| cap = cv2.VideoCapture(video_file) | |
| while cap.isOpened(): | |
| ret, frame = cap.read() | |
| yield frame | |
| def display_video_frames(): | |
| st.title("Live Video Stream") | |
| frame_generator = capture_video_frames() | |
| for frame in frame_generator: | |
| # Convert the frame from OpenCV's BGR format to RGB format | |
| frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| # Display the frame using Streamlit | |
| st.image(frame_rgb, channels="RGB", use_column_width=True) | |
| # if uploaded_file is not None: | |
| # video_file = st.file_uploader('video', type = ['mp4']) | |
| # cap = cv2.VideoCapture(video_file) | |
| # output = cv2.VideoWriter('output.mp4',cv2.VideoWriter_fourcc(*'MPEG'),30,(1080,1920)) | |
| # while cap.isOpened(): | |
| # # Capture frame-by-frame | |
| # ret, frame = cap.read() | |
| # # if frame is read correctly ret is True | |
| # if not ret: | |
| # print("Can't receive frame (stream end?). Exiting ...") | |
| # break | |
| # # Our operations on the frame come here | |
| # gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) | |
| # output.write(frame) | |
| # # Display the resulting frame | |
| # cv.imshow('frame', gray) | |
| # if cv.waitKey(1) == ord('q'): | |
| # break | |
| # cv2.destroyAllWindows() | |
| # output.release() | |
| # cap.release() | |
| # display_video_frames() | |
| if uploaded_file is not None: | |
| display_video_frames() | |