PDA

View Full Version : Determining and correcting audio capture delay.


mkanel
5th April 2004, 18:00
My VirtualDub captures always produce an avi file with audio that is about 0.17 seconds longer than the video, and the audio is always about 0.17 seconds delayed on playback. I noticed some slight lip sync on captured home videos, it seemed to be present throughout the video, not the kind that gets progressively worse.

I've been capturing analog home video to PCTV (BT8X8) and soundblaster live value on a Pentium III 933Mhz computer, I use the sourceforge WDM Video Capture Driver.

It's difficult to find the perfect spot in home video to check audio/video sync so I made a very exiting video for the sole purpose of testing audio/video sync. I recorded myself hitting two spoons together in an otherwise quiet background. Although I can spot lip sync it's still maddening difficult to look at the clanging spoons and tell if the audio is early or late.

I made a simple avisynth script using Richard Ling's AudioGraph plugin, which you can get here: http://www.avisynth.org/warpenterprises/ sh0dan's modified version is there also. Open this script in VirtualDubMod and you can easily see the audio delay.

#ASYNTHER AVISource
AVISource("D:\spoons.avi")
#complementparity #swaps field order if playback is jerky
bob
#delayaudio(-.17) #uncommenting this fixes my audio delay
audiograph(1)

For interlaced sources this doubles your frame rate to give even a better idea of how far off the audio is. In my case the audio is delayed by 0.17 seconds. (Would the delay be less on a faster computer?) It might coincidence that the audio delay exactly equals the difference between the audio and video length. This delay was constant whether I made short 10 second captures or two hour captures (no I didn't spend two hours smashing spoons together I did the spoon banging at the end of a normal video). It seems that both the VirtualDubMod syncronization schemes work, my captures go out of sync by several seconds if I turn off the sync correction, but VDM can't seem to get the audio/video start times exactly the same.

I read somewhere that avi_io produced audio and video lengths that were exactly the same so I tried capturing with the trial edition. Sure enough the audio and video times were equal. When I checked the sync with audiograph it showed that for avi_io the audio came before the video but only by 0.05 seconds, probably not enough to cause noticeable lip sync. Maybe VirtualDub and avi_io start audio and video capture in a different order, obviously they do something differently. As long as this delay proves to be constant it will be easy to correct.

Does anyone/everyone else get this delay?

Mike.

BruceL
6th April 2004, 03:41
I think you will find that the offset is .250 second. I forget the exact reason why it exists but if I come across it I'll repost. I think it has something to do with buffering. I always had to use that offset when capturing with any VDub version. I now use VirtualVCR and it corrects for the offset when capturing.

numlock
6th April 2004, 04:24
http://darkfalz.hypermart.net/software/
"AVI Offset Calculator - This is intended for people who use WDM capture device/programs. These often create AVI captures with internal audio and video offsets, which make their playback sync correctly but tend to ruin things when you try to edit them. This tool calculates the total offset, sets the internal offsets to zero, and renames the file so that you can manually adjust the audio skew in VirtualDub or other application prior to editing. This should result in proper sync for playback and editing."
http://darkfalz.hypermart.net/software/AVIOffsetCalculator_1.0.0.18.zip

mkanel
6th April 2004, 13:07
BruceL,

I just gave VirtualVCR a try and came up with the same audio delay 0.17 seconds. Perhaps I had it configured wrond.

numlock,

That looks like it addresses the issue but both links appear to be dead. I tried searching for AVI Offset Calculator and AVIOffsetCalculator without success.

Thanks for the responses. Mike.

Valky
6th April 2004, 14:37
Originally posted by mkanel
BruceL,

I just gave VirtualVCR a try and came up with the same audio delay 0.17 seconds. Perhaps I had it configured wrond.


Probably you hadn't. I have always had that -170 ms delay with VirtualVCR and I was surprised that you had same issues with vdub.
I use same capture-drivers.

mkanel
7th April 2004, 05:01
Valky,

I tried playing with a few more setting in VirtualDub but still always get the .17 second delay. I figured it was either a problem in my system or something that every was universal among all users. It's interesting that I get the audio delay in VDub and VirtualVCR, you had it only in VirtualVCR, and BruceL had good sync with VirtualVCR. I don't know why it happens but at least it's easy to correct. It's helpful to know that others have seen similar issues.

Thanks for the replies. Mike.

P.S. If any one has a working link to AVI Offset Calculator could you post it? Or email it to me (I assume it's freeware)

Edit: No need to send AVI Offset Calculator, I got it thanks numlock.

mkanel
9th April 2004, 05:20
I've experimented a little more with VirtualVCR and continue to get an audio delay of about 170ms, same in VirtualDub(Mod), in avi_io the audio is 50ms early. Those numbers come from looking at the video in VirtualDubMod with the AudioGraph filter. I expect these numbers will be different on different computers.

Avi Offset Calculator shows no audio delay for VirtualDub or avi_io but reports a correct delay for VirtualVCR of about 170ms. Looking at the options for VirtualVCR it is supposed to be able to automatically correct for the audio offset but the documentation says that feature doesn't work, you can also enter a manual offset but that was buggy, it either applied too much correction or none at all (zero ms or 500ms). Here's what the documentation says:


SyncUsingStreamOffset

This option will take into consideration any latency issues your capture devices have, if for some reason your audio card is delaying the audio stream by 2 seconds to fill up its internal buffers then the FilterGraph will delay the Video by the same amount etc. If you notice AV sync right from the beginning of the capture you can try this option to see if it helps, this option will only help initial delay problems not progressive AV sync problems.

Delay Audio By

I have not had any success with the SyncUsingStreamOffset option so I have added the Delay Audio by option as well, this option allows you to delay the audio by a certain amount thus allowing you manual control over the stream offset.



VirtualVCR is the only capture program of these three that admits that it has a problem, at least when it's asked by AVI offset calculator. Well that's a start and maybe they will correct the option to automatically fix it. I thought I was leading up to a question but I guess not, so thanks for the input, anything more is welcome. Mike.

Divine
16th April 2004, 00:09
Originally posted by numlock
http://darkfalz.hypermart.net/software/
"AVI Offset Calculator - This is intended for people who use WDM capture device/programs. These often create AVI captures with internal audio and video offsets, which make their playback sync correctly but tend to ruin things when you try to edit them. This tool calculates the total offset, sets the internal offsets to zero, and renames the file so that you can manually adjust the audio skew in VirtualDub or other application prior to editing. This should result in proper sync for playback and editing."
http://darkfalz.hypermart.net/software/AVIOffsetCalculator_1.0.0.18.zip


Links are dead. Can anyone upload the program somewhere?

mkanel
16th April 2004, 11:50
@Divine,

I can't find a working link and I'm not allowed to post any attachments, I can't pm you either, it must be disabled in your profile. If you pm me with your email I'll send it to you.

Depending on what your avi was captured with avioffsetcalc may or may not be useful. It doesn't come with any documentation. Here's a very short description from the author. http://virtualdub.everwicked.com/index.php?act=ST&f=6&t=1767&hl=offset&

Edit: Oh sure just as I send this I find this in my email, the author says it's probably temporary.

http://darkfalz.kiczek.com/software/AVIOffsetCalculator1.18.zip

Divine
16th April 2004, 18:53
Great, thanks! :sly:

Some info about my problem:
I captured something a few days ago. The original avi (100gb YUY2 uncompressed) is 100% sync when i play it, but once i start encoding/editing/whatever it is out of sync, so i will probably need this. :)

Valky
16th April 2004, 19:17
Strange thing. I tried this software 'avioffsetcal' and it seems to give me always suggestion -224 even if I am pretty sure that the correct suggestion should be -170 when using VirtualVCR. This setting has always gave me perfectly synched files before.

I did only short capture testing now (I am out of space), but I'll try to investigate more. It seems to me that using -170 instead of -224ms is little bit better synched, but I am not sure since the file is so short.

It would be intresting to know how accurate this software is.

Mac Sidewinder
17th April 2004, 18:48
I have always had this same problem. I use a pinnacle PCTV card with btwincap drivers and virtualdub sync. Since I use CCE to process the video and do the audio separtely I always have to adjust the audio by 150ms. (for some reason this just seemed about the correct delay adjustment). I will try 170 and see if it looks better.

Mac

mkanel
17th April 2004, 21:11
Another way to measure the delay is to do some captures with iuVCR, the trial version is here http://www.iulabs.com/iuvcr/download.shtml

When you click on start record it gives you a number at the bottom of the window "Video stream latency xxx ms" I think that is the audio delay, at least it seems to be on my system. You can repeatedly hit start capture/stop capture to see what kind of numbers you get. For me it's always been between 158 ms and 188 ms. The mean of 173 ms is close enough. Just put a minus in front of the number for the correction to your VirtualVCR VirtualDub captures.

It's worth checking out iuVCR it corrects for most of the delay automatically and it seems user friendly, I'd buy it except that I can't keep long captures in sync. Many say they get in sync captures with this program , I don't but I'm capturing from tape, maybe they're not.

Darkfalz
22nd April 2004, 10:33
Hello. I am the author of the above utility.

AVI header contains two offsets. One is the video offset in frames (how many frames from the start of the stream until the video actually starts) and the other is the audio offset in samples.

Now, when you play back most DirectShow based applications are delaying the audio and video streams by the relevant amount. This is why when you double click it, it plays back with correct sync (interesting, Media Player Classic doesn't seem to do it right). But when you open it in VirtualDub, it ignores the offsets completely and that's why after you edit it, your sync is gone.

So to get the actual audio/video skew is quite simple, (frames / fps) - (sample offset / samples rate). The video is always starting later than the audio. Then you write them both to 0 and you adjust the offset manually in VirtualDub, and viola - perfect sync (provided your capture driver and application didn't mess things up). I don't know exactly how it is caluclated in iuVCR but it's always about 10 ms different from mine, I suspect Ivan (good bloke) has made a miscalculation somewhere. I know mine is correct because of running it through DirectShow and it did delay the audio stream (null samples) for the right length as well as holding the right number of frames.

I'm usually getting between 150 ms and 250 ms (it's different every time but not by much) and considering you can't really judge sync exactly within about 100 ms, an average of 170 ms or so should work fine most of the time. But you can use my utility to get it perfect (hopefully) - turn off all sync options in the capture program just in case it's messing something else up.

Now I use the btwincap WDM driver (works great under XP, not so great under 98/ME) and iuVCR and since learning about these internal offsets and writing my tool, I've had perfect sync in every capture. Other things that might affect your sync are your sound card isn't accurate (I heard SBLive eventually drift out of sync unless you are capturing at 48000) of if your source material is a poor quality VHS, it will often drop frames and that can also mess up your sync completely.

Try iuVCR with standard MUX, no master stream, and ALL SYNC settings OFF, and then use my utility after your capture and see if you get your sync looking nice. Should work. :-)

olnima
22nd April 2004, 13:58
Is it better to use "no master stream" and adjust the framerate with VirtualDub ("Video" -> "framerate" -> "Change so Video and Audio Durations match") AFTER using your tool or to use "master stream=audio" to get the same length of audio and video BEFORE using your tool?

Thank You for your piece of soft

Greetz
Olnima

mkanel
22nd April 2004, 15:57
@Darkfalz

Good post. Just to clarify one thing about your program, please correct me if I'm wrong. Many people at this forum including myself capture with VirtualDub, when using your Avi Offset Calculator to open a VirtualDub captured AVI it will show the Audio/Video offsets to be zero but this is false comfort, an audio delay does exist but for whatever reason it's not written to the AVI header by VirtualDub. Is that right?

If despite your good advice one insists on capturing with VirtualDub they'll have to correct each capture using their eyes and ears to determine the amount of correction required or pick an offset number that seems to work and apply it to every capture.

Darkfalz
23rd April 2004, 01:14
VirtualDub uses the WDM to VFW wrapper. I don't think it captures with offsets. Honestly, I don't recommend capturing with any VFW based programs.

It's better to use no master stream in general, or you get weird framerates/samplerates. It's okay if they are not quite the same length, after you edit them they'll be fine.

I think you might want to use master stream video only if you have a problem with sync getting gradually worse.

Don't use that change so video and audio durations match at all. It's normal for the streams to be different lengths. Just try using the offset calculator, setting it, and them write it to a new file and see if the sync is better.

sh03z
23rd April 2004, 01:18
I don't know if anyone has said this (So sorry if I'm reiterating)

