7pixels commited on
Commit
f128b45
·
verified ·
1 Parent(s): a791d87

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from moviepy.editor import VideoFileClip
3
+ import os
4
+ from PIL import Image
5
+ import numpy as np
6
+
7
+ def video_to_images(video_file, fps=1):
8
+ video_path = video_file.name
9
+ output_folder = "frames"
10
+ os.makedirs(output_folder, exist_ok=True)
11
+
12
+ clip = VideoFileClip(video_path)
13
+ duration = int(clip.duration)
14
+
15
+ for t in range(0, duration, int(1/fps)):
16
+ frame = clip.get_frame(t)
17
+ frame_filename = os.path.join(output_folder, f"frame_{t:04d}.png")
18
+ img = Image.fromarray(frame)
19
+ img.save(frame_filename)
20
+
21
+ return [os.path.join(output_folder, f) for f in os.listdir(output_folder)]
22
+
23
+ iface = gr.Interface(
24
+ fn=video_to_images,
25
+ inputs=[gr.File(label="Upload Video"), gr.Slider(0.1, 5, value=1, step=0.1, label="Frames per second")],
26
+ outputs=gr.Gallery(label="Extracted Frames").style(grid=4),
27
+ title="Video to Images Converter"
28
+ )
29
+
30
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ moviepy
3
+ opencv-python
4
+ Pillow