File size: 1,792 Bytes
d85aab3
4ff70b7
c8fb47a
d85aab3
 
 
c8fb47a
d85aab3
c8fb47a
 
acf47f9
 
c8fb47a
d85aab3
 
 
 
 
acf47f9
 
d85aab3
 
 
 
 
 
acf47f9
d85aab3
 
 
 
 
 
 
 
 
 
acf47f9
 
c8fb47a
 
 
 
 
d85aab3
 
c8fb47a
d85aab3
 
 
746bc44
 
59fd99f
c8fb47a
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# app.py
import gradio as gr
from split_video import split_video
import os
import subprocess
import sys

def process_video(input_video, segment_duration, enable_mix=False):
    if not input_video:
        return "請上傳影片"

    # 切割長影片
    output_dir = "temp_segments"
    try:
        outputs = split_video(input_video, output_dir, int(segment_duration))
        gr.info(f"切割完成:生成 {len(outputs)} 個短片")
    except Exception as e:
        return f"切割錯誤:{str(e)}"

    # 可選:運行 pyToVideo2 混剪
    if enable_mix:
        try:
            cmd = [
                sys.executable, "main.py",
                "--input_folder", output_dir,
                "--output_folder", "mixed_output",
                "--num_clips", "20"
            ]
            result = subprocess.run(cmd, capture_output=True, text=True)
            if result.returncode != 0:
                gr.warning(f"混剪警告:{result.stderr}")
            else:
                mixed_files = [os.path.join("mixed_output", f) for f in os.listdir("mixed_output") if f.endswith(".mp4")]
                outputs.extend(mixed_files)
                gr.info("混剪完成")
        except Exception as e:
            gr.warning(f"混剪錯誤:{str(e)}")

    return outputs

iface = gr.Interface(
    fn=process_video,
    inputs=[
        gr.File(label="上傳長影片 (MP4)"),
        gr.Number(label="每段長度 (秒)", value=60),
        gr.Checkbox(label="啟用 pyToVideo2 混剪", value=False)
    ],
    outputs=gr.Files(label="下載短影片 / 混剪結果"),
    title="pyToVideo2 影片切割與混剪",
    description="上傳長影片切割成短片,並可選使用 pyToVideo2 混剪成 20 個新影片。"
)

if __name__ == "__main__":
    iface.launch()