[MPlayer-users] introducing DVD-to-DivX approach that fixes A/V sync problems

Joachim Jautz lists.mplayer-users at jay-jay.net
Sun Jul 3 19:35:00 CEST 2005


Hi MPlayer Users,

when converting a DVD into DivX using MEncoder it can (under
certain circumstances) happen that the resulting movie's audio and
video are out of sync. Usually the delay is about 300ms which is
enough to be annoying.

The purpose of this mail is to introduce my solution to this
problem for those who are interested.

When I myself ran into this problem in early 2004 there was
neither a definitive explanation why this problem sometimes
occures nor a good solution except one: encode and mix audio and
video at once.
But this solution was inacceptable for me because I wanted to
encode the video only once and then mix it with different audio
tracks.
After days of experimenting I finally came to the solution that
extracting the audio track to a wave file and then re-including it
while encoding is doing the trick (example follows below).

Since then I successfully use this method and therefore can call
it `thoroughly tested' with MPlayer/MEncoder 1.0pre5-2.95.4 .
I extended my dvd2divx script so that it works according to that
solution; it is available at:

http://www.jay-jay.net/src/bash/dvd2divx/index.html

A nice side effect of this method is that the dumped wave file can
be manipulated before it is re-included. Personally I normalize
all movies' audio tracks because they are usually too quiet and
their peak volume almost never reaches 100%.


Example
=======

Some annotated example commands follow in order to illustrate my
method.


AUDIO STEP
# for each language chosen the script will execute this step (with
# different -alang parameter etc.)

# this example dumps the german audio track into a wave file
mplayer dvd://1 -dvd-device ~/tmp/some_movie_data -alang de
-ao pcm -aofile ~/tmp/some_movie--pcmdump.de.wav -waveheader
-noframedrop -vc dummy -vo null

# the frameno.avi is created from the previously dumped wave file
# with -mc 0 to disable MEncoder's A-V sync correction
mencoder dvd://1 -dvd-device ~/tmp/some_movie_data
-o ~/tmp/some_movie--frameno.de.avi
-audiofile ~/tmp/some_movie--pcmdump.de.wav -mc 0
-ovc frameno -oac mp3lame -lameopts abr:br=128


VIDEO STEP
# nothing spectacular here but note the -nosound option

# video encoding, pass 1
mencoder dvd://1 -dvd-device ~/tmp/some_movie_data
-o /dev/null -nosound -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1118:vhq:vpass=1
-vf crop=700:550:8:12,scale=688:368

# video encoding, pass 2
mencoder dvd://1 -dvd-device ~/tmp/some_movie_data
-o ~/tmp/some_movie--video.divx.avi -nosound -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1118:vhq:vpass=2
-vf crop=700:550:8:12,scale=688:368


MIX STEP
# not shown here: when creating movies in multiple languages
# each iteration of the mix step creates a symbolic link named
# `frameno.avi' (as expected by mencoder) that points to the
# appropriate language's audio track

# mix audio and video
mencoder -o ~/movies/some_movie.de.divx.avi
-oac copy -ovc copy ~/tmp/some_movie--video.divx.avi



Summary
=======

This message is meant to provide an overview. For further details
please follow the URL mentioned above and read the documentation
(especially the sections where the AV_SYNC_FIX option (aka Mode 2)
is explained).

Thanks for reading. I hope it helps someone with A/V sync
problems. If the method introduced here is obsolete for the latest
releases (e.g. MEncoder's internals have changed after 1.0pre5
with respect to this) please let me know.
Of course, any other comments are welcome, too.


Joachim




More information about the MPlayer-users mailing list