Jump to content

Welcome to AnimePassion
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

Guide for time stretching audiotracks in MKV(whole track/partial)


  • Please log in to reply
11 replies to this topic

#1
szfzafa

szfzafa

    Meitantei

  • Members
  • 235 posts
  • 333 thanks
  • Local time: 05:44 AM
*EDIT* I was asking for help but later on I found the answer on my own. So I changed the topic title to a guidance, hope it's helpful to someone.

Click here to see how it works:
Guide for time stretching audiotracks in MKV(whole track)
Guide for time stretching audiotracks in MKV(partial, just a part, like an insert song or sth.)
======
Below's my original start thread:
======
Let's say I've got a movie and several audio tracks in different languages.

The French and German audio tracks (as well as the corresponding video and subtitles, from R2 PAL DVD) are shorter and faster than the English/Japanese by a factor of 23.97/25. With mkvmerge, I can easily timestretch the whole French and German AC3 tracks and subs with a factor of 25/23.97 (or 25025/24000, to be exact), and the result is fine and stable. When switched to French/German audio, video seems to play faster and audio is in sync, no stutters at all. :whistle:

The movie can be divided into 3 parts: main + ED song&staff + Ending slides.
Originally the ED song in movie is a short ver. which lasts 3 minutes. But another audio track is a very nice fandub and they even had the ED song fandubbed in full-length, lasting >5 minutes. (In their video they had their fan staff shown after the official staff)
The fandub audio is in sync with movie in the main part, then the ED song lasts 2 more minutes, causing a delay to Ending slides audio.

So the problem is that, is it possible to time stretch just the ED song part of the fandub audio?
I've tried splitting the fandub audio into 3 parts and append, timestretching only the ED song part, but no luck:
The last frame of the main movie would seem to last over a minute, then the ED staff video'd play almost normal, not as slow as it's supposed to be, then the Ending slides video'd finish even before the ED song audio ends...oh man, what should I do? :help:

Edited by szfzafa, 11 August 2012 - 12:12 PM.

Magical Girls don't age, they just fade away
-- or have their heads bitten off

#2
JohnFlower

JohnFlower

    Magical Girl

  • VIP
  • 810 posts
  • 39 thanks
  • Local time: 10:44 AM
  • LocationNew Zealand
I would use something like Adobe Audition to quickly sort out the speeds. Might not be the best or fastest method, but its something I know that works.

EDIT:
You might also want to load it with Adobe Premiere so you can get the right frames and whatnot. You can edit the audio selection from what you've chosen in Premiere with Audition.

#3
szfzafa

szfzafa

    Meitantei

  • Members
  • 235 posts
  • 333 thanks
  • Local time: 05:44 AM
I don't want to be rude, but I just don't want to reencode the audio.
Magical Girls don't age, they just fade away
-- or have their heads bitten off

#4
Cman21

