Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from moviepy.editor import VideoFileClip
|
4 |
+
|
5 |
+
def resize_video_and_show_resolution(video_path, width, height):
|
6 |
+
# 動画を読み込む
|
7 |
+
clip = VideoFileClip(video_path)
|
8 |
+
|
9 |
+
# 元の解像度
|
10 |
+
original_width, original_height = clip.size
|
11 |
+
|
12 |
+
# リサイズ処理(アスペクト比を無視して引き伸ばし)
|
13 |
+
resized_clip = clip.resize(newsize=(width, height))
|
14 |
+
|
15 |
+
# 出力ファイルパス
|
16 |
+
output_path = "/tmp/resized_video.mp4"
|
17 |
+
resized_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")
|
18 |
+
|
19 |
+
# 結果を返す:リサイズ後の動画ファイル + 元のサイズ情報
|
20 |
+
resolution_info = f"元の解像度: {original_width} x {original_height}"
|
21 |
+
return output_path, resolution_info
|
22 |
+
|
23 |
+
# Gradioインターフェース
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=resize_video_and_show_resolution,
|
26 |
+
inputs=[
|
27 |
+
gr.File(label="アップロードする動画", type="filepath"),
|
28 |
+
gr.Number(label="リサイズ後の幅", value=640),
|
29 |
+
gr.Number(label="リサイズ後の高さ", value=480)
|
30 |
+
],
|
31 |
+
outputs=[
|
32 |
+
gr.File(label="リサイズされた動画"),
|
33 |
+
gr.Textbox(label="元の解像度")
|
34 |
+
]
|
35 |
+
)
|
36 |
+
|
37 |
+
iface.launch()
|