Search Polybore

Monday, May 12, 2008

AVI file sound out of sync with video solution.


I can happily say that this method using virtualdubmod to sync sound with video in an AVI file works a treat. This problem had been driving my wife and I mad for months, we were constantly starting and stopping videos to try and get them back into sync.
We tried all our video software, VLC, windows media player and powerdvd but always the film would end up like a badly dubbed foreign language movie.

1. Load your completed avi (with out of sync sound) into virtualdubmod
2. Go to File, then 'File Information'. In the video details, look at the length. Compare that to the length in the audio details.
3. Take the difference and multiply by 10 (because we need to know how many miliseconds (thousandths of a second) not the hundredth of a second shown here).
4. Click OK
5. In the 'Video' menu, ensure 'Direct Stream Copy' is selected
6. Got to 'Streams' and them 'Stream list'. There should only be one stream listed there, as 'AVI audio stream 1'. Right click on that stream an ensure 'Direct Stream Copy' is selected.
7. Right click on the stream again and go to 'Interleaving'
8. In the box labeled 'Delay audio track by', enter the number you worked out before (difference between the 2 lengths, multiply by 10).
9. Click OK and then OK again
10. Go to 'File' and 'Save As'. give it a file name (don't overwrite the other file, just in case). Click save.

You can get virtualdubmod from http://virtualdubmod.sourceforge.net/

Click here for video tutorial I cooked up using Captivate and my new fav thing, screen-o-matic!
http://www.screencast-o-matic.com/watch/cjhlYgVt2

15 comments:

  1. Hello polybore.

    You recently answered a question on Y. Answers and it worked! Thanks for that, but now I seem to have a new problem and I am unsure what the cause is, or maybe it's been there all along.

    I successfully "synced" my audio/video at the start, but I noticed after watching the rest of it, the audio was then once again ahead of the video. This clip is only a minute long, and am doing trial runs and fix-ups in order to maintain the other recording of lengths 5-10 minutes.

    Would my remaining problem have to do with my capture card, frames dropping, or would you have yet another helpful tip?

    virtueq3@hotmail.com

    ReplyDelete
  2. I use a http://www.hauppauge.co.uk/pages/products/data_pvrusb2.html to record TV to my HTPC http://polybore.blogspot.com/2008/05/home-entertainmentorium.html(which is far lower spec than your PC) and I dont have any video sync problems. I've never used it to record off of a console but if it can do TV ok then a console should not be a problem.

    The only thing I can think to try is to use different software to record e.g. windows movie maker providing it detects your capture device.

    You could try recording a video off of the VCR. If that also had out of sync audio then you could place the blame on the dazzle device

    ReplyDelete
  3. Need to upload a screen recording Polybore? You could do worse than have look at screencast-o-matic.com

    It lets you make crystal clear screen recordings and hosts them for nowt. Uses Java.

    ReplyDelete
  4. Wow. Excellent. Thanks for that Beech.

    ReplyDelete
  5. I swear to god polybore...i'd marry you if i could. beautiful I can now watch my movies...with the sound right, and i'm half deaf so that shit drives me nuts

    ReplyDelete
  6. I worked for hours on trying to fix mp4 videos from google video that had the audio sync drift (gets worse as the video goes on). Instead of just realigning using the above technique, I had to:

    1. use virtualdub to save the audio and video separately.
    2. use 'super' to convert the audio from mp3 to wav.
    3. use "Wavefile Length Adjust" to stretch the audio to the same length as the video (virtualdub tells you both durations and you give them as a ratio to WLA.)
    4. use 'super' to convert the wav back to mp3.
    5. use "AVI-Mux" to put the video back together!

    ReplyDelete
  7. Nice fix rerintoul, thanks for that.

    ReplyDelete
  8. I feel compelled to add one last thing (I spent so long on this!). I was ultimately trying for divx so this would play in my dvd player. Step 5. put the file back together but it wasn't a valid divx file. Step 6. was to run the file back through 'super' using video stream copy and recode the audio to produce a valid divx. At least that part was very fast.

    ReplyDelete
  9. rememeber to read the warning about variablre bitrate audio, something you should to is, first re-encode the stream them try to ... "guestimate" the correct offset. it can take a while but generally should take more than 15 minutes unless the file is HUGE

    ReplyDelete
  10. Hi

    Im having problems with audio/video sync of my AVI file

    I tried to follow your tutorial, I got to number 6 but I dont seem to have a 'stream' or 'streams list' on my virtual dub

    Can someone help me out as its driving me up the wall

    feel free to email me or add me on MSN

    fatboystwin@hotmail.com (please put a little note as I get alot of spammers trying to add me)

    Thanks
    Marc

    ReplyDelete
  11. Hi Fernando, looks like VirtualDubMode is different from Virtual Dub.

    On it's download site it says: 'VirtualDubMod is based on the famous video editing software VirtualDub by Avery Lee'.

    Get VirtualDubMode and try these steps... I'm still going to try them. Thanks in advance guys.

    ReplyDelete
  12. rerintoul: VirtualDub can decompress and recompress audio on the fly if you choose full processing and select compression in the Audio menu. No need to use all those other tools.

    So, in order to linearly stretch or shrink your audio stream, you can do this:

    1. Select Full processing mode for audio and no compression (PCM)

    2. Save WAV

    3. Stretch/shrink the WAV with Wavefile Length Adjust

    4. Back in VirtualDub select Audio from other file (the file from the previous step), Full processing mode, and whatever compression you want your final AVI to have

    5. Save as AVI


    Unfortunately, in my case even this didn't help: although beginning and end were synced, everything in between was all over the place...

    ReplyDelete
  13. Hello,
    My problem is:
    my ~.ts is with errors, while I play - everything is fine, but after recompress to ~.AVI sound start to delay..
    By using this manual I adjust sound on the end, but after that sound lose sync in the beginning :(

    ReplyDelete
  14. I used VirtualDub instead of VirtualDubMod simply because it worked with it using VLC Media Player to find out the exact value to insert under audio skew correction in VirtualDub. What I did was:

    1. Open/Play the video file with VLC Media Player. (Right click your video file/highlight Open With/Click VLC media player.

    2. Use the J and K keys (J = negative and K = positive) on the keyboard to adjust the audio sync during playback (the values are displayed on screen)to figure out the exact value that is in sync with the video to type into VirtualDub.

    3. Remember/Write the exact value that is in sync with the video.

    4. Open the video file with VirtualDub. (Open VirtualDub/click File/click Open video file/click your video file/click Open).

    5. Click Video/click Direct stream copy

    6. Click Audio/(Direct stream copy should already be selected)if not, click Direct stream copy.

    7. Click Audio/click Interleaving/Under Audio skew correction, type in the exact value as discovered using VLC Media Player/click OK.

    8. Save your video file. Click File/click Save as AVI/Click a location to save your video file to/click save.

    Using the method above has worked perfectly for me.

    Using VirtualDub to find out the value
    by subtracting and then multiplying the difference by 10 gave me these results:

    1. Under File Information, the length of the video was 1:15:57.45 and the length of the audio was 1:15:57.48. The audio was playing too early. So the value selected must be positive.

    2. When subtracting 1:15:57.45 from 1:15:57.48 you get 3. Multiplying 3 by 10 gives you 30.

    3. When inserting the value as positive 30 under Audio skew correction and saving the file, the length of the video and the length of the audio are now the same: 1:15:57.45, however the audio is still out of sync with the video.

    4. If I take the difference, which is 3, and multiply it by 100, it gives me 300.

    5. Now when inserting the value as positive 300 under Audio skew correction and saving the file, the length of the video and the length of the audio are also the same: 1:15:57.45, but the audio and video are now in sync.

    Math is definitely not my strong suit, so I must ask, why must I multiply the difference by 100 instead of 10 as you suggested to get the correct value that is in sync with the video?

    To add, when using VLC Media Player to find out the correct value, the value displayed on the screen when using the J and K keys to adjust to proper audio and video sync was also positive 300.

    ReplyDelete
  15. thank a lot what i always did was looking for another copy... but better to know how to do it

    ReplyDelete