But, make sure you have the latest drivers/firmware for your audio/video stuff.

Darkfalz
24th April 2004, 06:02
One other thing, when capturing from VHS you typically get best results capturing full frame (640x480 for NTSC or 768x576 for PAL), I've found timing and sync problems are much more likely capturing smaller sizes or one field only.

Kalicrys
27th April 2004, 16:45
Originally posted by sh03z
But, make sure you have the latest drivers/firmware for your audio/video stuff. [/B]

actually, the asus V9520 videosuite I use seems to have problems with the latest drivers, so I use the next-to-last version. ;) But of course, common sense rules most of the time.

jhaverbs
29th April 2004, 00:20
Originally posted by mkanel
@Divine,

Edit: Oh sure just as I send this I find this in my email, the author says it's probably temporary.

http://darkfalz.kiczek.com/software/AVIOffsetCalculator1.18.zip

None of the link works. Where can I download AVI Offset Calculator?

Thanks,

Bharat

mkanel
29th April 2004, 00:53
Try this now.

http://darkfalz.kiczek.com/software/

jhaverbs
29th April 2004, 01:17
It works. And thanks a lot. Can't wait to try it tonight. The main reason I want to try is is:

I have ATI All In Wonder 7500 Radeon Card. With their MMC (Multi media Center), I capture to Mpeg-4. When I play the captured AVI on computer, plays in perfect sync. But when I download it to my ARCHOS handheld mp4 player, the audio is ahead of video.

