-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeanim.py
47 lines (33 loc) · 945 Bytes
/
makeanim.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
import os
import shutil
import subprocess
from multiprocessing.pool import ThreadPool
BASE_PATH = 'images'
TEMP_PATH = 'C:/temp/temp_gif'
THREADS = os.cpu_count()
COPY_ONSTART = False
DELETE_ATEXIT = False
def extractor(v: str):
v = v[:-4]
if '/' in v:
v = v[v.rindex('/'):]
p = v.split('_')
return int(p[5]) * 1000000000 + int(p[7])
def copy(f):
print(f[1])
shutil.copy(f'{ BASE_PATH }/{ f[1] }', f'{ TEMP_PATH }/{ f[0] }.png')
files = [ f for f in os.listdir(BASE_PATH) if 'iter' in f ]
files.sort(key=extractor)
if COPY_ONSTART:
print('Copying files')
os.makedirs(TEMP_PATH, exist_ok=True)
with ThreadPool(THREADS) as pool:
pool.map(copy, enumerate(files))
print('Starting ffmpeg')
process = subprocess.Popen(f'ffmpeg -i "{ TEMP_PATH }/%d.png" out.mp4', shell=True, stdout=subprocess.PIPE)
for line in process.stdout:
print(line)
process.wait()
if DELETE_ATEXIT:
print('Deleting files')
shutil.rmtree(TEMP_PATH)