Access detailed configuration for the x264vfw - H.264/MPEG-4 codec in Export Animation> Resolution tab> Codec. Change to x264vfw codec then click Configure.
Use the following settings to achieve desired results or adjust per your need:
Zero Latency makes video creation smooth but might slightly increase export time.
Virtual Dub Hack prevents loosing some frames, especially at the beginning of the video (it happens sometimes, when video is not buffered properly before encoding, on computers with a slower graphics cards).
Set Rate Control to Single pass / lossless to ensure but the best quality of encoding but file size is slightly larger.
Example settings from user 1:
Example settings from user 2: