Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image, ImageSequence
|
3 |
-
|
4 |
|
5 |
def edit_file(file, loop_count, speed_factor, frame_skip):
|
6 |
file_name = file.name.split("/")[-1] # 元ファイル名を取得
|
@@ -9,9 +9,18 @@ def edit_file(file, loop_count, speed_factor, frame_skip):
|
|
9 |
# ファイルがGIFか動画か判定
|
10 |
if file.name.endswith((".mp4", ".avi", ".mov", ".mkv")):
|
11 |
# 動画をGIFに変換
|
12 |
-
clip = VideoFileClip(file.name)
|
13 |
gif_path = f"{base_name}.gif"
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
gif = Image.open(gif_path)
|
16 |
else:
|
17 |
gif = Image.open(file.name)
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image, ImageSequence
|
3 |
+
import imageio
|
4 |
|
5 |
def edit_file(file, loop_count, speed_factor, frame_skip):
|
6 |
file_name = file.name.split("/")[-1] # 元ファイル名を取得
|
|
|
9 |
# ファイルがGIFか動画か判定
|
10 |
if file.name.endswith((".mp4", ".avi", ".mov", ".mkv")):
|
11 |
# 動画をGIFに変換
|
|
|
12 |
gif_path = f"{base_name}.gif"
|
13 |
+
video = imageio.get_reader(file.name)
|
14 |
+
frames = []
|
15 |
+
for i, frame in enumerate(video):
|
16 |
+
# 指定したフレーム数ごとにスキップ
|
17 |
+
if i % frame_skip != 0:
|
18 |
+
continue
|
19 |
+
# 再生速度調整
|
20 |
+
frames.append(frame)
|
21 |
+
|
22 |
+
# GIFとして保存
|
23 |
+
imageio.mimsave(gif_path, frames, duration=1/speed_factor)
|
24 |
gif = Image.open(gif_path)
|
25 |
else:
|
26 |
gif = Image.open(file.name)
|