Log in

View Full Version : Gradual audiodelay change


zefram
21st December 2005, 23:31
Is it possible to change audiodelay gradually over time?

For example, I would like to change audiodelay from -200 to -300 gradually, over say 10 seconds or 250 frames.

thanx

redfordxx
23rd December 2005, 14:35
Delay is a relation between audio and video. So either audio or video should be changed. Changing video is easy...AssumeFPS... and then mux audio. Don't know what happens when assume fps on a clip with audio...

stickboy
23rd December 2005, 20:38
Delay is a relation between audio and video. So either audio or video should be changed. Changing video is easy...AssumeFPS... and then mux audio. Don't know what happens when assume fps on a clip with audio...Read the AssumeFPS documentation. It says what happens quite clearly, since there's a sync_audio parameter.

Anyhow, that doesn't really answer zefram's question, does it?

Wilbert
23rd December 2005, 21:59
So the audio should be delayed with -200 and stretched after that?

IanB
24th December 2005, 03:00
Unfortunatly Animate() does not work for audio. Even if it did you would end up with glitches in the audio at each frame boundary as it adjusted the Audio Delay in small discreet steps. The glitches would be due to a small number of audio samples skipped at each transition and I am sure this would be very audible.

To achieve your goal I suggest you manually edit the additional 100ms of delay into the source audio in 10 to 20 ms slices at points where there is natural silence over the 10 second transition region. Then just use a global DelayAudio(-0.3)

Alternativly you could try using TimeStretch() on the transition segment, for small changes it uses a silence length adjustment algorithm.AviSource("file.avi")

AV200=DelayAudio(-0.2)
AV300=DelayAudio(-0.3)

A=AV200.Trim(0, 1000) # Start at frame 1000
C=AV300.Trim(1250, 0)

AV200.Trim(1000, 0)
TimeStretch(Tempo= 100.0*(1.0+((0.2-0.3)*FrameRate()/250)) )
B=Trim(0, 250)

A.Dissolve(B, 1).Dissolve(C, 1) # 1 frame overlap to mask audio transitionsCheck the sign in my arithmetic, Tempo=99.0 should remove 100ms in 10 seconds, but it might need to be 101.0

redfordxx
24th December 2005, 21:48
Read the AssumeFPS documentation. It says what happens quite clearly, since there's a sync_audio parameter.

Anyhow, that doesn't really answer zefram's question, does it?
Well it could, I think it depends what is the zefram's purpose.
What I had on my mind, was to avoid any audible artifacts caused by the delay easily: Just keep the audio and speed up the video, provided the nature of the clip and his purpose allow it.
And I think, first separating audio and video, then AssumeFPS on the video and the again joining would solve it.
Other extreme: just prepare the audio separately in advance and stretch it in some editor...

Mug Funky
26th December 2005, 03:07
it may well be easier to take it all into an audio editor (that supports video) and adjust it in blocks. scripting what could be multiple edits is just too painful.

btw, almost by definition, a gradual change in delay is the same thing as a change in sample-rate, so resampling chunks of audio is probably what is needed (or timestretching, but it is likely the pitch is altered in the source as well, and resampling may in fact correct it).

can i ask what you need this for? there's a couple of things i can think of that would require this, but chances are it's an analog capture where the audio and video are hooked to different wordclocks (ie sound card and capture card have slightly different clock speeds).

zefram
30th December 2005, 00:42
Kinda forgot about this thread, I eventually got what I wanted with something similar to what IanB posted above (also using timestretch).

What I'm doing: Have different mpeg2 files with different delay's, but the audio tracks should be linked end to beginning. Have found that linking with unalignedsplice (the default when using +) I can link the files perfectly, but then I loose sync.

With alignedsplice I either loose audio, or get silent audio, for about a 200 ms (enough to loose a word). I guess the loss comes from the differences in delays.

So what I did was link the end of a segment, with the beginning of the next segment using unalignsplice, and then gradually change the sync over the next ten seconds to what it was suppose to be. And then link the rest alignedsplice. I didn't know about the Dissolve, thats gonna help (I did it with mixaudio)

In the end my way worked, but IanB's solution is much more elegant.

Thanx to all :goodpost:

aarrgghh, edited twice to fix the aligned and unaligned, hope its right now :)