title: Audio/Video out of sync when recording
body: <p>I am recording the desktop with gdigrab and the audio with dshow, but they are out of sync.</p>
  
  <p>This is the first thing I tried, there was always about the same delay (about 20-30 frames): </p>
  
  <pre><code>// Command
  ffmpeg -f dshow -i audio="Microphone (NVIDIA RTX Voice)" -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -c:v h264 -preset ultrafast -qp 0 C:\Videos\test2.mp4
  
  // Bottom of debug log
  Input file #0 (audio=Microphone (NVIDIA RTX Voice)):
    Input stream #0:0 (audio): 15 packets read (1323000 bytes); 15 frames decoded (330750 samples);
    Total: 15 packets (1323000 bytes) demuxed
  Input file #1 (desktop):
    Input stream #1:0 (video): 223 packets read (1849663242 bytes); 223 frames decoded;
    Total: 223 packets (1849663242 bytes) demuxed
  Output file #0 (C:\Videos\test2.mp4):
    Output stream #0:0 (video): 243 frames encoded; 243 packets muxed (211227447 bytes);
    Output stream #0:1 (audio): 322 frames encoded (329728 samples); 323 packets muxed (120103 bytes);
    Total: 566 packets (211347550 bytes) muxed
  238 frames successfully decoded, 0 decoding errors
  [AVIOContext @ 0000028163c9c040] Statistics: 2 seeks, 810 writeouts
  </code></pre>
  
  <p>The second thing I tried I believe fixed the audio sync issue, but I can really tell because it made the recording very laggy:</p>
  
  <pre><code>// Command
  ffmpeg -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -f dshow -i audio="Microphone (NVIDIA RTX Voice)" -c:v h264 -preset ultrafast -qp 0 C:\Videos\test2.mp4
  
  // Bottom of debug log
  Input file #0 (desktop):
    Input stream #0:0 (video): 112 packets read (928978848 bytes); 112 frames decoded;
    Total: 112 packets (928978848 bytes) demuxed
  Input file #1 (audio=Microphone (NVIDIA RTX Voice)):
    Input stream #1:0 (audio): 12 packets read (1058400 bytes); 12 frames decoded (264600 samples);
    Total: 12 packets (1058400 bytes) demuxed
  Output file #0 (C:\Videos\test2.mp4):
    Output stream #0:0 (video): 388 frames encoded; 388 packets muxed (109408287 bytes);
    Output stream #0:1 (audio): 258 frames encoded (264192 samples); 259 packets muxed (96404 bytes);
    Total: 647 packets (109504691 bytes) muxed
  124 frames successfully decoded, 0 decoding errors
  [AVIOContext @ 0000019da713c040] Statistics: 2 seeks, 421 writeouts
  </code></pre>
  
  <p>How can I sync the audio and video?</p>
  
  <p>It turns out it is only the microphone that has the delay, I tried using <code>virtual-audio-capturer</code> device and the audio synced perfectly, but that is only the desktop audio and not the mic.</p>