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

Joachim Jautz lists.mplayer-users at jay-jay.net
Sat Jul 9 17:09:54 CEST 2005


[this is a summary of the results so far]

As this thread has become quite long and contains valuable
information I decided to write a summary of the results so far.
Thanks to all who contributed, you will see that your proposals
and concerns have been considered.


The Requirements:
=================

- the video is to be encoded only once (in two passes, of course)
- multiple audio tracks (e.g. `en' and `de') are desired and
  should be MP3 encoded
- each desired audio track leads to one stand-alone movie file
- target format is MPEG4 / DivX5


Some results of the discussion:
===============================

- the old method utilizing frameno.avi is considered a Bad Thing
  now.
- re-muxing the video with another audio track and thus creating
  several language versions is possible if one obeys some rules
  (details follow).
- increasing audio volume to maximize peak will result in
  distortion; some trade-off still has to be found (e.g.
  `moderate' increase of volume level || no manipulation and gain
  on playback only || ...).
  As the manipulation of audio volume was not the main subject in
  my original posting, I'll put that aside for the moment. Maybe
  this is better discussed in its own thread.


Methods that should work:
=========================

Overview:
Methods 1.* all use -oac copy during video encoding,
Method 2 includes sound from an external source.



*** Method 1.0

quoting Rich Felker:
> Encode with -oac copy or -oac pcm, then once you have your
> almost-final file, reencode it with -mc 0 -noskip -oac mp3lame
> -ovc copy. I _think_ this will work, but not sure.

A more detailed step by step example of this method is attached.

This worked quite well so far but I tested other methods more
thoroughly because a big drawback of this method is that we have
to guess the final audio size. This makes it hard to create movies
with a size of n*700MB.



*** Method 1.1

quoting Martin Collins:
> First split out the audio tracks and process them as you please.
> [...] Then encode the video using -oac copy to maintain sync.
> Then mux your audio into the video replacing the copied audio.
> You can do this for each language.

A more detailed step by step example of this method is attached.

This one is similar to Method 1.0 but the MP3 is created by
running lame externally. This should be done before encoding the
video so that the appropriate video bitrate for a certain target
file size can be calculated based on the audio file size.
In a last step the MP3 audio is included with ... -mc 0 -noskip
-audiofile <mp3-file> -oac copy ...



*** Method 1.2

A variant of 1.1: The only difference is that when encoding the
video "-oac copy" is replaced by "-nosound".
Don't shoot me, I know, in theory this may lead to A/V sync
problems but in my tests (with only three different DVDs, I admit)
this method yielded the same results (in one case even better),
although it was hardly possible to notice the difference to the
previous method.
I cannot generally recommend this method because from the
theoretical point of view this may loose A/V sync.



*** Method 2

quoting Rich Felker:
> Dump the audio with mplayer -ao pcm and encode it with external
> lame. Then run mencoder with -audiofile lame_output.mp3 -oac copy
I assume the last sentence implies "... when encoding the video".

A more detailed step by step example of this method is attached.
For two out of the three tested DVDs this worked perfectly well.

But for one of them the result was totally out of sync (one
duplicate frame every ~1/2 sec). I attached the log file that
was created during this failed test.
I had to add -mc 0 -noskip in order to get it in sync but that's
probably not the intended procedure.



Joachim
-------------- next part --------------
#
# METHOD 1.0
#
# In this example, only chapter 1 is processed but the -chapter
# option can simply be left out, of course.
#
#----------------------------------------------------------------
# dump desired audio track to a wave file
mplayer dvd://2 -dvd-device data -chapter 1-1 -alang en -ao pcm
-aofile pcmdump.en.wav -waveheader -vc dummy -vo null


#----------------------------------------------------------------
# calculate the video bitrate that leads to the desired target
# file size:
#                 $videosize * 8
# $videobitrate = --------------
#                 $length * 1000
#
# $videosize in bytes, $length in seconds, $videobitrate in kbit/s
#
# (equation was taken from mplayer manual encoding tips,
# contributed by Moritz Bunkus)
#
# The only thing we do not know is $videosize because it is
# $targetsize - $audiosize and the latter is unknown.
# There are two possibilities:

# (1) encode the pcmdump into MP3 in order to get its file size
#     and then throw it away

# this will show that pcmdump.en.abr.mp3 is 7004112 bytes long
lame --abr 128 --quiet pcmdump.en.wav pcmdump.en.abr.mp3
# our example $targetsize is 70MB => in bytes?
70 * 1024**2 == 73400320
# $targetsize - $audiosize = $videosize
73400320 - 7004112 == 66396208
# put in the equation above gives us $videobitrate
(66396208 * 8) / (469 * 1000) == 1132.56

# (2) guess $audiosize (works only with ABR or CBR)
#     Example assumes using 128kbit/s ABR later:

# convert 128kbit/s to bytes/s
128000 / 8 == 16000
# calculate $audiosize (our example chapter 1 length is 469 sec)
16000 * 469 == 7504000
# $targetsize - $audiosize = $videosize
73400320 - 7504000 == 65896320
# put in the equation above gives us $videobitrate
(65896320 * 8) / (469 * 1000) == 1124.03

# ==> slightly different results because lame's output has an
#     average bitrate of about 119 kbit/s in this example, thus
#     (2) will usually be inaccurate.

#----------------------------------------------------------------
# encode video with -oac copy for maintaining A/V sync
mencoder dvd://2 -dvd-device data -chapter 1-1 -o /dev/null
-oac copy  -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1132:mbd=2:vpass=1
-vf crop=716:552:4:16,scale=704:368

mencoder dvd://2 -dvd-device data -chapter 1-1 -o video.avi
-oac copy  -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1132:mbd=2:vpass=2
-vf crop=716:552:4:16,scale=704:368


#----------------------------------------------------------------
# mux dumped audio into the movie, replacing previously copied
# audio stream, and encode with lame on the fly.
# adding -mc 0 -noskip is obligatory to disable mencoder's
# built-in A/V sync correction.
mencoder -o movie.en.avi  -mc 0 -noskip
-audiofile pcmdump.en.wav -oac mp3lame -lameopts abr:br=128
-ovc copy video.avi

-------------- next part --------------
#
# METHOD 1.1
#
# In this example, only chapter 1 is processed but the -chapter
# option can simply be left out, of course.
#
#----------------------------------------------------------------
# dump desired audio track to a wave file
mplayer dvd://2 -dvd-device data -chapter 1-1 -alang en -ao pcm
-aofile pcmdump.en.wav -waveheader -vc dummy -vo null


#----------------------------------------------------------------
# encode the pcmdump into MP3 using VBR (or CBR / ABR if you like)
lame -v --quiet pcmdump.en.wav pcmdump.en.vbr.mp3

#----------------------------------------------------------------
# calculate the video bitrate that leads to the desired target
# file size:
#                 ($targetsize - $audiosize) * 8
# $videobitrate = ------------------------------
#                       $length * 1000
#
# $targetsize, $audiosize in bytes, $length in seconds,
# $videobitrate in kbit/s


#----------------------------------------------------------------
# encode video with -oac copy for maintaining A/V sync
mencoder dvd://2 -dvd-device data -chapter 1-1 -o /dev/null
-oac copy  -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1132:mbd=2:vpass=1
-vf crop=716:552:4:16,scale=704:368

mencoder dvd://2 -dvd-device data -chapter 1-1 -o video.avi
-oac copy  -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1132:mbd=2:vpass=2
-vf crop=716:552:4:16,scale=704:368


#----------------------------------------------------------------
# for each desired language:
# mux lame-encoded audio into the movie, replacing previously
# copied audio stream.
# adding -mc 0 -noskip is obligatory to disable mencoder's
# built-in A/V sync correction.
mencoder -o movie.en.avi  -mc 0 -noskip
-audiofile pcmdump.en.vbr.mp3 -oac copy
-ovc copy video.avi

-------------- next part --------------
#
# METHOD 2
#
# In this example, only chapter 1 is processed but the -chapter
# option can simply be left out, of course.
#
#----------------------------------------------------------------
# dump desired audio track to a wave file
mplayer dvd://2 -dvd-device data -chapter 1-1 -alang en -ao pcm
-aofile pcmdump.en.wav -waveheader -vc dummy -vo null


#----------------------------------------------------------------
# encode the pcmdump into MP3 using VBR (or CBR / ABR if you like)
lame -v --quiet pcmdump.en.wav pcmdump.en.vbr.mp3


#----------------------------------------------------------------
# calculate the video bitrate that leads to the desired target
# file size:
#                 ($targetsize - $audiosize) * 8
# $videobitrate = ------------------------------
#                       $length * 1000
#
# $targetsize, $audiosize in bytes, $length in seconds,
# $videobitrate in kbit/s


#----------------------------------------------------------------
# encode video including the MP3 encoded audio
mencoder dvd://2 -dvd-device data -chapter 1-1 -o /dev/null
-audiofile pcmdump.en.vbr.mp3 -oac copy  -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1132:mbd=2:vpass=1
-vf crop=716:552:4:16,scale=704:368

mencoder dvd://2 -dvd-device data -chapter 1-1 -o movie.en.avi
-audiofile pcmdump.en.vbr.mp3 -oac copy  -ovc lavc
-lavcopts vcodec=mpeg4:vbitrate=1132:mbd=2:vpass=2
-vf crop=716:552:4:16,scale=704:368


#----------------------------------------------------------------
# [optional] for each additional language:
# dump and encode another audio track and then mux it into the
# movie, replacing previously included audio stream.
mencoder -o movie.de.avi  -mc 0 -noskip
-audiofile pcmdump.de.vbr.mp3 -oac copy
-ovc copy movie.en.avi

-------------- next part --------------
MEncoder 1.0pre5-2.95.4 (C) 2000-2004 MPlayer Team

CPU: Advanced Micro Devices Duron Spitfire 933.1 MHz (Family: 6, Stepping: 1)
Detected cache-line size is 64 bytes
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 0 SSE2: 0
Compiled for x86 CPU with extensions: MMX MMX2 3DNow 3DNowEx

Reading /home/odin/.mplayer/codecs.conf: Can't open '/home/odin/.mplayer/codecs.conf': No such file or directory
Reading /usr/local/etc/mplayer/codecs.conf: Can't open '/usr/local/etc/mplayer/codecs.conf': No such file or directory
Using built-in default codecs.conf.
File not found: 'frameno.avi'
Failed to open frameno.avi
Reading config file /home/odin/.mplayer/mencoder: No such file or directory
libdvdread: Couldn't find device name.
Font /home/odin/.mplayer/font/font.desc loaded successfully! (206 chars)
Reading disc structure, please wait...
There are 6 titles on this DVD.
There are 17 chapters in this DVD title.
There are 1 angles in this DVD title.
DVD successfully opened.
success: format: 0  data: 0x0 - 0x1BA15000
MPEG-PS file format detected.
Audio file detected.
VIDEO:  MPEG2  720x576  (aspect 3)  25.000 fps  7530.0 kbps (941.2 kbyte/s)
[V] filefmt:65536  fourcc:0x10000002  size:720x576  fps:25.00  ftime:=0.0400
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1  (-1=autodetect) osd: 1
Opening video filter: [scale w=704 h=368]
Opening video filter: [crop w=716 h=552 x=4 y=16]
Crop: 716 x 552, 4 ; 16
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 720 x 576 (preferred csp: Mpeg PES)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
The selected video_out device is incompatible with this codec.
VDecoder init failed :(
Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.3.1
Selected video codec: [mpeg12] vfm:libmpeg2 (MPEG 1 or 2 (libmpeg2))
==========================================================================
audiocodec: framecopy (format=55 chans=2 rate=48000 bits=16 bps=0 sample=0)
Writing AVI header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
VDec: vo config request - 720 x 576 (preferred csp: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
SwScaler: reducing / aligning filtersize 6 -> 4
SwScaler: reducing / aligning filtersize 6 -> 4
SwScaler: reducing / aligning filtersize 7 -> 6
SwScaler: reducing / aligning filtersize 7 -> 6

SwScaler: BICUBIC scaler, from Planar YV12 to Planar YV12 using MMX2
videocodec: libavcodec (704x368 fourcc=58564944 [DIVX])
High quality encoding selected (non real time)!
Pos:   0.0s      1f ( 0%)   0fps Trem:   0min   0mb  A-V:0.000 [0:0]
Pos:   0.0s      2f ( 0%)   0fps Trem:   0min   0mb  A-V:-0.004 [0:0]
Pos:   0.1s      3f ( 0%)   0fps Trem:   0min   0mb  A-V:-0.008 [0:0]
Pos:   0.1s      4f ( 0%)   0fps Trem:   0min   0mb  A-V:-0.012 [0:0]
Pos:   0.2s      5f ( 0%)   0fps Trem:   0min   0mb  A-V:-0.016 [0:0]
--
Pos:   0.7s     18f ( 0%)   0fps Trem:   0min   0mb  A-V:-0.068 [0:106]
Pos:   0.7s     19f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.072 [0:107]
Pos:   0.8s     20f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.076 [0:107]
Pos:   0.8s     21f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.080 [0:107]
Pos:   0.8s     22f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.084 [0:108]

1 duplicate frame(s)!
Pos:   0.9s     23f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.048 [0:108]
Pos:   1.0s     24f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.052 [0:110]
Pos:   1.0s     25f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.056 [0:111]
Pos:   1.0s     26f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.060 [1116:112]
Pos:   1.1s     27f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.064 [1142:113]
Pos:   1.1s     28f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.068 [1151:113]
Pos:   1.2s     29f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.072 [1154:113]
Pos:   1.2s     30f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.076 [1156:114]
Pos:   1.2s     31f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.080 [1168:114]
Pos:   1.3s     32f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.084 [1181:114]

1 duplicate frame(s)!
Pos:   1.4s     33f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.048 [1156:114]
Pos:   1.4s     34f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.052 [1163:115]
Pos:   1.4s     35f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.056 [1169:115]
Pos:   1.5s     36f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.060 [1179:115]
Pos:   1.5s     37f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.064 [1182:116]
Pos:   1.6s     38f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.068 [1187:116]
Pos:   1.6s     39f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.072 [1197:117]
Pos:   1.6s     40f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.076 [1204:117]
Pos:   1.7s     41f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.080 [1212:118]
Pos:   1.7s     42f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.084 [1218:118]

1 duplicate frame(s)!
Pos:   1.8s     43f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.048 [1200:118]
Pos:   1.8s     44f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.052 [1205:118]
Pos:   1.9s     45f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.056 [1210:119]
Pos:   1.9s     46f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.060 [1214:119]
Pos:   2.0s     47f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.064 [1217:119]
Pos:   2.0s     48f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.068 [1222:119]
Pos:   2.0s     49f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.072 [1224:120]
Pos:   2.1s     50f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.076 [1227:120]
Pos:   2.1s     51f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.080 [1234:120]
Pos:   2.2s     52f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.084 [1236:121]

1 duplicate frame(s)!
Pos:   2.2s     53f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.048 [1218:121]
Pos:   2.3s     54f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.052 [1220:121]
Pos:   2.3s     55f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.056 [1223:121]
Pos:   2.4s     56f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.060 [1228:121]
Pos:   2.4s     57f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.064 [1234:121]
Pos:   2.4s     58f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.068 [1233:121]
Pos:   2.5s     59f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.072 [1236:121]
Pos:   2.5s     60f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.076 [1237:121]
Pos:   2.6s     61f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.080 [1238:122]
Pos:   2.6s     62f ( 0%)  18fps Trem:   0min   0mb  A-V:-0.084 [1239:122]

#
# S N I P -- same pattern for about 27000 lines
#

1 duplicate frame(s)!
Pos: 515.7s  11723f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.048 [1030:121]
Pos: 515.8s  11724f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.052 [1030:121]
Pos: 515.8s  11725f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.056 [1030:121]
Pos: 515.8s  11726f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.060 [1030:121]
Pos: 515.9s  11727f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.064 [1030:121]
Pos: 515.9s  11728f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.068 [1030:121]
Pos: 516.0s  11729f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.072 [1030:121]
Pos: 516.0s  11730f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.076 [1030:121]
Pos: 516.0s  11731f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.080 [1030:121]
Pos: 516.1s  11732f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.084 [1030:121]

1 duplicate frame(s)!
Pos: 516.2s  11733f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.048 [1030:121]
Pos: 516.2s  11734f ( 0%)  19fps Trem:   0min   0mb  A-V:-0.052 [1030:121]

Writing AVI index...
Fixing AVI header...
ODML: vprp aspect is 16384:8866.

Video stream: 1030.283 kbit/s  (128785 bps)  size: 66479036 bytes  516.200 secs  11734 frames

Audio stream:  121.448 kbit/s  (15181 bps)  size: 7123296 bytes  469.224 secs


More information about the MPlayer-users mailing list