INDEX  F.A.Q.  SEARCH  LATEST POSTS     Rules  Register  Profile  Private messages  Login


Search all forums or this forum: Advanced search
How to fix gradual loss of sync once and for all

Forum Index -> How to's -> User guides Printer-friendly version
Goto page 1, 2, 3  Next
Reply to topic
Author Message
Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 29, 2003 22:30 Posts Comp View users profile Send private message Reply with quote

Ok i guess this topic has been covered quite a few times. So i'll try and make it quick.

Now Phat J's guide did give me some clues, but he overlooked a simpler, more accurate and quicker solution. I guarantee and promise this will work. Basically you need to resample rather than compress or expand the time. The example I've done here works for MPEGs but you could apply the same methods for AVI files.

Unbeknownst to most people I should imagine. Sound cards suggest they are record at 44.1KHz. Well in most cases they probably do. However, sometimes they don't quite sample correctly and are off by about 0.005KHz. This is what causes your gradual sync people. Some guitarists may recognise this if you have a software tuner. You need to calibarate the soundcard to get the perfect tuning.

The method will also work with VHS captures too, even if you capture other sources and they are in sync.


Is everybody in, is everybody in, so let me begin.

You will need:
Sonic Foundry's Sound Forge or Cool Edit (Both are available as demos)
TMPGenc
VirtualDub

1. Similiar to Phat J's guide
Use VirtualDub to find a time in the video to find a noticeable sound. It helps if you can lip-read but it's not essential. Make a note whether the sound is behind or before the video.

Here I've found a frame from the Let It Be film, where John is going to sing the word "Seeeeee" from the song I've Got A Feeling.



Jot the time down, in this case it's 1:16:22.891. The audio is ahead.

2. Use TMPGenc and under MPEG Tools to demultiplex the MPEG file into two separate files. So in this case it would Let It Be.m1v for the video and Let It Be.mp2

