Record audio and video simultaneously

hi guys, is there a way to record audio and video simultaneously?

I ask because when I go to recompose a video adding the audio afterwards I always have problems with synchronization.

I created a class that performs this task in deferred time and there I have no problems, only that some sketches can not change them for the delayed time because they are based precisely on the time between frames and then I need to record audio and video in real time.