first commit
This commit is contained in:
commit
9e4d936a96
9 changed files with 4864 additions and 0 deletions
30
make_animation.py
Normal file
30
make_animation.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import base64
|
||||
from pathlib import Path
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
fps = 5
|
||||
|
||||
infile = Path(sys.argv[1])
|
||||
|
||||
with open(infile) as f:
|
||||
data = json.load(f)
|
||||
|
||||
fps = data['fps']
|
||||
duration = data['duration']
|
||||
frames = data['frames']
|
||||
|
||||
print(len(frames))
|
||||
for i,frame in enumerate(frames):
|
||||
print(i)
|
||||
pngdir = Path('pngs')
|
||||
pngdir.mkdir(exist_ok=True)
|
||||
filename = Path(f'frame-{i:04d}.png')
|
||||
pngname = pngdir / filename
|
||||
with open(pngname, 'wb') as f:
|
||||
png = base64.b64decode(frame[len('data:image/png;base64,'):])
|
||||
f.write(png)
|
||||
|
||||
outfile = Path(infile.name).with_suffix('.mp4')
|
||||
subprocess.run(['ffmpeg','-r',str(fps),'-f','image2','-i','pngs/frame-%04d.png','-vcodec','libx264','-crf','25','-pix_fmt','yuv420p','-vf','pad=ceil(iw/2)*2:ceil(ih/2)*2',outfile,'-y']);
|
Loading…
Add table
Add a link
Reference in a new issue