Log in

View Full Version : Out of sync splitted file and +/++ joining ?


Poutnik
9th April 2005, 11:10
Lets say I have splitted parts of air captured avi file.
They are rather out of sync.

Is not better to use alignedsplice ( ++ )
to start syncing from the scratch
at begin of next split ?

Added after research:

Investigate and note what fps Virtualdub suggests
for each split to make a/v sync ( Video - frame rate )
lets name it Vdubrate.

for each split perform following command

s1=avisource(filename1).timestretch(tempo=100.0*25.0/vdubrate1)
s2=avisource(filename2).timestretch(tempo=100.0*25.0/vdubrate2)
and so on..
last=s1+s2+.....
The sync perfect matches now.

Poutnik
11th April 2005, 21:31
Originally posted by Poutnik

s1=avisource(filename1).timestretch(tempo=100.0*25.0/vdubrate1)
s2=avisource(filename2).timestretch(tempo=100.0*25.0/vdubrate2)
and so on..

Is there a script to do this automacically, without
looking at VirtualDub FrameRateData ?

stickboy
12th April 2005, 04:29
VirtualDub reports the AVI's reported framerate, which is the same
value that FrameRate() should return.
s1 = AVISource(filename1)
s1 = s1.Timestretch(tempo=100.0*25.0/s1.FrameRate())

s2 = AVISource(filename2)
s2 = s2.TimeStretch(tempo=100.0*25.0/s2.FrameRate())should do the same thing...

Poutnik
12th April 2005, 05:36
I am sorry, it seems I did not explain it clearly.

the framerate is always 25 fps, as I set it fix by capture app.
the problem is a sound is usually little faster than video.
virtualDub at video/framerate offer change fps e.g. from 25 to 25.047
I do not this, because I want to keep fps of the splits constant.
I would like to catch 25.047 value by script, not by myself.

Note that I have capture options "master stream non/video/audio".
I use none, so fps and audiorate is nominal, and I use timestretch
to "zoom" audio length.

There could be other possiblility master stream video, so
audio would have the same length, but shifted sample rate, lets say
44155. (It could be get by audiorate() )
would it work similar command to keep audio length, but change
44155 to 44100 hz
by s2=avisource(filename2).timestretch(pitch=100.0*44100/44155) ?
Or should do resampling ?

stickboy
12th April 2005, 06:19
Originally posted by Poutnik
virtualDub at video/framerate offer change fps e.g. from 25 to 25.047
I do not this, because I want to keep fps of the splits constant.
I would like to catch 25.047 value by script, not by myself.From where did you get the value 25.047? Did you calculate it yourself? If it's the value reported by VirtualDub's File Information dialog, then it's the same as what AviSynth's FrameRate() function will report.

If it's something you calculated, then any information accessible through VirtualDub should be accessible through AviSynth as well, so you can generate whatever mathematical expression you like.There could be other possiblility master stream video, so
audio would have the same length, but shifted sample rate, lets say

44155. (It could be get by audiorate() )
would it work similar command to keep audio length, but change
44155 to 44100 hz
by s2=avisource(filename2).timestretch(pitch=100.0*44100/44155) ?
Or should do resampling ?Well, I personally use VirtualVCR for my captures with dynamic resampling.

Poutnik
12th April 2005, 09:21
Originally posted by stickboy
From where did you get the value 25.047? Did you calculate it yourself?
personally use VirtualVCR for my captures with dynamic resampling.

VDub file info is reporting 25.000 fps as expected.
If video is slow comparing to audio, framerate dialog of VDub
suggests to change fps from 25 to 25.xxx to have video/audio synced.
I use this value, but do the opposite: in avs change audio tempo(length) by timestratch(?), using tempo=100*25/25.xxx.

Unfortunately, I was not successful in proper VirtualVCR
settings in my Win98SE/Leadtek 2000XP Expert card (CX2388x based)

BTW is timestratch par pitch=100*22050/44100 the same,
as changing audiosamplerate from 44100 to 22050 with keeping
audio lenght ?

stickboy
14th April 2005, 05:41
Ah, okay.

