Spaces:
Running
Running
File size: 1,267 Bytes
e9c4020 035c6aa 51e5e37 9f3650c 1b88ba6 035c6aa 1b88ba6 035c6aa 9f3650c 035c6aa 1b88ba6 e9c4020 9f3650c e9c4020 9f3650c e9c4020 42e0d78 e9c4020 9f3650c 1b88ba6 9f3650c e9c4020 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
from moviepy.editor import VideoFileClip
def edit_file(file, loop_count, speed_factor, frame_skip):
file_name = file.name.split("/")[-1]
base_name = file_name.rsplit(".", 1)[0]
# 動画またはGIFの読み込み
clip = VideoFileClip(file.name)
# フレームスキップと速度調整
if frame_skip > 1:
clip = clip.subclip(0, clip.duration).set_fps(clip.fps / frame_skip)
if speed_factor != 1:
clip = clip.fx(VideoFileClip.speedx, factor=speed_factor)
# GIFとして書き出し
output_path = f"{base_name}_edited.gif"
clip.write_gif(output_path, loop=loop_count)
return output_path, output_path
# Gradioインターフェース
interface = gr.Interface(
fn=edit_file,
inputs=[
gr.File(label="GIFまたは動画をアップロード"),
gr.Number(label="ループ回数(0は無限ループ)", value=0),
gr.Number(label="再生速度の倍率(例: 2は2倍速)", value=1),
gr.Number(label="フレームスキップ数(1以上)", value=1, minimum=1),
],
outputs=[
gr.File(label="ダウンロードリンク"),
gr.Image(label="プレビュー", type="filepath")
]
)
interface.launch()
|