Untrunc is a piece of software which can rebuild the information required to make MP4 files work based on the information stored in another video from the same source. It is available as a piece of software you can compile, or as a free web service. I imagine the website will be easier for most people, but in my case, I just compiled the software and ran it on my own machine, so I can't vouch for the site. However you do it, this is the software you need to use.
The website is self-explanatory, and the software is very simple, but it needs to be compiled and run in the command line, so it may be too complicated for some people.
It also doesn't appear to run on Windows, so you'll need a Linux or Mac machine if you want to use the software on your own computer.
Find the file you want to fix, and then another video from the same source. If this was a physical medium like a camera, choose a video that has the same resolution and settings from the same camera.
If it's from a recording software like OBS, follow the same procedure and find a file with the same resolution and as many similarities as possible.
In both cases, choosing a video with similar length is recommended.
This is the part where you hope you're in luck. In both of the cases I tried this, it was successful and recovered everything. The first was a livestream
I recorded with youtube-dl that was killed before finishing the MP4 file it was building. In that
case, the reference video I used was a piece of the stream built out of the last available stream segments that were still hanging around. The size
difference was very significant: ~5 seconds of sample vs. over 2 hours of stream to recover, but it worked nonetheless. The other video I recovered
was a recording I did with OBS in 2018 that I kept around in case I found a solution to fix it. I'm glad I did! I used an OBS recording from around the
same time, which was still much shorter than the corrupt recording, but it also worked. It's also worth noting that this file was in the MOV container,
which is a little different from MP4, but uses the same underlying codec (MPEG-4). Here's some more information on QuickTime (MOV)
files from Mozilla MDN.