-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut_video.py
47 lines (35 loc) · 1.02 KB
/
cut_video.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
42
43
44
45
46
47
#!/usr/bin/env python3
import sys
import argparse
from os import path
import ffmpeg
from datetime import datetime
TIME_FORMAT = "%H:%M:%S"
def time(input: str):
datetime.strptime(input, TIME_FORMAT)
return input
def main():
parser = argparse.ArgumentParser()
parser.add_argument("filename", type=str)
parser.add_argument("--start", type=time, default="00:00:00")
parser.add_argument("--end", type=time, default="23:59:59")
parser.add_argument("--name", type=str)
parser.add_argument(
"--dry-run",
help="simulate actions without touching filesystem",
action="store_true",
)
args = parser.parse_args()
(name, ext) = path.splitext(args.filename)
out = args.name if args.name else f"{name}-cut{ext}"
cmd = ffmpeg.input(args.filename, ss=args.start, to=args.end).output(
out,
acodec="copy",
vcodec="copy",
)
print(" ".join(cmd.compile()))
if args.dry_run:
sys.exit(0)
cmd.run()
if __name__ == "__main__":
main()