For avi captured with 320x240 resolution I was able to correct the sync by using graphedit, splitting the avi using AVI splitter first, and then muxing back using AVI Mux. The default AVI Mux in graphedit has "No interleave". But I change that to Full Interleave at 1000 ms. And bingo, the remuxed AVI file works perfect in my ARCHOS player.

Unfortunately, the same technique does not work for AVI captured at 640x480 resolution. Does anyone know why? Very strange.

I will try this AVI Offset Calculator and remux in virtualdub.

Bharat

FulciLives
2nd May 2004, 08:09
Here is what I do to get my captures in sync:

First I'll give you some specs of how I capture. I use an AverTV Stereo PCI TV tuner type capture card. I use the BTwincap driver. I do mostly NTSC so I use 712x480 29.970fps ... and yes I know 712x480 sounds "odd" but I use that because according to Trevlac (a forum poster here and on VIDEOHELP.COM) that is how you get a proper aspect ratio with the BTwincap driver. Go figure. I tested it and it sure seems to be correct though admittingly the aspect ratio errror of using 720 or 704 instead of 712 is very negligable.

I use a capture program called TheFlyDS which seems to fuction very similiar to iuVCR. I set MASTER STREAM to audio. I use PICVideo MJPEG on the 19 setting and my audio is set to 16-bit Stereo 48k PCM WAV.

