-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
split.py
41 lines (33 loc) · 1.05 KB
/
split.py
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
from __future__ import annotations
import argparse
import subprocess
import time
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('times_file')
parser.add_argument('video_file')
args = parser.parse_args()
with open(args.times_file) as f:
lines = [line.strip() for line in f]
for i, line in enumerate(lines, 1):
print(f'doing {i}/{len(lines)}', flush=True)
p1, _, p2 = line.split()
t0 = time.time()
subprocess.check_call(
(
'ffmpeg',
'-hwaccel', 'cuda', '-hwaccel_output_format', 'cuda',
'-ss', p1,
'-to', p2,
'-i', args.video_file,
'-preset', 'slow',
'-c:v', 'hevc_nvenc',
f'{i:02}_clip.mov',
),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
print(f'cut from {p1} to {p2} in {time.time()-t0:.2f}s', flush=True)
return 0
if __name__ == '__main__':
raise SystemExit(main())