30 lines
826 B
Python
30 lines
826 B
Python
![]() |
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']);
|