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