Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
MKVToolNix
MKVToolNix
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 29
    • Issues 29
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 2
    • Merge Requests 2
  • Requirements
    • Requirements
    • List
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • Moritz Bunkus
  • MKVToolNixMKVToolNix
  • Wiki
  • Stretch or shrink audio tracks

Last edited by remuxer32 Sep 17, 2017
Page history

Stretch or shrink audio tracks

How can I stretch or shrink an audio track?

The problem

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:

  1. Use mkvmerge's --sync option or MKVToolNix GUI'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, 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. 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

Clone repository
  • About track UIDs, track numbers and track IDs
  • Adding files vs. Appending files vs. adding as additional parts
  • All tracks vanished after mkvpropedit, the header or chapter editors
  • Appending & splitting FLAC audio tracks not supported
  • Automation examples
  • Batch muxing with the GUI
  • Characters (e.g. Umlauts) aren't shown correctly
  • Chinese not selectable as language
  • Crash when adding attachments
  • Creating byte identical files
  • Cropping ignored
  • DLLs not found
  • Debugging GUI startup problems
  • Default and forced flags and default yes no in the GUI
  • Delay not shown in the GUI
View All Pages