You should be able to do the calculations yourself using a combination of AudioRate(), AudioLength(), FrameRate(), and FrameCount().

Poutnik
14th April 2005, 11:12
thanks for your replies.
I have already explored this, made some joining script,
assuming all splits are out of sync, with FPS and Audiorate
different from nominal.

Test script with useful user functions,
some code can be redundant.



function VLen(clip c) {
#Counts video time (sec)
return float(framecount(c))/float(framerate(c))
}

function ALen(clip c) {
#Counts audio time (sec)
return float(audiolength(c))/float(audiorate(c))
}

function AVSync(clip c) {
#Conts Sync v/a time ratio
vl=VLen(c)
al=ALen(c)
return al/vl
}

function DeSync(clip c,dfps,dar,dptc) {
#For test purposes causes total A/V desychronisation
assumefps(c,framerate(c)+dfps,false)
assumesamplerate(audiorate()+dar)
resampleaudio(audiorate()+dptc)
return last
}

function NominalAudioRate(clip c) {
ar=audiorate(c)
return (ar > 46000 ) ? 48000 : (\
(ar > 37000 ) ? 44100 : (\
(ar > 26000 ) ? 32000 : (\
(ar > 18000 ) ? 22050 : ((ar > 14000 ) ? 16000 : 11025 ))))
}

function NominalFPS(clip c) {
fps=framerate(c)
return (fps > 27.5 ) ? 29.997 : (\
(fps > 24.5 ) ? 25.0 : 23.976)
}


function NClip(clip c) {
#set nominal FPS+Audiorate to allow joining splitted files
FPSNom=NominalFPS(c)
ARNom=NominalAudioRate(c)
return assumefps(c,FPSNom,false).assumesamplerate(ARNom)
}


function RateInfo(clip c) {
#Put in subtitles FPS, AudioRate, Sync v/a time ratio
vl=VLen(c)
al=ALen(c)
avsync=avsync(c)
s="fps "+string(framerate(c),"%2.4f")\
+" AuR "+string(audiorate(c),"%5.2f")\
+" ViTim "+timestr(vl)\
+" vasync "+string(avsync,"%2.6f")
return subtitle(c,s,size=12)
}

cl=BlankClip (length=10000, width=384, height=288, pixel_type="YV12", fps=25.000, audio_rate=44100,stereo=true, sixteen_bit=true)
c1=desync(cl,0.17,-50,-65).NClip()
c2=desync(cl,0.38,-440,+660).NClip()
c3=desync(cl,-0.29,-30,-75).NClip()
c4=desync(cl,0.69,+200,-770).NClip()
c1+c2+c3+c4
timestretch(tempo=100.0*avsync())
rateinfo()

Poutnik
14th April 2005, 17:24
For some reasen,I cannot edit my own reply, even logged in.

There are error in script, introduced when I thought there
are errors, without checking again.



function NClip(clip c) {
#set A/V sync + nominal FPS+Audiorate
#to allow joining splitted files

FPSNom=NominalFPS(c)
ARNom=NominalAudioRate(c)
assumefps(c,FPSNom,false)
assumesamplerate(ARNom)
return timestretch(tempo=100.0*avsync())
}

function RateInfo(clip c) {
#Put in subtitles FPS, AudioRate, Sync v/a time ratio
vl=VLen(c)
al=ALen(c)
sync=avsync(c)
s="fps "+string(framerate(c),"%2.4f")\
+" AudioRate "+string(audiorate(c),"%5.2f")\
+" VTime(sec) "+string(vl,"%5.3f")\
+" A/VsyncRatio "+string(sync,"%2.6f")
return subtitle(c,s,size=12)
}

BlankClip (length=10000, width=384, height=288,pixel_type="YV12",\
fps=25.000, audio_rate=44100,stereo=true, sixteen_bit=true)
desync(0.17,-50,-65).NClip()+\
desync(0.38,-440,+660).NClip()+\
desync(-0.29,-30,-75).NClip()+\
desync(0.69,+200,-770).NClip()
rateinfo()