When I open my AVI directly into VirtualDubMod the audio and video almost always match but are never 29.970fps. Usually I get something like 29.967fps or 29.966fps.

When they do NOT match it is usually VERY close. Like video will be 29.967fps whereas audio might be 29.966fps ... so ... when that happens I select the option to match and do a DIRECT STREAM copy save to a new file. I then discard the original capture and work with the new file.

I used TMPGEnc in the past but now mostly use CCE. I use AviSynth scripting and my last line in the script is: AssumeFPS(29.970, true)

I load the AviSynth script into TMPGEnc and do an audio only encode to 16-bit Stereo 48k LPCM (WAV) using SSRC as a plug-in. This gives me a "matched" audio file of high quality. Usually SSRC goes from 48005 or 48006 to 48000

Then I load my AviSynth script in CCE to do the video.

I then take my PCM WAV file from TMPGEnc and normalize then encode to 256kbps 2.0 AC-3 audio.

I never ever get sync problems this way :)

So I'd say setting MASTER STREAM to AUDIO is key although I tried this once with VirtualVCR and it didn't seem to work. My trial for iuVCR ended long before I discovered this but since TheFlyDS seems so somiliar I bet iuVCR would work the same way.

- John "FulciLives" Coleman

jhaverbs
4th May 2004, 09:56
Originally posted by Darkfalz
Hello. I am the author of the above utility.

AVI header contains two offsets. One is the video offset in frames (how many frames from the start of the stream until the video actually starts) and the other is the audio offset in samples.


