Log in

View Full Version : Changing audio/video duration (for out of sync audio)


Dot50Cal
19th May 2008, 17:32
Hi guys, I've captured some footage from a game console but the audio gets progressively out of sync. I noticed that if I load it into virtualdub and check the "Change so video and audio durations match" under frame rate it fixes everything up perfectly. The frame rate suggestion it gives is 29.968. The file itself is 29.970.

My question is, is it possible to do this job in Avisynth? I've tried using assumeFPS 29.968 but that doesn't work.

I've looked around and found some people with similar problems but nothing matching my exact case. None of the solutions presented worked. Here is my Avisynth script:

LoadAviutlInputPlugin("C:\Program Files\AviSynth 2.5\plugins\EARTH SOFT DV.aui" , "EARTHSOFTDV")
EARTHSOFTDV("K:\RE4-1.dv")
ChangeFPS(29.970)
converttoRGB()
crop(39,72,-41,-74)

I am reading off a custom codec for a Japanese capture card's file format. I need to change it to 29.970 first, as the game only runs 30, but my capture card records at 60 all the time.

I had been googling a while and came across this post:

load avisynth file
under frame rate
Source rate adjustment
tick
Change so video and audio durations match

or else- adjust the fps in the avisynth file so that the video and audio durations are shown equal in File Information

But I'm not sure how to accomplish the bolded part. Can anyone offer assistance? Here is the File Information from Virtualdub:

http://b.imagehost.org/0859/fileinfo.gif

IanB
20th May 2008, 01:22
AviSource("....avi")
# Adjust FPS so video and audio duration match
AssumeFPS(FrameCount()/AudioLengthF()*AudioRate(), False)Of course this approach will lead to a non standard video rate, which may give you grief in later processing steps.

Another solution is to re-clock the audio to match the video duration.AviSource("....avi")
AR=AudioRate()
TR=Float(AR)*AR*FrameCount()/(AudioLengthF()*FrameRate())
KScale=Int($7FFFFFFF/ TR)
ResampleAudio(Round(TR*KScale), KScale)
AssumeSampleRate(AR)

Dot50Cal
20th May 2008, 01:59
Great! The first one does the trick just perfect! It seems to adjust in the same way VirtualDub was so I'm happy :)

The second one is a mystery to me though. I'm not very familiar with an advanced syntax like that. It throws an exception for the ResampleAudio command. Any idea why that might be?

IanB
20th May 2008, 23:19
Opps, the denominator argument to ResampleAudio() must be an Int. I have rewritten the example (and tested it this time :o )

Basically it calculates the hypothetical floating point sample rate needed to make the Audio track length match the Video track length. Then uses the ResampleAudio() filter to apply the require change ratio. Finally we set the Audio Sample Rate back to the original rate. Most of the Mathemagical trickery is to avoid integer overflow and achieve (close to) the correct fractional resampling.

Dot50Cal
24th May 2008, 00:32
Works perfect! Thanks Ian!