Corrupted .mp4's After Tagging

I've been running into this same problem for a long time now. I do a lot of encoding from .mkv to .mp4 (mostly hardcoding of subtitles, for compatibility for mobile devices). However, when I try to tag these .mp4 files, I will sometimes get a "hole" in the video. I can confirm that the files were fine prior to tagging. The oddest thing is that the corrupting is random; some files are fine, some aren't. For now, for any videos I encode, I copy the file prior to tagging, tag one of them, and if I find that that file has been corrupted as I'm watching it, I make a new copy of the untagged file and tag it (this usually results in the file being fine). I have no idea why tagging an .mp4 would result in it being corrupted. It should also be noted that this doesn't apply to all .mp4's I've tried; I've downloaded hundreds of .mp4's from YouTube and tagged them the exact same way, and I've never had a single problem with any of them.

If a way to stop this from happening or repair the files is impossible, I'd settle for a procedural way to check to see if the files are corrupted, since the only way I currently have is to watch them. I have an example of the corrupted files here:

Untagged, fine:

Tagged, glitched at about 17 minutes:

If you want to see this for yourself, I had a HELL of a time (moreso than usual) when trying to tag TV-Nihon's release of Kamen Rider OOO (which are .mp4's that I tried to tag straight as opposed to encoding first). 4 times out of 5, they'd be corrupted after tagging.

EDIT: I seem to have found a way to tell if a file is corrupted. If I take my tagged files and run just the audio through my encoder (which is very, very quick), jump to the end of that file, and if the audio there is glitched, then there's a glitch in the video itself. So I should be able to avoid glitches while I'm watching. However, I would still very much like to get some insight on how they get corrupted in the first place and how to prevent it from happening in the future.

I've read elsewhere that tagging video files can be problematic, leading to some videos becoming unplayable, and that it's dependent on the audio stream used.

If an Mp4 isn't using an AAC audio stream it's been suggested that ffmpeg should be used for appropriate tagging, but others here may chime in with more info about it.

You can check what audio format a video is encoded with by using tools like MediaInfo, or a video player like PotPlayer (by pressing the Tab key while a video is playing).

I always encode to AAC audio. And I usually use the FFmpegSource2 decoder for the video stream, although DirectShowSource2 is sometimes necessary; both can still result in errors (unless that's not what you're asking about, in which case, ignore me).