Spaces:
Runtime error
Runtime error
Download app.py from Trueinfo/video2frames: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/spaces/Trueinfo/video2frames/resolve/main/app.py
- Command line
-
hf download hf://spaces/Trueinfo/video2frames/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Trueinfo/video2frames/resolve/main/app.py
948 Bytes
| import streamlit as st | |
| import cv2 | |
| from PIL import Image | |
| uploaded_video = st.file_uploader("Choose video", type=["mp4", "mov"]) | |
| frame_skip = 200 # display every 300 frames | |
| if uploaded_video is not None: # run only when user uploads video | |
| vid = uploaded_video.name | |
| with open(vid, mode='wb') as f: | |
| f.write(uploaded_video.read()) # save video to disk | |
| st.markdown(f""" | |
| ### Files | |
| - {vid} | |
| """, | |
| unsafe_allow_html=True) # display file name | |
| vidcap = cv2.VideoCapture(vid) # load video from disk | |
| cur_frame = 0 | |
| success = True | |
| while success: | |
| success, frame = vidcap.read() # get next frame from video | |
| if cur_frame % frame_skip == 0: # only analyze every n=300 frames | |
| print('frame: {}'.format(cur_frame)) | |
| pil_img = Image.fromarray(frame) # convert opencv frame (with type()==numpy) into PIL Image | |
| st.image(pil_img,channels='BGR') | |
| cur_frame += 1 |