Automate Everything: Ruby, Linux and other hints, tips and tricks.

How to fix audio synchronization of an AVI on Linux

I just downloaded an AVI file with audio out of sync. Everything sounded one second before it should during the whole movie so it was really annoying. Fixing this with mencoder is easy and fast.

mencoder video.avi  -oac copy -ovc copy  -delay -1 -o video-fixed.avi

That will delay sound for one second. Notice that “-1″ represents a negative value, so you could write “2.5″ to advance (not delay) audio for 2 seconds and a half.

Here comes the tedious part. How do I know how much do I have to delay audio? What I did is trial and error. But don’t scream yet it’s not as horrible as it sounds. You can make tries less painful encoding just the first 150 seconds of video adding “-endpos 150″:

mencoder video.avi  -oac copy -ovc copy  -delay -1 -endpos 150 -o video-fixed.avi

You can follow any responses to this entry through the RSS 2.0 feed.