tangled
alpha
login
or
join now
tilde.link
/
tm
0
fork
atom
TrackMania old videos archive
tm.tilde.link
0
fork
atom
overview
issues
pulls
pipelines
encode
tilde.link
3 years ago
8027fce0
cbf25abf
+48
1 changed file
expand all
collapse all
unified
split
encode.py
+48
encode.py
···
1
1
+
#! /usr/bin/env python3
2
2
+
3
3
+
import os
4
4
+
import subprocess
5
5
+
6
6
+
7
7
+
def encode(input_file, output_file):
8
8
+
output_directory = os.path.dirname(output_file)
9
9
+
os.makedirs(output_directory, exist_ok=True)
10
10
+
if not os.path.exists(output_file):
11
11
+
subprocess.call([
12
12
+
'ffmpeg',
13
13
+
'-i', input_file,
14
14
+
'-codec:a', 'libopus',
15
15
+
'-codec:v', 'libx264',
16
16
+
'-preset', 'veryslow',
17
17
+
'-qp', '23',
18
18
+
'-movflags', '+faststart',
19
19
+
'-pix_fmt', 'yuv420p',
20
20
+
output_file
21
21
+
])
22
22
+
23
23
+
24
24
+
def main():
25
25
+
file = os.path.realpath(__file__)
26
26
+
root = os.path.dirname(file)
27
27
+
raw_root = os.path.join(root, 'raw')
28
28
+
web_root = os.path.join(root, 'web')
29
29
+
print(f'← {raw_root}')
30
30
+
print(f'→ {web_root}')
31
31
+
tasks = []
32
32
+
for directory, directories, files in os.walk(raw_root):
33
33
+
for file in files:
34
34
+
relative_directory = os.path.relpath(directory, raw_root)
35
35
+
name, ext = os.path.splitext(file)
36
36
+
relative_name = os.path.join(relative_directory, name)
37
37
+
tasks.append((relative_name, ext))
38
38
+
for relative_name, ext in sorted(tasks):
39
39
+
raw_file = os.path.join(raw_root, f'{relative_name}{ext}')
40
40
+
web_file = os.path.join(web_root, f'{relative_name}.mp4')
41
41
+
print()
42
42
+
print(f'← {raw_file}')
43
43
+
print(f'→ {web_file}')
44
44
+
encode(raw_file, web_file)
45
45
+
46
46
+
47
47
+
if __name__ == '__main__':
48
48
+
main()