I often find myself needing to crop out sections from .TS files (such as commercials). I do this using DGIndexNV by selecting the section I want to keep and selecting "output trimmed TS." This usually results in approx 5 new .TS segments. Then I use DGIndex (NOT the NV one) to index each of those and extract the audio, which lists a DELAY in the file name. After I've reencoded the 5 videos to a lower bitrate and removed interlacing, etc. (output is a raw .264), I need to append them and the audio together into a .MKV. I found that adding video1 and audio1, then appending video2+audio2, video3+audio3, etc. in mkvmerge doesn't allow for proper audio sync, even when I've made sure the DELAY is being used. However, if I merge each segment separately into .MKVs, THEN append those MKVs into a single one, it all works out. Except...

During the transition from one segment to another, the video from the first segment speeds up while the audio remains at a normal rate, then the second segment starts and everything is fine. This happens in between each segment, even though this is now in one file (I still know the timecodes where the original file breaks were). If I then use MKVExtract to demux the full .MKV into its .264 + .ac3 files (only one of each now- no more segments), and then remux them into an MKV, the audio sync has been lost after where the first segment would be. How do I fix this?

I'm really only interested in using free tools, especially ones that can also be run using a CLI