Spaces:
Runtime error
Runtime error
eienmojiki
commited on
Commit
•
b311af1
1
Parent(s):
1586983
Update app.py
Browse files
app.py
CHANGED
@@ -5,35 +5,33 @@ import gradio as gr
|
|
5 |
|
6 |
def get_video_detail(video_path):
|
7 |
if not video_path:
|
8 |
-
return 0, 0, 0, 0
|
9 |
|
10 |
else:
|
11 |
info = VideoFileClip(video_path)
|
12 |
-
return 0, info.duration, info.fps, max(info.size)
|
13 |
|
14 |
def convert_video_to_gif(
|
15 |
input: str,
|
16 |
start: float = 0,
|
17 |
end: float | None = None,
|
18 |
fps: int | None = None,
|
19 |
-
quality: int | None = None
|
|
|
20 |
):
|
21 |
"""
|
22 |
Convert video to GIF image
|
23 |
-
|
24 |
Args:
|
25 |
input (str): Path to video file.
|
26 |
start (float, optional): Start time in seconds. Defaults to 0.
|
27 |
end (float, optional): End time in seconds. Defaults to None.
|
28 |
fps (int, optional): Frames per second. Defaults to None (max fps).
|
29 |
quality (int, optional): Image quality. Defaults to None (max quality).
|
30 |
-
|
31 |
Returns:
|
32 |
str: Path to the GIF file
|
33 |
-
|
34 |
Examples:
|
35 |
-
>>> convert_video_to_gif("input.mp4")
|
36 |
-
|
37 |
"""
|
38 |
# Get video input & info
|
39 |
clip = VideoFileClip(input)
|
@@ -65,6 +63,9 @@ def convert_video_to_gif(
|
|
65 |
target_width = int(target_height * aspect_ratio)
|
66 |
clip = clip.resize((target_width, target_height))
|
67 |
|
|
|
|
|
|
|
68 |
clip = clip.set_fps(fps)
|
69 |
|
70 |
# Create a temporary file
|
@@ -115,6 +116,12 @@ with gr.Blocks(
|
|
115 |
interactive=True
|
116 |
)
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
run_btn = gr.Button("Convert")
|
119 |
output = gr.File(
|
120 |
label="GIF"
|
@@ -129,14 +136,14 @@ with gr.Blocks(
|
|
129 |
).then(
|
130 |
fn=get_video_detail,
|
131 |
inputs=save,
|
132 |
-
outputs=[start, end, fps, quality],
|
133 |
queue=False,
|
134 |
api_name="info"
|
135 |
)
|
136 |
|
137 |
run_btn.click(
|
138 |
fn=convert_video_to_gif,
|
139 |
-
inputs=[save, start, end, fps, quality],
|
140 |
outputs=output,
|
141 |
api_name="convert"
|
142 |
)
|
|
|
5 |
|
6 |
def get_video_detail(video_path):
|
7 |
if not video_path:
|
8 |
+
return 0, 0, 0, 0, 1.0
|
9 |
|
10 |
else:
|
11 |
info = VideoFileClip(video_path)
|
12 |
+
return 0, info.duration, info.fps, max(info.size), 1.0
|
13 |
|
14 |
def convert_video_to_gif(
|
15 |
input: str,
|
16 |
start: float = 0,
|
17 |
end: float | None = None,
|
18 |
fps: int | None = None,
|
19 |
+
quality: int | None = None,
|
20 |
+
speed: float = 1.0 # Add the 'speed' parameter
|
21 |
):
|
22 |
"""
|
23 |
Convert video to GIF image
|
|
|
24 |
Args:
|
25 |
input (str): Path to video file.
|
26 |
start (float, optional): Start time in seconds. Defaults to 0.
|
27 |
end (float, optional): End time in seconds. Defaults to None.
|
28 |
fps (int, optional): Frames per second. Defaults to None (max fps).
|
29 |
quality (int, optional): Image quality. Defaults to None (max quality).
|
30 |
+
speed (float, optional): Playback speed. Defaults to 1.0 (normal speed).
|
31 |
Returns:
|
32 |
str: Path to the GIF file
|
|
|
33 |
Examples:
|
34 |
+
>>> convert_video_to_gif("input.mp4", speed=2.0)
|
|
|
35 |
"""
|
36 |
# Get video input & info
|
37 |
clip = VideoFileClip(input)
|
|
|
63 |
target_width = int(target_height * aspect_ratio)
|
64 |
clip = clip.resize((target_width, target_height))
|
65 |
|
66 |
+
# Set the playback speed
|
67 |
+
clip = clip.fx(vfx.all, speed)
|
68 |
+
|
69 |
clip = clip.set_fps(fps)
|
70 |
|
71 |
# Create a temporary file
|
|
|
116 |
interactive=True
|
117 |
)
|
118 |
|
119 |
+
speed = gr.Number(
|
120 |
+
label="Speed",
|
121 |
+
info="Default speed / Gif speed",
|
122 |
+
interactive=True
|
123 |
+
)
|
124 |
+
|
125 |
run_btn = gr.Button("Convert")
|
126 |
output = gr.File(
|
127 |
label="GIF"
|
|
|
136 |
).then(
|
137 |
fn=get_video_detail,
|
138 |
inputs=save,
|
139 |
+
outputs=[start, end, fps, quality, speed],
|
140 |
queue=False,
|
141 |
api_name="info"
|
142 |
)
|
143 |
|
144 |
run_btn.click(
|
145 |
fn=convert_video_to_gif,
|
146 |
+
inputs=[save, start, end, fps, quality, speed],
|
147 |
outputs=output,
|
148 |
api_name="convert"
|
149 |
)
|