import subprocess,sys,os,time,pathlib,signal
root=pathlib.Path(sys.argv[1]);side=sys.argv[2]
video=root/(side+'-screen.mp4')
f=subprocess.Popen(['ffmpeg','-y','-loglevel','error','-f','x11grab','-video_size','1920x1080','-framerate','10','-i',os.environ['DISPLAY'],'-c:v','libx264','-preset','ultrafast','-pix_fmt','yuv420p',str(video)],stdin=subprocess.PIPE)
try:
    subprocess.run(['gnome-terminal','--wait','--geometry=140x38','--hide-menubar','--zoom=1.5','--title','T3 Code AppImage shutdown proof','--','python3',str(root/'driver.py'),*sys.argv[1:]],check=True)
finally:
    f.communicate(b'q\n',timeout=20)
print(video)
