frame-example / app.py
abidlabs's picture
abidlabs HF staff
Create app.py
df7a2cf
raw
history blame contribute delete
707 Bytes
import cv2, os
import gradio as gr
def process_frame(frame):
# Your processing logic here
return frame
def video_to_frames(video_filepath):
cap = cv2.VideoCapture(video_filepath)
frame_number = 0
while True:
ret, frame = cap.read()
if not ret:
break
frame_ = process_frame(frame)
# Save the frame as an image
os.makedirs("frames", exist_ok=True)
frame_filename = os.path.join("frames", f"frame_{frame_number}.jpg")
cv2.imwrite(frame_filename, frame_)
yield frame_filename
frame_number += 1
cap.release()
gr.Interface(video_to_frames, "video", "image").queue().launch()