So to get the actual audio/video skew is quite simple, (frames / fps) - (sample offset / samples rate). The video is always starting later than the audio. Then you write them both to 0 and you adjust the offset manually in VirtualDub, and viola - perfect sync (provided your capture driver and application didn't mess things up). I don't know exactly how it is caluclated in iuVCR but it's always about 10 ms different from mine, I suspect Ivan (good bloke) has made a miscalculation somewhere. I know mine is correct because of running it through DirectShow and it did delay the audio stream (null samples) for the right length as well as holding the right number of frames.


Would someone please confirm. If audio/video skew defined above is positive, I delay audio by that amount in virtualdub. And if skew is negative, I give that -ve number in audio delay.

What confused me is that AviOffsetcalc gives a +ve skew, but adds a -ve nuber to the new file name.

numlock
4th May 2004, 15:52
yes, it's always negative

Darkfalz
8th May 2004, 17:53
Should always be a positive skew (hence you use a negative in VD to offset it), because the main stream or whatever you want to call it cannot start AFTER the audio or video streams, only before.

stickboy
10th May 2004, 01:51
Originally posted by jhaverbs
What confused me is that AviOffsetcalc gives a +ve skew, but adds a -ve nuber to the new file name.I agree, the inconsistent signs are confusing. I think it would be better if AVI Offset Calculator picked one convention and stuck with it.
Originally posted by Darkfalz
because the main stream or whatever you want to call it cannot start AFTER the audio or video streams, only before.There are three streams? :confused:

jhaverbs
10th May 2004, 21:28
Originally posted by Darkfalz
Should always be a positive skew (hence you use a negative in VD to offset it), because the main stream or whatever you want to call it cannot start AFTER the audio or video streams, only before.

On occasion I get -ve skew. Video delay of 1 frame and audio offset 2880 sample at 48 HZ. Thn skew = (1/29.97 - 2880/48000)* 1000 = -26.63. Then I use a +ve 26.63 in VD and it sounds synched.

Tell me is this unusual -ve skew or am i still confused about the terminology?

(By the way this is a real capture with avio using ATI AIW 7500 card with MMC9.0)

manolito
18th May 2004, 22:43
More or less by trial and error I found another method that consistently gives me perfect audio / video sync. It uses VirtualVCR and Darkfalz's AVI Offset Calculator.

Let me first explain which other methods I tried before, and why they did not work for me:

Darkfalz's method (no master stream) does not work because for longer movies my capture card and my soundcard drift apart.

VirtualVCR can dynamically resample audio to match the video. This works as long as I capture from a perfect source that does not cause frame drops. Capturing from a badly worn VHS tape with lots of dropped frames ruins sync completely with this approach.

I do get perfect sync when I specify audio as the master stream. However this results in a weird video frame rate. I use DVD2SVCD for encoding, and this requires standard frame rates. (D2S does convert the frame rate, but audio resampling always crashes BeSweet. Resampling audio manually would probably be possible, but I simply don't want to deal with it.)


So here comes my new method:

In VirtualVCR's AV Sync settings I select "Video" as the master stream. I also check "Adjust Stream Offset" and I select "Offset Audio by 0 mS". When I play the captured AVI in Media Player, audio lags behind. All I do now is load the AVI into AVI Offset Calculator and let it eliminate the offsets in the AVI header. The resulting file has perfect sync, no need to correct audio skew in VDub. Since the offsets have been removed, editing the file in VDub does not ruin sync anymore.

I also tried to duplicate these settings in iuVCR (Master stream: Video, Audio Stream Offset: 0 ms <Auto>), but surprisingly it did not work. Maybe the "<Auto>" does some mysterious things...


Anyway, I'd like to know if this method also works with different hardware and drivers. I use a BT848 based Leadtek VC 100 (just a capture card, no TV tuner). My capture driver is iuLab's tweaked BT848 driver. (BTWinCap crashed my machine twice during installation.) I capture in 768 x 556 using the PICVideo MJPEG codec, audio sample rate is 48 kHz.


Cheers
manolito

Deskgrunt
20th May 2004, 20:29
I use iuVCR to capture Huf 704x576 with my AIW 9800pro card and my .avi's are always in sync. Or atleast good enough sync for me not to notice it.

I use:
Standard MUX
Interleave = None
Master stream = Audio
Sync using stream offset
Audio stream offset = 0 (Auto)
Short audio samples

In theory this should set the sync from directshows timestamps.

This seems to work fine for me but the only editing I do is cutting out commercials inside TMPGenc Plus while encoding for DVD.

My offset in iuVCR is usually between 17-100ms, often the first capture gets a high value and the following between 17-30 so I always capture a short file before the main one.