Delete split_video.py
Browse files- split_video.py +0 -26
split_video.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
# split_video.py
|
| 2 |
-
import subprocess
|
| 3 |
-
import math
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
def split_video(input_path, output_dir, segment_duration=60):
|
| 7 |
-
if not os.path.exists(input_path):
|
| 8 |
-
raise ValueError("輸入影片不存在")
|
| 9 |
-
|
| 10 |
-
os.makedirs(output_dir, exist_ok=True)
|
| 11 |
-
cmd_duration = ['ffprobe', '-v', 'quiet', '-show_entries', 'format=duration', '-of', 'csv=p=0', input_path]
|
| 12 |
-
result = subprocess.run(cmd_duration, capture_output=True, text=True)
|
| 13 |
-
total_duration = float(result.stdout.strip())
|
| 14 |
-
|
| 15 |
-
num_segments = math.ceil(total_duration / segment_duration)
|
| 16 |
-
outputs = []
|
| 17 |
-
for i in range(num_segments):
|
| 18 |
-
start_time = i * segment_duration
|
| 19 |
-
output_file = os.path.join(output_dir, f"segment_{i+1}.mp4")
|
| 20 |
-
cmd_split = [
|
| 21 |
-
'ffmpeg', '-i', input_path, '-ss', str(start_time), '-t', str(segment_duration),
|
| 22 |
-
'-c', 'copy', '-avoid_negative_ts', 'make_zero', output_file, '-y'
|
| 23 |
-
]
|
| 24 |
-
subprocess.run(cmd_split, check=True)
|
| 25 |
-
outputs.append(output_file)
|
| 26 |
-
return outputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|