diff --git a/Stretch-or-shrink-audio-tracks.md b/Stretch-or-shrink-audio-tracks.md new file mode 100644 index 0000000..b921803 --- /dev/null +++ b/Stretch-or-shrink-audio-tracks.md @@ -0,0 +1,26 @@ +# How can I stretch or shrink an audio track? + +## The problem + +First of all: don't. If you can avoid it then 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 then 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: + +1. Use mkvmerge's `--sync` option or mmg's corresponding controls `delay` and `stretch by`. For example, if your movie is 2h long and your audio track with the track ID 1 is too short by 30s then you can stretch it by the factor `movie_length / audio_length` or the equivalent `movie_length / (movie_length - audio_too_short)`. For our example you could use `--sync 1:7200/7170`. +2. Use a proper audio processing application like e.g. [Audacity](http://audacity.sourceforge.net/). 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. + +Categories: [merging](Category-merging)