How can I stretch or shrink an audio track?
First of all: don't. If you can avoid it, do not do it. Instead apply the opposite to the video and subtitle tracks present.
mkvmerge's stretch function can be used for stretching or shrinking the length of a track. This works by adjusting the timestamps of said track by a formula: adding/subtracting a fixed value and/or multiplying by a factor. This effectively tells the player to play that track slower/faster than originally intended.
What this does not do, though, is modify the samples themselves. mkvmerge is not an audio resampler.
So why not apply this to audio tracks?
Each audio track has a set sampling frequency noted in the track headers. This tells the playback hardware how many distinct samples it should expect and play per second. You cannot simply deliver a lot more or a lot less samples in a second because the audio hardware will still play each sample at a fixed duration of
1/sampling_frequency. If the player delivers more samples, it will simply have to wait until the audio hardware has caught up, or buffer overruns will occur and samples will be dropped. Similar situation with fewer samples than the sampling frequency.
The same does not apply to video tracks that much simply because they have such a low sampling frequency: the number of frames per second (e.g. compare 25 samples for a video track to 48000 samples for an audio track). Hardware already expects video frames to appear at not-so-fixed intervals, and variable video frame rate has never been a problem either.
It's even simpler for subtitle tracks as they don't even have a set sampling frequency. Their frames occur when they do, and are therefore unproblematic regarding changing their timestamps.
If you really want to
If you really want to strech or shorten an audio track, you have two options:
--syncoption or MKVToolNix GUI's corresponding controls
stretch by. For example, if your movie is 2h long and your audio track with the track ID 1 is too short by 30s, you can stretch it by the factor
movie_length / audio_lengthor the equivalent
movie_length / (movie_length - audio_too_short). For our example you could use
Use a proper audio processing application like e.g. Audacity. Such applications can stretch the audio track by inserting new samples in between the old ones (or leave some out in case of shrinking). This is the safer bet, even though it degrades audio quality a bit.