Exporting the whole image to the compressed file may be quite a performance heavy thing. Before you start, you can check out this trick that allows to prepare krita for recording with external program (basically creating new krita window with fullscreen canvas that isn’t moved or rotated while you draw).
There is also a discussion there about this WIP plugin for recording inside krita. Maybe this code could be useful to you, or you would like to help there instead of doing it all on your own ![]()