"""Convert AE output to source frames and a stereo review movie; no runtime dependency.""" import argparse from pathlib import Path import shutil import subprocess import sys import wave ROOT=Path(__file__).resolve().parents[2] WORK=ROOT/'build/cinematic-v3' def main(): parser=argparse.ArgumentParser() parser.add_argument('--ffmpeg') parser.add_argument('--frames-ready',action='store_true') parser.add_argument('--refined-city',type=Path) args=parser.parse_args() encoder=args.ffmpeg or shutil.which('ffmpeg') if not encoder: sys.path.insert(0,str(ROOT/'build/scratch/video-tools')) from imageio_ffmpeg import get_ffmpeg_exe encoder=get_ffmpeg_exe() def run(options): subprocess.run([encoder,'-hide_banner','-loglevel','error','-y',*map(str,options)],check=True,cwd=ROOT) frames=WORK/'render' if not args.frames_ready: run(['-i',frames/'master-v3.mp4','-map','0:v:0','-fps_mode','passthrough',frames/'film_%05d.png']) if args.refined_city: run(['-i',args.refined_city,'-map','0:v:0','-fps_mode','passthrough','-start_number',241,frames/'film_%05d.png']) assert len(list(frames.glob('film_*.png')))==600,'Expected 600 AE frames' audio=WORK/'master-audio.wav' with wave.open(str(audio),'wb') as target: target.setparams((2,2,22050,0,'NONE','not compressed')) for name in ['studio-ident.wav','casino-title.wav']: with wave.open(str(ROOT/'assets/audio/startup'/name),'rb') as source: assert (source.getnchannels(),source.getsampwidth(),source.getframerate())==(2,2,22050) target.writeframes(source.readframes(source.getnframes())) output=WORK/'cinematic-v3-preview.mp4' run(['-framerate',30,'-start_number',1,'-i',frames/'film_%05d.png','-i',audio, '-c:v','libx264','-preset','medium','-crf',17,'-pix_fmt','yuv420p', '-c:a','aac','-b:a','160k','-movflags','+faststart','-shortest',output]) print('Exported 20 seconds / 600 AE frames / stereo:',output) if __name__=='__main__': main()