Cman21

    /)*(\ ^_^

  • Administrators
  • 2,442 posts
  • 259 thanks
  • Local time: 05:44 PM
when you split up the file into parts and stretched did you change the fps or use the stretch feature in mkvmerge?

#5
szfzafa

szfzafa

    Meitantei

  • Members
  • 235 posts
  • 333 thanks
  • Local time: 05:44 AM

when you split up the file into parts and stretched did you change the fps or use the stretch feature in mkvmerge?

I split only the fandub audio into 3 parts, and use the stretch feature on the 2nd part only. Then I remux the fandub audio to the video using append feature.
Magical Girls don't age, they just fade away
-- or have their heads bitten off

#6
Cman21

Cman21

    /)*(\ ^_^

  • Administrators
  • 2,442 posts
  • 259 thanks
  • Local time: 05:44 PM
but how did you stretch it? cuz if you used mkvmerge to stretch it that will get re-written when appeneding and it will be like normal. you really need to use something else like audacity to stretch that part and then append back.

#7
eccon

eccon

    エ コ ン

  • VIP
  • 273 posts
  • 12 thanks
  • Local time: 11:44 PM
  • LocationEurope
Audio has nothing to do with fps, it's the runtime that matters.

I would suggest you cut off the fandub ED and replace it with a regular one, since you surely don't want to hear music at >166% speed, or see the ending credits at <33% speed :no:
Hence, you have no choice but to re-encode, which isn't a bad thing at all when it's done properly and using Audacity is indeed a proper way to do it.

Alternatively, you could use eac3to.
All you need is the possition of the cut in X ms.
Open cmd, look for the eac3to.exe and then type:
eac3to.exe c:\"location\of\old\file".ac3 c:\"destination\of\new\file".ac3 -edit=0:00:00.000,-XXXXXXXXXXms


#8
szfzafa

szfzafa

    Meitantei

  • Members
  • 235 posts
  • 333 thanks
  • Local time: 05:44 AM
Sorry guys, I've got it all wrong.

"Audio has nothing to do with fps" eccon's right about that.

The problem is not time stretching on part of an audio track, actually it doesn't matter if it's partial or the whole, time stretching on audio tracks makes no sense.(just read this: http://forum.videohe...stretch-5-1-AC3)
Now I think, applying time stretch feature to an audio track in mkvmerge does not affect video/audio playback fps, perhaps it only changes the audio timecode. Even through your video/audio have "equivalent time length" and you can always seek any time accurately, the audio and video will be out of sync if you continue to play, and it's a linearly growing delay.

So, the problem should be that, is it possible to time stretch only some certain the audio tracks, not all the audio tracks?
How I wish one video stream/track can be played at different reference framerate in a MKV to adapt to audio tracks from various sources!!

*EDIT*:
I just read these:

TrackTimecodeScale

The TrackTimecodeScale is used align tracks that would otherwise be played at different speeds. An example of this would be if you have a film that was originally recorded at 24fps video. When playing this back through a PAL broadcasting system, it is standard to speed up the film to 25fps to match the 25fps display speed of the PAL broadcasting standard. However, when broadcasting the video through NTSC, it is typical to leave the film at its original speed. If you wanted to make a single file where there was one video stream, and an audio stream used from the PAL broadcast, as well as an audio stream used from the NTSC broadcast, you would have the problem that the PAL audio stream would be 1/24th faster than the NTSC audio stream, quickly leading to problems. It is possible to stretch out the PAL audio track and reencode it at a slower speed, however when dealing with lossy audio codecs, this often results in a loss of audio quality and/or larger file sizes.

This is the type of problem that TrackTimecodeScale was designed to fix. Using it, the video can be played back at a speed that will synch with either the NTSC or the PAL audio stream, depending on which is being used for playback.

from MKV Specification Notes, http://matroska.org/...pecs/notes.html

TrackTimecodeScale modifies only specific header parameter and not the whole timecodes. It doesn't require audio resampling. It's easy to recognize if this parameter was used. TrackTimecodeScale was designed for sync, it doesn't produce weird audio tracks and doesn't require to break spec compliance for proper playback. So the only problem is lack of support, which is partially caused by mkvmerge using some hack instead of this parameter.

from http://forum.doom9.o...d.php?p=1387282

I found that by time stretching, mkvmerge just modified the timecode of the track rather than modifying the TrackTimecodeScale in the track flags. Despite that it enables seeking accurate, this is still a wrong method according to the idea of TrackTimecodeScale in the design of Matroska container. However, on the other hand, the TrackTimecodeScale flag is not supported by players/renders, and it seems there's no developer willing to resolve this matter, so far as I know.

Edited by szfzafa, 11 August 2012 - 09:13 AM.

Magical Girls don't age, they just fade away
-- or have their heads bitten off

#9
Cman21

Cman21

    /)*(\ ^_^

  • Administrators
  • 2,442 posts
  • 259 thanks
  • Local time: 05:44 PM
ok, now i am confused at what exactly you are trying to do... but i still think you need to stretch something and re-encode something as i do not think mkvmerge can fix what you are wanting to do alone.

#10
szfzafa

szfzafa

    Meitantei

  • Members
  • 235 posts
  • 333 thanks
  • Local time: 05:44 AM
Problem resolved. :w00t:

Now I'll try to clarify this with an example: :coffee:
Let's say now I want these tracks in sync and I don't want to edit or reencode the PAL audio.

Track 1: NTSC Video @ 23.976fps
Track 2: NTSC Audio @ 23.976fps
Track 3: PAL Audio @ 25fps

Muxing:

There're two separate ways.

Method 1) use "Stretch by" feather in mkvmerge.

Select Track 3 in mkvmerge GUI, go to "Format specific options" page and in "Stretch by:" type "1001/960"(more accurate than 25/23.976)

Method 2) use TrackTimecodeScale feature of MKV tracks

TrackTimecodeScale is a track flag designed for such cases, you can read the Specification Notes for details(http://matroska.org/...ckTimecodeScale).
Use the Header Editor (mkvmerge GUI -> File -> ...) to open your remuxed MKV file, go to track 3 and modify the "Timecode Scaling" value to "1.042708" (actually should be 1001/960=1.0427083333... it's only a float value, but accurate enough)

Facts:

You'll have to combine both methods.
Fact 1) If you use method 1) only, stutters will occur for all renders except EVR Sync. I mean, the video will play faster, @25fps in average, but maybe @23.976 for 3-4 secs then comes a boost. But seeking is accurate and immediately done.
Fact 2) If you use method 2) only, there will be less stutters. Seeking can be accurate, I mean when you seek, video can be played immediately but audio will be muted for a while, then the audio will come back. The delay will be longer if you seek further from the beginning.

