Are you following this sample? Tutorial: Using the Sink Writer to Encode Video, just rtStart += rtDuration is wrong. You cannot capture and write screen exactly at this time.
So the solution is using IMFPresentationClock to handle the correct WriteSample time.
https://github.com/tomrsae/Windows-Screen-Recorder/blob/master/Screen%20Recorder/MP4File.h