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

Update split_video.py

Browse files
Files changed (1) hide show
  1. split_video.py +3 -3
split_video.py CHANGED
@@ -5,13 +5,13 @@ import os
5
  def split_video(input_path, output_dir, segment_duration=60):
6
  if not os.path.exists(input_path):
7
  raise ValueError("輸入影片不存在")
8
-
9
  video = VideoFileClip(input_path)
10
  total_duration = video.duration
11
  num_segments = int(total_duration / segment_duration) + (1 if total_duration % segment_duration > 0 else 0)
12
  os.makedirs(output_dir, exist_ok=True)
13
  outputs = []
14
-
15
  for i in range(num_segments):
16
  start = i * segment_duration
17
  end = min((i + 1) * segment_duration, total_duration)
@@ -20,6 +20,6 @@ def split_video(input_path, output_dir, segment_duration=60):
20
  subclip.write_videofile(output_file, codec='libx264', audio_codec='aac', verbose=False, logger=None)
21
  outputs.append(output_file)
22
  subclip.close()
23
-
24
  video.close()
25
  return outputs
 
5
  def split_video(input_path, output_dir, segment_duration=60):
6
  if not os.path.exists(input_path):
7
  raise ValueError("輸入影片不存在")
8
+
9
  video = VideoFileClip(input_path)
10
  total_duration = video.duration
11
  num_segments = int(total_duration / segment_duration) + (1 if total_duration % segment_duration > 0 else 0)
12
  os.makedirs(output_dir, exist_ok=True)
13
  outputs = []
14
+
15
  for i in range(num_segments):
16
  start = i * segment_duration
17
  end = min((i + 1) * segment_duration, total_duration)
 
20
  subclip.write_videofile(output_file, codec='libx264', audio_codec='aac', verbose=False, logger=None)
21
  outputs.append(output_file)
22
  subclip.close()
23
+
24
  video.close()
25
  return outputs