abidlabs HF staff commited on
Commit
df7a2cf
1 Parent(s): 31a6998

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2, os
2
+ import gradio as gr
3
+
4
+ def process_frame(frame):
5
+ # Your processing logic here
6
+ return frame
7
+
8
+ def video_to_frames(video_filepath):
9
+ cap = cv2.VideoCapture(video_filepath)
10
+ frame_number = 0
11
+ while True:
12
+ ret, frame = cap.read()
13
+ if not ret:
14
+ break
15
+
16
+ frame_ = process_frame(frame)
17
+
18
+ # Save the frame as an image
19
+ os.makedirs("frames", exist_ok=True)
20
+ frame_filename = os.path.join("frames", f"frame_{frame_number}.jpg")
21
+ cv2.imwrite(frame_filename, frame_)
22
+ yield frame_filename
23
+
24
+ frame_number += 1
25
+
26
+ cap.release()
27
+
28
+ gr.Interface(video_to_frames, "video", "image").queue().launch()