-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp4.py
56 lines (48 loc) · 1.32 KB
/
mp4.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
48
49
50
51
52
53
54
55
56
import glob
import subprocess
import os
def copy_to_mp4(in_path: str, out_path: str, audio_track=None):
args = ["ffmpeg.exe", "-i", in_path]
if audio_track is not None:
args.extend(
[
"-map",
"0:v:0",
"-map",
"0:a:{}".format(audio_track),
]
)
args.extend(
[
"-vcodec",
"copy",
"-acodec",
"copy",
out_path,
]
)
print("Copying video '{}' to '{}'".format(in_path, out_path))
print("Running {}".format(args))
subprocess.check_call(args)
print("Process finished\n")
def cli(
vids_glob: str,
skip_existing: bool = True,
simple_glob: bool = True,
audio_track=None,
):
if simple_glob:
vids_glob = "*".join(map(glob.escape, vids_glob.split("*")))
print(vids_glob)
vids_paths = glob.glob(vids_glob)
print(vids_paths)
for path in vids_paths:
out_path = f"{os.path.splitext(os.path.basename(path))[0]}.mp4"
if not (skip_existing and os.path.exists(out_path)):
copy_to_mp4(path, out_path, audio_track)
else:
print(f"{out_path} already exists, skipping")
print("Finished successfully :)")
if __name__ == "__main__":
import fire
fire.Fire(cli)