TIL that most video processing tools accept as a valid input stream a set of concatenated PPM [1] files, so you can generate video from your own programs easily. You just have to pipe your program's output to the appropriate tools (indicating the FPS) like
./fancy-prg | mpv --no-correct-pts --fps=$FPS -
or
./fancy-prg | ffmpeg -i - -r $FPS video.mp4
[1]
https://en.wikipedia.org/wiki/Netpbm_format