Spaces:
Running
Running
import gradio as gr | |
from moviepy.editor import VideoFileClip | |
# アップロードされた動画の解像度を表示する関数 | |
def show_original_resolution(video_path): | |
clip = VideoFileClip(video_path) | |
width, height = clip.size | |
return f"元の解像度: {width} x {height}" | |
# リサイズ処理の関数(解像度は取得済みなので返さない) | |
def resize_video(video_path, width, height): | |
clip = VideoFileClip(video_path) | |
resized_clip = clip.resize(newsize=(width, height)) | |
output_path = "/tmp/resized_video.mp4" | |
resized_clip.write_videofile(output_path, codec="libx264", audio_codec="aac") | |
return output_path | |
# Gradio Blocksを使ってインターフェースを組み立て | |
with gr.Blocks() as demo: | |
gr.Markdown("### 動画リサイズツール") | |
with gr.Row(): | |
video_input = gr.File(label="アップロードする動画", type="filepath") | |
resolution_display = gr.Textbox(label="元の解像度", interactive=False) | |
video_input.change(fn=show_original_resolution, inputs=video_input, outputs=resolution_display) | |
width_input = gr.Number(label="リサイズ後の幅", value=640) | |
height_input = gr.Number(label="リサイズ後の高さ", value=480) | |
resize_button = gr.Button("リサイズ実行") | |
output_video = gr.File(label="リサイズされた動画") | |
resize_button.click(fn=resize_video, inputs=[video_input, width_input, height_input], outputs=output_video) | |
demo.launch() | |