-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimPro.py
More file actions
58 lines (57 loc) · 2.13 KB
/
AnimPro.py
File metadata and controls
58 lines (57 loc) · 2.13 KB
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
57
58
from svgwrite import Drawing
from Operations import Animate
from Objects import *
from tqdm import tqdm
from subprocess import Popen,call
from os import system
from tempfile import gettempdir
tempdir = gettempdir()
system(' '.join(('cd',tempdir,'&& IF NOT EXIST animpro_temp mkdir animpro_temp')))
tempdir+="\\animpro_temp\\"
def genScreen(max_h,max_w,background):
screen= Drawing(
"",
size=(str(max_h)+'px',str(max_w)+'px'),
viewBox="0 0 {0} {1}".format(max_h,max_w)
)
screen.add(screen.rect(insert=(0,0),size=(max_h,max_w),id="background"))
screen.defs.add(screen.style("backgorund{fill: "+background+";}"))
return screen
def saveframes(screen,frames,framepos):
cframepos=0
for objs in zip(*frames):
cframepos+=1
framepos+=1
screen.elements+=objs
screen.saveas(tempdir+"frame{0}.svg".format(framepos))
for f in objs:
screen.elements.remove(f)
return framepos
class Scene:
def __init__(self,max_h,max_w,background="black"):
self.screen = genScreen(max_h,max_w,background)
self.framepos = 0
def render(self,*frames):
frames = [combineGen(objs) if isinstance(objs, tuple) else objs for objs in frames]
self.framepos = saveframes(self.screen,frames,self.framepos)
def render_video(self,filename):
print('Creating TIF Files')
converts = [(i,f'sconvert {tempdir}frame{i}.svg {tempdir}frame{i}.tif') for i in range(1,self.framepos+1)]
previous = []
for l,program in tqdm(converts):
previous.append(Popen(program))
if l%4==0:
for p in previous:
p.wait()
previous = []
for p in previous:
p.wait()
print('Converting TIF files into',filename)
call([
'ffmpeg','-hide_banner','-loglevel','error',
'-y','-start_number','1','-i',
tempdir+'frame%d.tif','-r',
'60','-b:v','5000k',filename
])
system(' '.join(('cd',tempdir,'&&','del','/Q','*')))
print('Opening',filename)