soiz1 commited on
Commit
dab190d
·
verified ·
1 Parent(s): c5636c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -28
app.py CHANGED
@@ -1,37 +1,36 @@
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()
 
 
1
  import gradio as gr
2
  from moviepy.editor import VideoFileClip
3
 
4
+ # アップロードされた動画の解像度を表示する関数
5
+ def show_original_resolution(video_path):
6
  clip = VideoFileClip(video_path)
7
+ width, height = clip.size
8
+ return f"元の解像度: {width} x {height}"
 
9
 
10
+ # リサイズ処理の関数(解像度は取得済みなので返さない)
11
+ def resize_video(video_path, width, height):
12
+ clip = VideoFileClip(video_path)
13
  resized_clip = clip.resize(newsize=(width, height))
 
 
14
  output_path = "/tmp/resized_video.mp4"
15
  resized_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")
16
+ return output_path
17
+
18
+ # Gradio Blocksを使ってインターフェースを組み立て
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("### 動画リサイズツール")
21
+
22
+ with gr.Row():
23
+ video_input = gr.File(label="アップロードする動画", type="filepath")
24
+ resolution_display = gr.Textbox(label="元の解像度", interactive=False)
25
+
26
+ video_input.change(fn=show_original_resolution, inputs=video_input, outputs=resolution_display)
27
+
28
+ width_input = gr.Number(label="リサイズ後の幅", value=640)
29
+ height_input = gr.Number(label="リサイズ後の高さ", value=480)
30
+
31
+ resize_button = gr.Button("リサイズ実行")
32
+ output_video = gr.File(label="リサイズされた動画")
33
+
34
+ resize_button.click(fn=resize_video, inputs=[video_input, width_input, height_input], outputs=output_video)
35
 
36
+ demo.launch()