Spaces:
Running
Running
import gradio as gr | |
from moviepy.editor import VideoFileClip | |
def resize_video_and_show_resolution(video_path, width, height): | |
# 動画を読み込む | |
clip = VideoFileClip(video_path) | |
# 元の解像度 | |
original_width, original_height = clip.size | |
# リサイズ処理(アスペクト比を無視して引き伸ばし) | |
resized_clip = clip.resize(newsize=(width, height)) | |
# 出力ファイルパス | |
output_path = "/tmp/resized_video.mp4" | |
resized_clip.write_videofile(output_path, codec="libx264", audio_codec="aac") | |
# 結果を返す:リサイズ後の動画ファイル + 元のサイズ情報 | |
resolution_info = f"元の解像度: {original_width} x {original_height}" | |
return output_path, resolution_info | |
# Gradioインターフェース | |
iface = gr.Interface( | |
fn=resize_video_and_show_resolution, | |
inputs=[ | |
gr.File(label="アップロードする動画", type="filepath"), | |
gr.Number(label="リサイズ後の幅", value=640), | |
gr.Number(label="リサイズ後の高さ", value=480) | |
], | |
outputs=[ | |
gr.File(label="リサイズされた動画"), | |
gr.Textbox(label="元の解像度") | |
] | |
) | |
iface.launch() | |