I would like to add the command I use to capture the screen:
ffmpeg.exe -y ^
-vsync vfr ^
-f gdigrab ^
-indexmem 300M ^
-rtbufsize 1G ^
-probesize 7M ^
-max_probe_packets 50k ^
-draw_mouse 0 ^
-video_size 1280x720 ^
-offset_y 152 ^
-framerate 24 ^
-c:v bmp ^
-strict strict ^
-thread_queue_size 50k ^
-r 24 ^
-i desktop ^
-f dshow ^
-channel_layout stereo ^
-thread_queue_size 50k ^
-strict strict ^
-i "audio=Stereo-mix (Realtek High Definition Audio)" ^
-map 0:v ^
-max_muxing_queue_size 50k ^
-f mp4 ^
-movflags +faststart ^
-max_interleave_delta 0 ^
-c:v libx264 ^
-r 24 ^
-preset fast ^
-tune film ^
-strict strict ^
-crf 25 ^
-pix_fmt yuv422p ^
-map 1:a ^
-max_muxing_queue_size 50k ^
-max_interleave_delta 0 ^
-c:a aac ^
-strict strict ^
-ac 2 ^
screencapture.mp4
The value of probesize appears to have much influence on the audio/video synchronisation. Raising the value by a few megabytes may cause A/V out of sync. Change by 1M or 500k, e.g. to 7500k, at a time.
If you leave out the probesize option, ffmpeg will, by default, set the probesize to 5M.
max_interleave_delta option prevents ffmpeg forcing output. If ffmpeg forces output, a message will appear in your log, e.g.:
[mp4 @ 00000199f7512040] Delay between the first packet and last packet in the muxing queue is 10007271 > 10000000: forcing output
If ffmpeg takes to much processor time, try changing the -preset option (ultrafast, superfast, veryfast, faster, fast, medium (default), slow, slower, veryslow), larger -crf (constant rate factor), e.g. 32 or lower framerate (-framerate and -r options on several places in the command).