View Full Version : Adjusting A/V sync with AVISynth - is it possible ?
aklendathu
13th January 2004, 11:17
I am trying to convert an MPEG-1 VCD file to MPEG-2 for DVD authoring.
Using AVISynth to frameserve the MPEG-1 file to TMPEGenc gives a good quality MPEG-2 video stream. However, audio gets out of sync after 10-15 minutes of play time. It seems audio and video streams in the original MPEG-1 file have different durations (framerates?) - I opened the MPEG-1 file in VirtualDUB and by looking at Video->Framerate it tells me that video is 29.97 fps and audio is 30.01 fps...
My question is: is it possible to correct this problem with AVISynth?
for example, changing the video framerate to 30.00 fps ? When this video is converted to 29.97fps MPEG-2 will it then stay in sync with the audio ?
TIA,
Pedro.
d'Oursse
13th January 2004, 13:42
look at there :
http://www.avisynth.org/index.php?page=FPS
ppera2
13th January 2004, 16:46
I suggest to you that don't change video FPS - it is right as standard requires.
Need to correct audio. It can be done with AVISynth too.
LoadPlugin("YOUR_LOCATION\mpasource.dll")
....
CacheAudio()
ResampleAudio(48000/44100x48000x30.01/29.97)
AssumeSampleRate(48000)
You need latest version of mpasource.dll and CacheAudio() command, or will have very distorted audio. I assumed that VCD has samplerate of 44100, therefore such formula. Otherwise use just 30.01/29.97. And of course, you need to write in script result of calculation...
For better audio quality, you need some audio editor program and timestretch.
aklendathu
14th January 2004, 00:21
Thanks,
I'll try that. In the meantime, I found out that I can get properly synchronized a/v if I recode the VCD MPEG-1 to DVD MPEG-2 with NeroVision Express. However, the AVISYnth script looks more attractive if it works because I can then use TMPEGenc in batch mode whereas NeroVision does not have such a feature.
Cheers,
Pedro.
ppera2
14th January 2004, 01:07
Originally posted by aklendathu
... the AVISYnth script looks more attractive if it works because I can then use TMPEGenc in batch mode whereas NeroVision does not have such a feature.
Sure, such programs can solve only simple cases. With AVISynth you can solve lot of specific problems.
ronnylov
14th January 2004, 10:36
You don't need to convert MPEG1 at VCD resolution to MPEG2 for DVD authoring. MPEG1 at VCD resolution is a valid format on DVD. But the audio need to be converted to 48 kHz sampling frequency.
You can use TMPGEnc DVD Author to import VCD video and it will also resample audio if needed then you can author a DVD of it.
aklendathu
14th January 2004, 20:18
@ronnylov:
I know that. The problem is that when I use that procedure the audio and video become unsynchronized.
@ppera:
I couldn't get your suggestion to work on my system. I am using AVISynth 2.5.3 and downloaded the latest MPASource plugin. Could you post a more detailed script example ? You can PM me if you prefer.
TIA,
Pedro.
ppera2
14th January 2004, 20:26
Script is quite simple:
LoadPlugin("F:\PROGRA~1\GORDIA~1\mpasource.dll")
LoadPlugin("F:\Program Files\Gordian Knot\Vsfilter.dll")
Directshowsource("G:\Att2.avi")
CacheAudio()
ResampleAudio(42294)
AssumeSampleRate(44100)
ConvertToYUY2()
AssumeFps(25)
BicubicResize(480,320)
AddBorders(0,128,0,128)
TextSub("E:\Att2.ssa")
This is for conversion 23.976 to 25 fps, and make SVCD.
As I said, you need to write numbers, not formulas by ResampleAudio.
I didn't try it with Mpeg1 source.
What error message you get?
Wilbert
14th January 2004, 22:39
As I said, you need to write numbers, not formulas by ResampleAudio.
Formulas are fine. But, don't forget to convert them to ints. Thus
a = int(48000/44100*48000*30.01/29.97)
ResampleAudio(clip,a)
aklendathu
15th January 2004, 01:16
@ppera2:
Thanx! The problem was in the order of the commands.
The script
LoadPlugin("...\AviSynth 2.5\plugins\mpasource.dll")
DirectShowSource("D:\...\mydfile.mpg",audio=true)
CacheAudio()
ResampleAudio(48064)
AssumeSampleRate(48000)
LanczosResize(352,480)
works (i.e., I can open the file in VDUB and see Audio properties).
Before, I was placing the audio commands after LanczosResize(352,480)
and no audio properties showed up in VDUB.
You'll notice that I am resampling audio to 48064, i.e. 48000*30,01/29,97 - I don't understand why you had it further multiplied by 48000/44100 in your formula.
@Wilbert:
There's a float version of CacheAudio named BufferAudio. I presume that one can handle non-integer values.
ppera2
15th January 2004, 01:59
Originally posted by aklendathu
...You'll notice that I am resampling audio to 48064, i.e. 48000*30,01/29,97 - I don't understand why you had it further multiplied by 48000/44100 in your formula....
I explained it - you need 48000/44100 only if VCD has sample rate of 44100 to increase it on 48000 for DVD compatib.
Actually ResampleAudio() accepts only integers. Perhaps is better rounding by hand - int(11.9) will give 11, but better is 12, if I'm correct.
Wilbert
15th January 2004, 10:27
Perhaps is better rounding by hand - int(11.9) will give 11, but better is 12, if I'm correct.
Yes, you are right. I should have used "round" instead of "int".
There's a float version of CacheAudio named BufferAudio. I presume that one can handle non-integer values.
I never have heard of that. Do you have a link?
aklendathu
15th January 2004, 11:45
@ppera2:
I see your point, but the reference manual only mentions e.g.,
ResampleAudio(48000) to do just that, regardless of the original source sampling. From your script I guess that you change the resample rate and then use the AssumeSampleRate to change playback speed according to frame rate difference ? If I do the calculations as per your formula I would get ResampleAudio(52297) which strikes me as rather odd for such a small frame rate conversion...
In your example, what was the original audio sample rate ?
@Wilbert:
Here it is:
http://www.avisynth.org/warpenterprises/files/mpasource_25_dll_20040109.zip
ppera2
15th January 2004, 16:08
Originally posted by aklendathu
@ppera2:
I see your point, but the reference manual only mentions e.g.,
ResampleAudio(48000) to do just that, regardless of the original source sampling. From your script I guess that you change the resample rate and then use the AssumeSampleRate to change playback speed according to frame rate difference ? If I do the calculations as per your formula I would get ResampleAudio(52297) which strikes me as rather odd for such a small frame rate conversion...
In your example, what was the original audio sample rate ?
Right... I confused some things here... You need only ResampleAdio(48000*30/29.97) in first command. My script does 2 things in one command: resamples to 44100 (fictive), and speeds up some 4%.
Now I'm not sure in that 30/29.97... Maybe you need to use 29.97/30...
Try it, and inform us :)
Assume samplerate is needed always when we change speed - we need to supply standard audiosamplerate to compressor.
aklendathu
15th January 2004, 23:24
Well, no luck.
I discovered that my problem for this particular file is caused by a MPEG-1 video stream corruprtion(?) - by stepping through several movie frames in VDUB (Direct open) I noticed that there is an unusually short GOP (IP only) which coincides with a discontinuity in playback and is very likely the source of a/v out of sync from there on. The amazing thing is that apart from that hiccup, the file plays OK when burned as a VCD. The conversion to AVI also produces a file with complete a/v sync. Only the direct conversion to MPEG-2 with AVISynth/VDUB via TMPEGenc gives trouble. Oddly enough NeroVision Express 2 also encodes the movie to MPEG-2 correctly, but the lowest resolution is 352x480, which is an overkill in this case.
Thanks nevertheless for your help. Although unsuccessful in solving this problem, I did learn a lot about AVISynth in the process.
Cheers,
Pedro.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.