| 218 | customKeyDownCallbacks = {} # User callback is called when event.type == pygame.KEYDOWN and event.key == key |
| 219 | |
| 220 | class Recorder: |
| 221 | def __init__(self, recordPath, resolution): |
| 222 | import subprocess |
| 223 | |
| 224 | os.makedirs(os.path.dirname(recordPath), exist_ok=True) |
| 225 | if os.name == 'nt': |
| 226 | ffmpegStdErrToNull = "2>NUL" |
| 227 | else: |
| 228 | ffmpegStdErrToNull = "2>/dev/null" |
| 229 | |
| 230 | self.resolution = resolution |
| 231 | cmd = "ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s {}x{} -i - -an -pix_fmt yuv420p -c:v libx264 -vf vflip -crf 17 \"{}\" {}".format( |
| 232 | resolution[0], resolution[1], recordPath, ffmpegStdErrToNull) |
| 233 | self.recordPipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True) |
| 234 | |
| 235 | def recordFrame(self): |
| 236 | buffer = glReadPixels(0, 0, self.resolution[0], self.resolution[1], GL_RGB, GL_UNSIGNED_BYTE) |
| 237 | self.recordPipe.stdin.write(buffer) |
| 238 | |
| 239 | class Visualizer: |
| 240 | def __init__(self, args=VisualizerArgs()): |