Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,24 @@
|
|
| 1 |
-
|
| 2 |
from video2images import Video2Images
|
| 3 |
-
from PIL import Image
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
def extract_frames(
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Create Video2Images object
|
| 10 |
v2i = Video2Images(video_filepath, out_dir=out_filepath)
|
| 11 |
# Extract frames
|
| 12 |
v2i.start()
|
| 13 |
-
#
|
| 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.
|
| 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."
|