Log in

View Full Version : Audio sync problem at player seeking


lilive
7th September 2009, 18:05
Hi,

I've got an audio sync problem with a script.
- I open it with a video player.
- audio is first sync with video
- I lose the sync when I seek the movie with the player controls.

I've already done this type of script without problem.

Note : The avi file belong from a dv-cam, and some frames are missing, but not in the part I trim (as I can see)

Here's the script :

DirectShowSource("part00.avi")
last + DirectShowSource("part01.avi")
last + DirectShowSource("part02.avi")
v = last
a = AudioDub( BlankClip(v, length=5000, width=8, height=8) , WAVSource("sound.wav") )

v1 = v.Trim(20563 , 0)
a1 = a.Trim( 20000 , 0 )
a1 = a1.Trim(0, v1.framecount -1)

AudioDub(v1, a1)


If I encode the script, and play the result, there's no more sync problems.

May anyone know how can I fix this problem ?
Thank you very much.

Gavino
7th September 2009, 22:05
a = AudioDub( BlankClip(v, length=5000, width=8, height=8) , WAVSource("sound.wav") )
...
a1 = a.Trim( 20000 , 0 )
See the problem?

lilive
7th September 2009, 22:48
See the problem?
Oh, sorry, a little mistake posting this code :o
Don't care about it.
As I said, it works. Sync problems only appear seeking the video (forward and rewind).
But thanks for your reply :)

Gavino
7th September 2009, 23:02
As I said, it works.
It can't possibly work as posted - it produces a clip with only one frame's length of audio. If you want your question answered, you will have to post the exact script you used.

lilive
8th September 2009, 10:34
It can't possibly work as posted - it produces a clip with only one frame's length of audio. If you want your question answered, you will have to post the exact script you used.

Ok, sorry for that.
Here's the right script, with some commented tests :

DirectShowSource("part0.avi")
last + DirectShowSource("part1.avi")
last + DirectShowSource("part2.avi")
v = last
#~ return MessageClip(string(v.framecount)) >> display 40183

a = AudioDub( BlankClip(v, length=128250, width=8, height=8) , WAVSource("sound.wav") )
#~ return MessageClip(string(a.framecount)) >> display 128250

v1 = v.Trim(20563 , 0)
#~ return MessageClip(string(v1.framecount)) >> display 19620
a1 = a.Trim( 81225 , 0 )
#~ return MessageClip(string(a1.framecount)) >> display 47025
a1 = a1.Trim(0, v1.framecount -1)
#~ return MessageClip(string(a1.framecount)) >> display 19620

AudioDub(v1, a1)
#~ return MessageClip(string(last.framecount)) >> display 19620


Opening it with mplayer or media player classic, it work fine.
But audio sync fails when I press either the rewind or the forward button.

I have just noticed that by adding two lines at the end of the script :

DirectShowSource("part0.avi")
last + DirectShowSource("part1.avi")
last + DirectShowSource("part2.avi")
v = last

a = AudioDub( BlankClip(v, length=128250, width=8, height=8) , WAVSource("sound.wav") )

v1 = v.Trim(20563 , 0)
a1 = a.Trim( 81225 , 0 )
a1 = a1.Trim(0, v1.framecount -1)

AudioDub(v1, a1)

Trim(20,0)
#~ return MessageClip(string(last.framecount)) >> display 19600

The audio sync fails in every case.
Really strange isn't it ?

Gavino
8th September 2009, 14:34
Really strange isn't it ?
It is, yes.
Normally, audio sync problems that show up only on playing (and not on encoding) are due to the script being too slow to process in real time. But your script doesn't have any 'slow' filters in it.

Is there anything odd about your source files? What did you mean when you said some frames were missing?
Is sound.wav a pure uncompressed LPCM source (not MP3 stored in a wav file, for example)?
Have you tried replacing DirectShowSource by AviSource?

lilive
8th September 2009, 15:51
Is there anything odd about your source files? What did you mean when you said some frames were missing?

Desync problems occurs only for some avi files.
Playing these files, I can see "artifacts" or "jumps" in a few shorts regions.
(Perhaps these jumps are just frames dropped during acquisition.)
My script work fine if I cut these regions.
I think I will solve my problem this way, unless finding another solution.


Is sound.wav a pure uncompressed LPCM source (not MP3 stored in a wav file, for example)?

Yes, I convert a mp3 file to wav, with audacity.


Have you tried replacing DirectShowSource by AviSource?
Yes but :
AVISource: could'nt locate a decompressor for fourcc dvsd.

Thanks for your suggestions.

Gavino
8th September 2009, 17:02
Desync problems occurs only for some avi files.
Playing these files, I can see "artifacts" or "jumps" in a few shorts regions.
(Perhaps these jumps are just frames dropped during acquisition.)
My script work fine if I cut these regions.
Possibly these confuse and slow down the decompressor until it recovers.
AVISource: could'nt locate a decompressor for fourcc dvsd.
You need to install a VfW DV codec. Cedocida is widely recommended on these forums.

lilive
9th September 2009, 17:08
Possibly these confuse and slow down the decompressor until it recovers.

You need to install a VfW DV codec. Cedocida is widely recommended on these forums.

Thanks for this advice.

But I'm in a hurry with this movie, and I prefer not to modify my computer config now. (And I don't believe enough it could fix the problem)
At the moment, I simply removed the bad frames.

I will try cedocida later.
Thanks again for your help.

foxyshadis
9th September 2009, 21:49
DirectShowSource inherently causes desynchronizations when you seek. The more recent versions of avisynth are better, so it's very important to have the latest, but avisource or ffmpegsource is better for keeping synch. You should try ffmpegsource (http://code.google.com/p/ffmpegsource/).

Gavino
9th September 2009, 23:59
DirectShowSource inherently causes desynchronizations when you seek.
Certainly it often does.
But in this case, the OP states that desync only happens on real-time playback, not on encoding. Can this be explained by the usual limitations of DirectShowSource? His sources are DV video and LPCM audio which one would hope to be more easily seekable.

foxyshadis
11th September 2009, 02:21
Yes. Encoding doesn't seek, unless you have lots of large trims or filters that seek wildly. Recent versions of DSS will not seek forward unless the seek request is large, 1000 frames iirc, otherwise it will just decode up to that point, and backward you can get whatever's still in the cache. Whether it's DV or mpeg4 or uncompressed avi makes absolutely no difference at all: if the source splitter can't seek properly, you won't get proper seeking.

Very few splitters have frame-exact seeking because nobody cares that much when watching, as long as the audio is off by the same amount. Some return a few grey frames until they have their bearings, again because it isn't visible in playback, or even crash while seeking because they're so poorly written. There's an old thread where IanB described the pathologies encountered in many filters.

lilive
9th October 2009, 22:05
Hi,
Just to tell you that I now use cedocida to load DV movies (AviSource). Work fine.
I haven't try it to solve my previous problem, but thanks again.