If you need to record your game from the editor to the highest resolution and framerate possible, you can use the Unity Recorder, that is available in the Package Manager. Just search for “Unity Recorder” and click Install, then select Window > General > Recorder > Recorder Window, set your output resolution and framerate, then select the path to the file, and Unity will record everything that is happening. If your FPS drops during the recording, don’t worry, because it the drop won’t be present in the resulting recording.
If you need to record your game from the player (when it has already been built to an APK/EXE/whatever and is not running under the Unity Editor), then you can try saving everything that is being rendered by using the OnRenderImage method, then append that image to an MP4 file using FFmpeg. This has already been done for you: GitHub - keijiro/FFmpegOut: Video capture plugin for Unity with FFmpeg.
You can still attempt to make your own recorder, you just need to find an FFmpeg port to Unity, and you would be good to go.
Please note that FFmpeg is licenced under GPL/LGPL!