3. Open your audio file in Sound Forge (This may take a while if it's huge) and find your jotted time. Play the sound and note the where it's playing.



Here you can see the beginning of the "Seeee" peak and the audio is about 0.939 seconds ahead out of sync.

4. Now here's the amazing part. Instead of expanding or compressing the sound, we're going to adjust sample rate of the sound instead. Under Process you will find an option called Resample.



Make sure you only set the sample rate first only. Here i've added 9Hz because the sound was ahead so it needs to be played ever slightly more quickly. Reduce the sample rate if it's behind. You'll have to tinker with the sampling rate, but you'll find that adding 1 Hz will reduce about 0.1 seconds off over an hour. Don't worry about the pitch change, it's doesn't make a difference due to such a small change.



Now you can see i'm only 0.002 seconds out. This is alot more accurate than the time expand/compression utility. Not only that, you don't have to render the effect to preview, so you don't have to wait ages if you've got a big file. Some soundcards won't play at 41,109Hz but this really isn't a worry.

5. Once you've found the correct sample rate, you need to resample. So this time go back to Process and Resample and clear the box that says: "Set the sample rate only(Do Not Resample") and adjust the new sample rate to 44,100Hz. You don't need to apply an anti-aliasing filter, the resampling difference is so small to justify the time taken to apply the filter. Once you've set it it will start to resample which may take a while.

Now you can see your sound is at 44,100Hz and the sync is damn as near correct as it can be. No amount of time expanding/compression can get this close.

6. Now all you need to do is save the file. You'll have to save it as a Wave File at 44,100Hz Stereo unfortunately, which means mega space, but it'll be worth it.

7. After you've saved it, use TMPGenc to change the wav file into an mp2 file.



8. Use TMPGenc again and goto MPEG Tools and select Multiplex. Here it would be Let It Be.m1v as the video and Let It Be.mp2 as the audio. Choose anything you want as the output file( well make sure you end it .mpg or mpeg)

9. Enjoy your newly synched video.

10. Praise me for wasting hours trying to sort this out once and for all. I really do believe you can't get any more accurate than this method and it works with humungous files.

So to cap off, blame the soundcard, it's not recording at the correct sampling rate it's supposed to. The soundcard in this case actually records at probably about 44,109 to 44,110Hz. Perhaps video capturering software needs to use an audio calibrating utility like guitar tuning software does to help with the sampling rate and synch.

Thanks to Phat J for spurring me a bout of inspiration and thanks all for those in sync-hell. Welcome to uniformity.

Yours in humanity

ACID Agent


Last edited by Acidagent on Jan 31, 2003 15:32, edited 2 times in total


Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 30, 2003 12:15 Posts Comp View users profile Send private message Reply with quote

/me is sad sad.gif no one's praising me for my fantastic efforts in audio department. I should get some Nobel award for this research. We should have VCDHelp medals.

donpedro
member bember


Joined: 05 Aug 2002
Location: EU

Post Posted: Jan 30, 2003 13:41 Posts Comp View users profile Send private message Reply with quote

I will try it wink.gif I will try also that another option smile.gif
_________________
Pinnacle Studio 8 and DV home video editing (ver.9 already home)


Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 30, 2003 15:47 Posts Comp View users profile Send private message Reply with quote

That is most kind sir, tell me how you get on, i'm sure you'll be pleased with the results.

edwags
Member


Joined: 19 May 2002

Post Posted: Jan 30, 2003 19:11 Posts Comp View users profile Send private message Reply with quote

your info looks great. im not very audio knowledgeable. i use cool edit and goldwave any chance you could show how to use one of those? also im not sure of the difference between playback rate and resampling. i tried it with goldwave now my wav is 44090 which i presume wont work as a svcd. thank you ejw

BJ_M
Patron


Joined: 30 Jul 2002
Location: Canada

Post Posted: Jan 30, 2003 19:16 Posts Comp View users profile Send private message Reply with quote

well - its a nice guide you wrote but i mentioned also you can just load the mpeg file (audio and video) into soundforge and view both together (vegas is even better for this) and adjust your audio .. then save out only the new wav (or mp2 file) ..

lpn1160
Member


Joined: 03 Jul 2002
Location: United States

Post Posted: Jan 30, 2003 19:33 Posts Comp View users profile Send private message Reply with quote

where was this guide when I was capping with a USB capture device?? wink.gif Then my audio was always out-of-synch.
Since I bought a PCI card and cap to .avi instead of mpeg2 I haven't had the problem since!! But should I ever run into that problem again I have your guide. Good-job, Well done!!!!!
_________________
"The software said Win XP or better, so I Installed Linux"


Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 30, 2003 20:14 Posts Comp View users profile Send private message Reply with quote

EJW, it looks as if you're getting somewhere. You're right in saying that at 44090Hz it won't be SVCD compatible. I've just downloaded Goldwave.

[EDIT]See my post below about the whole Playback rate issue. Although it really shouldn't be called Playback rate. It may confuse you more, but if you just want to do the job just read below.

To permenantly change the audio file for compatibility and to get it into sync, the first thing you should do in Goldwave is set the "Playback rate" to 44090Hz. Next click Resample and change that to 44100Hz. It should then render the file so that the "correct" recorded sample rate of 44090Hz will be upsampled to the compliant VCD/SVCD sample rate of 44100Hz. The timing will stay the same as 44090Hz, but it will now be a legitimate 44100Hz audio file. Now save your file as a wav file.

Sorry if i've explained that really poorly. I'll give you another example. In ye olden days of computing audio recording was limited to recording at 22500Hz. The quality of 22500Hz recordings is half the quality of a 44100Hz recording. So if you were to set the playback rate of your 22500Hz file to 44100Hz it would play the file at double the speed although the file would still remain a 22500Hz file.

If you were to immediately resample the file, then the 22500Hz would be converted to 44100Hz without the change of speed. If you set the playback rate first and then resample it, you would end up with a file that plays double the original speed and 44100Hz.

BJ_M i didn't even bother at first trying to open the MPEG in Sound Forge or Vegas!!! I overlooked that one. Can you adjust the playback rate of the sound only and then resample it in Vegas. I'll have a look when i get back to my computer tomorrow. The only problem i can predict is that Vegas will have to encode the whole mpeg again, but i guess this might solve a error message i got in TMPGenc when i multiplexed. I'll try to remember what it said, but it worked fine when i played it back.

Sorry Lpn1160.. twas never destined for this guide to come to light any earlier or later in time. Or maybe i was just a lazy bastard wink.gif

I've only really got into video encoding, it's time to get rid of my Hauppauge PCI Card, the quality is pretty terrible for previewing and/or capturing. I wanna watch decent quality TV on my new 17" IIyama LCD screen!!


Last edited by Acidagent on Jan 31, 2003 00:41, edited 2 times in total


BJ_M
Patron


Joined: 30 Jul 2002
Location: Canada

Post Posted: Jan 30, 2003 21:17 Posts Comp View users profile Send private message Reply with quote

no -- dont touch the mpeg file in vegas or soundforge .. your just adjusting audio , render out the audio file only ... the video is loaded in there for refrence only ..

demultiplex existing audio and re-multiplex with new audio after


btw -- sample rate has NOTHING to do with playback rate ..

you are only tricking the audio decoder on how many sample bits are in a stream .. many decoders just would not play .

audio is normally 30fps NDF but you can change that ..

30fps still plays at the same speed as say 24fps .. , just that there are 24 pictures instead of 30 every sec..

audio - the same thing .. except with audio you can more easy to stretch or shrink it ..

sample rates should not be changed for a number of reasons except if nessessary between 44.1 and 48 ...


edwags
Member


Joined: 19 May 2002

Post Posted: Jan 30, 2003 23:16 Posts Comp View users profile Send private message Reply with quote

thanks for all the info i will play around with this on sat. ejw

Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 31, 2003 00:34 Posts Comp View users profile Send private message Reply with quote

BJ_M - I've edited my fourth post to make things a bit clearer. I don't know if it's just me, but I don't think you understand confused.gif . The finished file ends up as a 44.1KHz audio file. Complete compatibility. The decoder will see it as a 44.1KHz file.

44090Hz was what the audio was really recorded by the soundcard but encoded at 44100Hz and so hence it goes out of sync. So we need to set the sample rate back to 44090Hz and then upsample and encode it from that to 44100Hz.

The "playback rate" at 44090Hz will seem to "play" slower(although it really always plays at the same speed of 30 fps) when actually the audio has been expanded(if you saved the file now, it would be a 44090Hz file and incompatible)!!!

However Goldwave is tricked into thinking it now has a sample rate of 44090Hz. Since Goldwave now thinks the sample rate is 44090Hz you can now upsample from 44090Hz(which is taken from the adjusted "playback rate" in Goldwave) to 44100Hz. You end up with a file which is 44100Hz, in sync and compatible.

I agree playbackrate is a totally different thing. Goldwave is a bit silly really, instead of calling it the playback rate, they should change it to "set sample rate only" instead, to clear things up like Sound Forge. Playback rate to me suggests 1x 2x speed settings, rather than using Hz.

I hope this clears a few things up. BJ_M i don't know if you believe me, but i promise you what i'm doing is 100% compatible and in-sync. Maybe i'm just not explaining it well enough.


BJ_M
Patron


Joined: 30 Jul 2002
Location: Canada

Post Posted: Jan 31, 2003 00:51 Posts Comp View users profile Send private message Reply with quote

ok my error then -- i didnt understand and perhaps didnt read your post through enough ...

don't get me wrong either ... its great that you have taken the time to put this together and worked it all out ... very nice work ..


drewson99
DigiMember


Joined: 02 Jun 2002

Post Posted: Jan 31, 2003 00:57 Posts Comp View users profile Send private message Reply with quote

vcdhelp medals, heh. i second that motion.

Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 31, 2003 15:34 Posts Comp View users profile Send private message Reply with quote

Thanks BJ_M i knew we'd get there eventually. Explaining sampling is not the easiest subjects to deal with.

vitualis
Moderator


Joined: 01 Oct 2000
Location: Australia

Post Posted: Jan 31, 2003 16:03 Posts Comp View users profile Send private message Reply with quote

Acidagent wrote:
Unbeknownst to most people I should imagine. Sound cards suggest they are record at 44.1KHz. Well in most cases they probably do. However, sometimes they don't quite sample correctly and are off by about 0.005KHz. This is what causes your gradual sync people. Some guitarists may recognise this if you have a software tuner. You need to calibarate the soundcard to get the perfect tuning.


Actually, there are many other reasons for gradual sync issues -- codec problems, muxing problems, etc.

Unless you have a capture card that locks the video clock and audio clock together, you will often have drift between the video and audio. This isn't necessarily a problem, however, as a good capture program (e.g., VirtualDub) will drop the necessary frames to keep A/V sync...

As for "awards", the mods have suggested creating a "karma" rating system... However, it is not that easy to implement. Until it actually comes into being, I give you positive karma points for you guide! wink.gif

Regards.
_________________
Michael Tam
vitualis' Medical Rant :: stay updated, read the rant
The Medicine Box
GNU VCDImager Authoring Guide Series


Bizuser
Member


Joined: 21 Dec 2002
Location: Bay Area, CA, USA

Post Posted: Jan 31, 2003 19:29 Posts Comp View users profile Send private message Reply with quote

Acidagent - I came across this guide, and subsequent thread, because you posted in a thread I was participating in. You pointed people over here to solve audio drift problems. My issue is that I get audio 'drift' (starts great; ends up 2 seconds out after 30 mins), so I came over here to read your guide.

My situation is that I can capture video at 352x240 using ATI, direct to MPEG 1; The MPEG1 file plays great in ATI file player - no synch issues. I can also author the mpeg file as VCD using VCDEasy and get a decent VCD file that plays on my standalone.

Then I tried to capture video at 480x480, direct to MPEG-2. The MPEG 2 file plays great in ATI file player - no synch issues. When I author this file to SVCD, I get lots of errors (encoding errors). I then demux/remux using TMPG, author as SVCD (no encoding errors), and get an output file that has the audio drift.

So - referring to the post of the moderator, and your posts/guide, would you think I'm experiencing the problem you are addressing (poor clock / timing attributes of the audio stream), or, problems with the codec, muxing problems, etc? My hunch is that I'm experiencing Muxing or codec issues, since my audio is in synch on captures with certain settings. Only falls apart when I capture to MPEG2, and/or at certain settings, and process the files.

Of course, I'll give the audio cleanup a shot. I have beSweet - that should be usable, should it not? I'd rather not learn yet another audio program!!

Thanks for the guide.


Acidagent
Member


Joined: 24 Jan 2003

Post Posted: Jan 31, 2003 23:26 Posts Comp View users profile Send private message Reply with quote

Vitualis - Yep you're right, i was a bit carried away with the moment thinking i found the sole cause to gradual sync problem laugh.gif But resampling should help a lot of people out whether it be the soundcard or the codec, etc. We all need aid to get us some decent capture cards.

It's about time i got some good karma, although it worries me cos now i've got good karma somewhere along the line will come the bad karma biggrin.gif

Bizuser - I'm guessing that its ATI's MPEG2 codec which is a bit buggy when it comes to compliancy. The same goes for Cyberlink's too in PowerVCR. I think it's probably down to them trying to save processing power or cutting corners because they capture in realtime but their players can regonise and correct this.

I've had a look at beSweet and it doesn't look the most useable of programs but it's in its early days by the looks of things. beSweet seems to be more of a channel converter. You really need to see the data to see where the sound fits in. I really suggest you try the Sound Forge Demo or Goldwave demo. Personally i'd go for Sound Forge but Goldwave is a lot smaller and quicker to download.


mazinz
Killer Pirate


Joined: 21 Jul 2001
Location: NY

Post Posted: Feb 01, 2003 14:34 Posts View users profile Send private message Reply with quote

thanks for the newer info this would expalin a lot. Actually i have heard of this before and if you use soundforge to cpature it has the option of properly caliberating your sound card to fix any speed problem it migt have.
i just did 2 dvd projects and had 2 audio tracks for each. Long story short, i have soundblaster 2k and it has the rate at 48k for dvd, anyway whatever i ran in would NEVER properly sync up to the video source already on my pc or the other sound itself.
it was driving me nuts and i did some side by side to make sure my source and sound were playing the same speeds which they were.
thanks for the info check on the resample rate to fix that issue.


Valnar
Member


Joined: 01 May 2001

Post Posted: Feb 01, 2003 17:50 Posts View users profile Send private message Reply with quote

My 2 cents for analog source captures:

Of course, one way to fix sync is to capture it in sync in the first place! PCI drift is definitely caused by the fact the sound card and video capture board (or USB, or whatever) aren't keeping track of each other with any time code. So you need software to do it for you.

If you use Windows 9x, then AVI_IO is the best program. It drops or adds blank frames to adjust for the sound drift.

If you have Win2K/XP and all WDM driver based hardware, then the best capture app is Virtual VCR at www.digtv.ws. It can resample the audio dynamically to keep sync with the video. We're talking less than .01% so not even somebody with perfect pitch can hear the difference. The only other 32-bit Windows program that keeps audio in sync correctly is Showshifter, but its not freeware.

I capture all my VHS tapes with VirtualVCR. As long as you set it up right, then you'll have perfect captures every time.

Proper settings under the AV tab are:
* Check: Resample Audio & Resample audio dynamically
* No Check: Adjust Stream Offset


-Robert


dark_knight_br
Member


Joined: 29 Jan 2003

Post Posted: Feb 02, 2003 10:03 Posts View users profile Send private message Reply with quote

Hey!
What should I do if my synch problem is the video, not the audio?
I have a video at 24.021 fps and I have to convert it to 29.97 fps, so I can watch it in my standalone dvd player.
And doing the conversion, the video becomes like 15 minutes shorter. I can easily fix the audio to match that lenght and have no synch problems. But that video is a concert, and that change in the lenght really screws it up.
So, how do I convert the framerate without changing the lenght?


kenmo
Member


Joined: 27 Dec 2002
Location: Canada

Post Posted: Feb 02, 2003 10:20 Posts Comp View users profile Send private message Reply with quote

Valnar wrote:
My 2 cents for analog source captures:

Of course, one way to fix sync is to capture it in sync in the first place! PCI drift is definitely caused by the fact the sound card and video capture board (or USB, or whatever) aren't keeping track of each other with any time code. So you need software to do it for you.

If you use Windows 9x, then AVI_IO is the best program. It drops or adds blank frames to adjust for the sound drift.

If you have Win2K/XP and all WDM driver based hardware, then the best capture app is Virtual VCR at www.digtv.ws. It can resample the audio dynamically to keep sync with the video. We're talking less than .01% so not even somebody with perfect pitch can hear the difference. The only other 32-bit Windows program that keeps audio in sync correctly is Showshifter, but its not freeware.

I capture all my VHS tapes with VirtualVCR. As long as you set it up right, then you'll have perfect captures every time.

Proper settings under the AV tab are:
* Check: Resample Audio & Resample audio dynamically
* No Check: Adjust Stream Offset


-Robert


I could not agree more. VirtualVCR is the best capture program bar none. I've been using it since Christmas and I capture at least two hours of video daily (Star Trek Voyager shows on two stations in Halifax daily) and I only had one instance where video was out of synch. This was due to audio noise during the shows broadcast. This is one awesome piece of software. Strongly recommend it.

Getting the best results ever from my ATi TV Wonder (pci version and not VE version).


mazinz
Killer Pirate


Joined: 21 Jul 2001
Location: NY

Post Posted: Feb 02, 2003 16:33 Posts View users profile Send private message Reply with quote

for the record my card is the dazzle 2 (dvc2) i also have a tbc so my issues are not cpaturing. Sometimes i ripped a certain dvd and looked at the aiudio, yours truly made some commentaries for my own benefit to add on the actual disc. So iwould just run in the sound as thats what was only recored (via the mic input, as its just me tlaking), but i have eveerything on key and due to the sound card it would throw off the sync and now i know why

Bizuser
Member


Joined: 21 Dec 2002
Location: Bay Area, CA, USA

Post Posted: Feb 02, 2003 18:04 Posts Comp View users profile Send private message Reply with quote

(I'm the poster who complained of audio synch problems with ATI AIW, using direct-to-MPEG2).

Yesterday I experimented with adjusting the audio stream. I used 'WLA' (wavelength adjust), and found that my audio and video were finally in synch - but the process for me is tedious based on the tools I'm using (demux; convert audio to wav; adjust length of audio; convert back to mpa; remux). I know it could be easier if I used recommended tools, but anyway I proved the point. FYI, for me, I adjusted from 44100 to 44200, NOT to 44095 - but it seems somewhat random. Rather than go through this whole process (since I also have difficulty cutting these native mpeg2 files) ...

Today I experimented with both PicVideo MJPEG and Huffyuv codecs in VDub. While the Huffyuv results were very good, the size is extremely large. MJPEG, at setting '18', seems to be giving me great quality AND manageable sizes (2 gig for 20 minutes). I then use avisynth to frame-serve the AVI to TMPG. So at this point, I'm thinking of giving up on the MPEG2, even though it's great compression and good video quality.

Now you bring up virtualVCR ... I'll definitely give it a try. I see, from reading the website, that it too requires/recommends MJPEG or Huffyuv codecs; so ... if I'm getting good results with Vdub+MJPEG and Huffyuv, what may I expect that's better with virtualVCR? From reading here, I'm guessing that VirtualVCR adds the audio clock-synching feature. Ironically, I don't seem to be getting audio synch problems in the first place once I use VDub!

Thanks everyone for the help!


Bizuser
Member


Joined: 21 Dec 2002
Location: Bay Area, CA, USA

Post Posted: Feb 02, 2003 18:13 Posts Comp View users profile Send private message Reply with quote

Dark Knight jr:
Quote:
What should I do if my synch problem is the video, not the audio?
I have a video at 24.021 fps and I have to convert it to 29.97 fps, so I can watch it in my standalone dvd player.
And doing the conversion, the video becomes like 15 minutes shorter


There are many 'standard' ways to handle this.