Rahatara commited on
Commit
24802c8
·
verified ·
1 Parent(s): 3bb6aeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -8
app.py CHANGED
@@ -1,13 +1,37 @@
 
 
1
  import gradio as gr
 
 
2
 
3
- def video_identity(video):
4
- return video
 
 
 
 
 
 
 
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- demo = gr.Interface(video_identity,
8
- gr.Video(),
9
- "playable_video",
10
- )
11
 
12
- if __name__ == "__main__":
13
- demo.launch()
 
 
 
1
+ from video2images import Video2Images
2
+ import os
3
  import gradio as gr
4
+ from PIL import Image
5
+ import shutil
6
 
7
+ def capture_frames(video_filepath, start_time=None, end_time=None, capture_rate=None, save_format=".jpg", out_dir=None):
8
+ # Create a Video2Images object
9
+ v2i = Video2Images(video_filepath, start_time=start_time, end_time=end_time, capture_rate=capture_rate, save_format=save_format, out_dir=out_dir)
10
+ # Extract frames
11
+ v2i.extract()
12
+ # Get paths of captured frames
13
+ frame_paths = v2i.get_frames_path()
14
+ # Load frames as PIL images
15
+ frames = [Image.open(frame_path) for frame_path in frame_paths]
16
+ return frames
17
 
18
+ def video_to_gallery(video_path):
19
+ # Temporary directory to store frames
20
+ temp_dir = "temp_frames"
21
+ os.makedirs(temp_dir, exist_ok=True)
22
+ # Copy video file to temporary directory
23
+ video_file_path = os.path.join(temp_dir, "uploaded_video.mp4")
24
+ shutil.copyfile(video_path, video_file_path)
25
+ # Capture frames from video
26
+ frames = capture_frames(video_file_path, out_dir=temp_dir)
27
+ # Remove temporary directory
28
+ shutil.rmtree(temp_dir)
29
+ return video_file_path
30
 
31
+ inputs = gr.Video(label="Upload Video")
32
+ outputs = gr.Gallery(label="Frames")
 
 
33
 
34
+ title = "Video to Image Gallery"
35
+ description = "Upload a video and get its frames displayed as a gallery of images."
36
+
37
+ gr.Interface(fn=video_to_gallery, inputs=inputs, outputs=outputs, title=title, description=description).launch()