if you don't mind setting up a bit, OBS actually also have a replay buffer feature to do that. It's a good software to have even if you are not streaming because of the virtual camera feature that let you share screen with very deep customization too.