Ffmpeg error: 2nd pass has more frames than 1st pass I'm recording video in windows 10 with gdigrab so want the capture as fast as possible in pass 1 and encode to a smaller file in pass 2.  No matter what I do I always get this error when executing pass 2:


  [libx264 @ 000000000084ca60] 2nd pass has more frames than 1st pass
  (460) 
  
  [libx264 @ 000000000084ca60] continuing anyway, at constant QP=4


Pass 1 command:
    ffmpeg -y -rtbufsize 1500M  -f gdigrab -framerate 29.97 -draw_mouse 0 -offset_x 224 -offset_y 232 -video_size 1280x720 -i desktop -pix_fmt yuv420p -c:v libx264 -r 29.97 -pass 1 -an -tune zerolatency -preset ultrafast -b:v 2600k -crf 0 -f mp4 NUL

Pass 2 command:
    ffmpeg -y -rtbufsize 1500M  -f gdigrab -framerate 29.97 -draw_mouse 0 -offset_x 224 -offset_y 232 -video_size 1280x720  -i desktop -pix_fmt yuv420p -c:v libx264 -r 29.97 -pass 2 -an -tune zerolatency -preset ultrafast -b:v 2600k -crf 22 C:/myVideo.mp4


I've tried setting -crf to 0 on the second pass but always get the same error.  Also the video that does get written by the second pass just has the first frame of the first pass. 
EDIT:  Also tried adding -passlogfile to no avail.

What am I doing wrong?
Two-pass is meant for when you have a fixed input and you wish to analyze the file beforehand, so that the encode is optimized for the target bitrate and other encoder parameters.

Your 1st command is discarding the capture. And so your 2nd command is using the stats from pass 1 to apply to a new capture, which obviously won't match.

Use

ffmpeg -y -rtbufsize 1500M -f gdigrab -framerate 30000/1001 -draw_mouse 0 -offset_x 224 -offset_y 232 -video_size 1280x720 -i desktop -c:v libx264 -r 30000/1001 -an -tune zerolatency -preset ultrafast -crf 0 Capture.mp4


and then

ffmpeg -y -i Capture.mp4 -pix_fmt yuv420p -c:v libx264 -pass 1 -an -b:v 2600k -f mp4 NUL

ffmpeg -y -i Capture.mp4 -pix_fmt yuv420p -c:v libx264 -pass 2 -an -b:v 2600k myVideo.mp4