I have a handful of MKV videos which claim to be a few seconds longer than they actually are. When played in VLC, they simply stop abruptly when they get to the actual end of the video. This would be fine if I were not trying to include them in a larger video concatenated from these smaller videos. When watching the compilation in VLC, it manifests as a sort of hiccup where it abruptly stops, pauses, and then the time skips forward multiple seconds. It's tolerable, but not ideal.
I'm concatenating the videos using mkvtoolnix, which reports that each MKV contains one AVC/H.264/MPEG-4p10 video track, multiple AC-3 audio tracks, and an HDMV PGS subtitle track. I'd like to preserve all of these when fixing the video length. When I open the MKV in avidemux, I see the correct, shorter length. When I save it from avidemux, the output is also the correct length and the video and audio tracks are preserved. However, the subtitle track is lost. If I try to merge the original MKV and the avidemux-shortened MKV in mkvtoolnix, taking only the subtitle track from the original, the length gets messed up again.
I've tried telling mkvtoolnix to split after the actual end time, but it doesn't do it because it doesn't encounter another key frame on which to split. (Which makes sense, because there's no more real video or audio left.)
I've also tried telling mkvtoolnix to just leave out the subtitle track in the original MKV, purely for testing purposes. That didn't work either. So I assume it is not the only track with an incorrect length, at least in the original.
How can I achieve what I'm trying to do? I'm open to using other tools, like ffmpeg on the command line, but video editing is not really my area of expertise so I don't know what I'm looking for.
Thank you in advance.