Rahatara commited on
Commit
754d1ac
·
verified ·
1 Parent(s): b655741

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,25 +1,24 @@
1
- cimport gradio as gr
2
  from video2images import Video2Images
3
- from PIL import Image
4
  import os
5
 
6
- def extract_frames(video_filepath, out_dir):
7
- # Use a temporary filename in the current directory
8
- out_filepath = os.path.join(os.getcwd(), "extracted_frames")
 
 
 
 
 
 
9
  # Create Video2Images object
10
  v2i = Video2Images(video_filepath, out_dir=out_filepath)
11
  # Extract frames
12
  v2i.start()
13
- # Load extracted frames as PIL images
14
- frames = []
15
- for frame_filename in os.listdir(out_filepath):
16
- frame_path = os.path.join(out_filepath, frame_filename)
17
- frame_image = Image.open(frame_path)
18
- frames.append(frame_image)
19
- return frames # Return list of PIL images
20
 
21
  inputs = gr.Video(label="Upload Video")
22
- outputs = gr.ImageGallery(label="Extracted Frames")
23
 
24
  title = "Extract Frames from Video"
25
  description = "Upload a video file and extract frames from it."
 
1
+ import gradio as gr
2
  from video2images import Video2Images
 
3
  import os
4
 
5
+ def extract_frames(video_file):
6
+ # Temporary directory to store frames
7
+ temp_dir = "temp_frames"
8
+ os.makedirs(temp_dir, exist_ok=True)
9
+ # Save uploaded video to temporary directory
10
+ video_filepath = os.path.join(temp_dir, "uploaded_video.mp4")
11
+ video_file.save(video_filepath)
12
+ # Use the path of the uploaded video for extracting frames
13
+ out_filepath = os.path.join(temp_dir, "extracted_frames")
14
  # Create Video2Images object
15
  v2i = Video2Images(video_filepath, out_dir=out_filepath)
16
  # Extract frames
17
  v2i.start()
18
+ return out_filepath # Return the directory where frames are saved
 
 
 
 
 
 
19
 
20
  inputs = gr.Video(label="Upload Video")
21
+ outputs = gr.Textbox(label="Output Directory")
22
 
23
  title = "Extract Frames from Video"
24
  description = "Upload a video file and extract frames from it."