I used to use TimeSnapper for that. The classic version is free.
It did use a crapload of disk space though (20GB per week?), and most of the data is almost identical, so I started designing an algorithm to store only the differences between images before realizing I had reinvented video codecs... so I just made a ffmpeg one liner to convert the image sequences to mp4 :)
You can capture straight from the GPU into the GPU's video encoder and directly get h265 frames efficiently without laundering the whole framebuffer through system RAM each time.
Nvenc is actually quite nice and easy to use for that, but if you want to do any serious post processing you'll need to parse h265 (headers at least) and it's not the easiest parser to write.
On Windows, there's an API to capture the display as a DX texture. Then either use NVENC or AMF to encode. You'll get compressed frames that you can just stuff straight into whichever video container you like.
It did use a crapload of disk space though (20GB per week?), and most of the data is almost identical, so I started designing an algorithm to store only the differences between images before realizing I had reinvented video codecs... so I just made a ffmpeg one liner to convert the image sequences to mp4 :)