Explanation:
To fact 1), it's because mkvmerge just modified the timecode of the audiotrack and it's just like general a/v missync problems. One thing that matters is that various renders handle variable video FPS regarding to a/v missync delay differently.
To fact 2), it's because the reference framerate of the video is somehow changed, multiplied by the TrackTimecodeScale of the selected audiotrack. TrackTimecodeScale modifies only specific header parameter and not the whole timecodes. When seeking to a new position, only timecode matters and TrackTimecodeScale is not put into consideration. Thus the timecode of audiotrack is larger than that of the videotrack. So the audio just hang there muted until the video timecode advances to meet that position.

Combination? No!
So it's high suggested that you use method 1) then plus method 2). That is to modify both the timecodes and the TrackTimecodeScale of an audiotrack, which means minimum stutters and minimum seeking delay during playback.
It would be nonsense to combine these two separate methods. It would take both methods' downsides, completely messing up the output. :sick:
If you use method 1) then method 2), the video will play even faster @25*25/23.976fps.
If you use method 2) then method 1), the video will play original framerate, @23.976fps, and seeking is still out of sync. Because when muxing, mkvmerge will always remove previous TrackTimecodeScale settings and set the value to default.

Playback:

As I just mentioned, TrackTimecodeScale is not put into consideration when seeking.
Unfortunately, it's not supported by all audio decoders as well.

a) Audio Decoder

I just tried and here's the result.

Audio Decoder support for TrackTimecodeScale support for modified timecodes
AC3Filter 2.5b....................Yes.................................................Yes
Cyberlink 8.4.0.4812.........Yes.................................................Yes
FFDShow(Jun 27,2012).....No..................................................No
Gabest(1.6.3.5336)...........No..................................................Yes
LAV 0.50.5........................Yes.................................................Yes

For those who favors FFDShow audio decoder(including myself), they lucked out. :sweat: Video playback fps doesn't change at all. Even though they can seeking accurately, there will always be a linearly growing delay: the longer they play the video, the more out of sync the audio will be.
And those who favors Gabest will have more stutters.

b ) Video Render

VMR sucks, most stutters.
MadVR is much better, no visible stutter, but may still not with your time tooltip(time progress indicator, not sure how to say that :().
EVR Sync is the best, no sensible stutter at all.

Suggested Method and Playback Settings:

Method 1) only.
AC3filter/Cyberlink/LAV audio decoder.
EVR Sync or MadVR.

:wallbash:So it seems I've written a whole bunch of bullshit :spam:


Sorry for my bad English. :blushing:
Magical Girls don't age, they just fade away
-- or have their heads bitten off

#11
szfzafa

szfzafa

    Meitantei

  • Members
  • 235 posts
  • 333 thanks
  • Local time: 05:44 AM
Sorry for the double posting, but I'll write how to do a partial time stretching on an audio clip later here.

(This reply is reserved)
Blah blah blah...


I'd better explain with another example.

Let's say I've got a movie with official dub, and there's a fandubbed video.

The movie is Part I + Insert Song + Part II.
Originally, the insert song is 1min. at length, but they've made it into 2min. full ver..

If you want to remux the fandub audiotrack with official video&dub in same length, you need to follow these steps:

1. load the fandub video into mkvmerge, deselect the video track, split into 3 parts (Part I, Insert Song, Part II), they should be .mka files, let's call them P1.mka P2.mka P3.mka
2. open a new mkvmerge window, load the second .mka(P2.mka, the insert song part), select the audiotrack, type 1/2 in the "Stretch By" textbox. (1/2 means 2mins->1min in this case) then merge, let's call it P2_alt.mka
3. now you can remux with the official video&audio tracks using "Append": Load P1.mka, then append P2_alt.mka, then P3.mka, and merge.

Well, it's done.
And be sure to use the suggested playback settings I mentioned above.

Edited by szfzafa, 15 August 2012 - 09:46 AM.

Magical Girls don't age, they just fade away
-- or have their heads bitten off

#12
Cman21

Cman21

    /)*(\ ^_^

  • Administrators
  • 2,442 posts
  • 259 thanks
  • Local time: 05:44 PM
i see, so you went the round and about way to avoid re-encoding something.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users