Ryanus commited on
Commit
acf47f9
·
verified ·
1 Parent(s): 284b0a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -8,43 +8,35 @@ import sys
8
  def process_video(input_video, segment_duration, enable_mix=False):
9
  if not input_video:
10
  return "請上傳影片"
11
-
12
- # 步驟 1: 切割長影片
13
  output_dir = "temp_segments"
14
  try:
15
  outputs = split_video(input_video, output_dir, int(segment_duration))
16
  gr.info(f"切割完成:生成 {len(outputs)} 個短片")
17
  except Exception as e:
18
  return f"切割錯誤:{str(e)}"
19
-
20
- # 步驟 2: 可選混剪(使用 pyToVideo2 的 main.py)
21
  if enable_mix:
22
  try:
23
- # 假設 pyToVideo2 的 main.py 支援 --input_folder 和 --num_clips 參數
24
- # 根據實際 main.py 調整命令(檢查 pyToVideo2 的 README 或代碼)
25
  cmd = [
26
  sys.executable, "main.py",
27
  "--input_folder", output_dir,
28
  "--output_folder", "mixed_output",
29
- "--num_clips", "20" # 混剪成 20 個新影片
30
  ]
31
  result = subprocess.run(cmd, capture_output=True, text=True)
32
  if result.returncode != 0:
33
  gr.warning(f"混剪警告:{result.stderr}")
34
  else:
35
- # 添加混剪輸出
36
  mixed_files = [os.path.join("mixed_output", f) for f in os.listdir("mixed_output") if f.endswith(".mp4")]
37
  outputs.extend(mixed_files)
38
  gr.info("混剪完成")
39
  except Exception as e:
40
  gr.warning(f"混剪錯誤:{str(e)}")
41
-
42
- # 清理臨時檔案(可選,節省空間)
43
- # for f in outputs:
44
- # if os.path.exists(f):
45
- # os.remove(f)
46
-
47
- return outputs # Gradio 提供下載
48
 
49
  iface = gr.Interface(
50
  fn=process_video,
 
8
  def process_video(input_video, segment_duration, enable_mix=False):
9
  if not input_video:
10
  return "請上傳影片"
11
+
12
+ # 切割長影片
13
  output_dir = "temp_segments"
14
  try:
15
  outputs = split_video(input_video, output_dir, int(segment_duration))
16
  gr.info(f"切割完成:生成 {len(outputs)} 個短片")
17
  except Exception as e:
18
  return f"切割錯誤:{str(e)}"
19
+
20
+ # 可選:運行 pyToVideo2 混剪
21
  if enable_mix:
22
  try:
 
 
23
  cmd = [
24
  sys.executable, "main.py",
25
  "--input_folder", output_dir,
26
  "--output_folder", "mixed_output",
27
+ "--num_clips", "20"
28
  ]
29
  result = subprocess.run(cmd, capture_output=True, text=True)
30
  if result.returncode != 0:
31
  gr.warning(f"混剪警告:{result.stderr}")
32
  else:
 
33
  mixed_files = [os.path.join("mixed_output", f) for f in os.listdir("mixed_output") if f.endswith(".mp4")]
34
  outputs.extend(mixed_files)
35
  gr.info("混剪完成")
36
  except Exception as e:
37
  gr.warning(f"混剪錯誤:{str(e)}")
38
+
39
+ return outputs
 
 
 
 
 
40
 
41
  iface = gr.Interface(
42
  fn=process_video,