In “Windows won't let you own Win+Shift+S. So I hooked the keyboard in Python.”, Akhouri Anmol Kumar (@akhourianmolkumar) describes building a Windows screen recorder that saves microphone and system playback to separate WAV files before mixing them. The article is at https://dev.to/akhourianmolkumar/windows-wont-let-you-own-winshifts-so-i-hooked-the-keyboard-in-python-248c.
Capture playback and narration separately
Kumar used sounddevice for the microphone and PyAudioWPatch for system playback. These sources answer different questions about a recording. The microphone captures the speaker in the room. WASAPI loopback captures what Windows plays through a rendering endpoint, which means the audio output selected for capture matters. Microsoft describes this distinction in its loopback recording documentation at https://learn.microsoft.com/en-us/windows/win32/coreaudio/loopback-recording.
Keeping a WAV for each input also gives the developer something concrete to inspect. In a hypothetical screen capture of a demo, the narration might sound continuous while a notification recorded from system playback cuts off. Listening to the two files before mixing helps locate where the problem first appears. Once the sounds have been mixed, diagnosing a gap means working with the combined result.
Match the track lengths before the mix
Kumar says the implementation pads or trims each track to the video duration, then mixes with FFmpeg's amix filter. The two inputs can stop at slightly different times. The FFmpeg filter reference describes amix as combining multiple audio inputs into a single output, with a duration option that controls when the output ends. https://ffmpeg.org/ffmpeg-filters.html#amix
Matching the endpoint and checking synchronization are two distinct tasks. Consider a test capture with an audible cue near both the start and end. The first cue helps check the starting alignment. The second helps reveal accumulated timing differences. Padding the end of a short track gives it the intended length while preserving the position of samples already recorded. In the author's design, the separate WAV files are available for that check before they are combined with the video.