I keep seeing everybody say "record in MKV so you don't lose footage" every time someone posts about the "stopping recording..." bug (that still to this day exists for some reason) but that's just not true. I ALWAYS lose HOURS of footage after this.
"Stopping recording..." is no bug. It's the symptom of some other issue, and this is the file write not being able to write a complete group of pictures (GOP). With h.264-encoded material, frames are grouped for compression purposes. In short, frames within a group might refer to picture data of some frame at the end of the group, if the encoder decides this gets good compression.
So the file write module never stops writing immediately, instead it waits for the current group to finish, then stops writing. Otherwise the end of the video would look corrupted or would be missing. For a normal 30 or 60 fps video, this waiting time is perceived as instantly.
As long as the encoder isn't outputting any frame, the file writer waits.
This can happen if the encoder is overloaded and unable to encode frames in time. Worst case is if the encoder aborts encoding some frame, because it gets too many new frames to encode. Then it starts to encode the new frame, but also takes too long, and need to abort this, and so on. In the end, the encoder outputs nothing or only one frame every few seconds - this is the slide show some people get as video.
It's also possible in this situation the encoder forgets about the group of pictures it started some time ago and cannot finish that group. Starting at this moment, nothing is written to the file any more, and if you stop recording, it is stopping indefinitely, because the encoder isn't able to deliver frames to complete the group.
Symptoms for this situation is an extraordinarily high number of frames lost due to rendering and encoding lag (80%+) in the logfile. And the situation that only the first few seconds or minutes are in the file, regardless how long the recording should be. The first seconds/minutes are in the file, because despite encoder overload, frames to encode are queued, but if the buffer for the queue gets full due to severe encoder overload, the frames are thrown away and the encoding is broken from then on.
So aim for a resolution and fps where you get no lost frames due to encoding or rendering lag. Watch out for the "encoder is overloaded" message in the OBS window (it must not appear), and watch for the frames missed and skipped in the stats window of OBS: they should remain at 0 or at at least at a very low value - below 1%)
Single lost frames are often unavoidable, but more than 1% lost frames are an indication the settings are too demanding for the machine.