[MEncoder-users] Sync and Encoding audio: AAC and muxing

Nicolas Hesler nicolas.hesler at sheridanc.on.ca
Fri May 9 23:11:51 CEST 2008


Up until recently, I've used mencoder to encode and mux MPEG-2.

Now I've begun trying to encode h.264 with AAC in AVI and then remux 
with mp4box.

There are a couple of reasons behind my not wanting to mux with lavf in 
mencoder:
- all of the reasons outlined on this list and in the docs (including b 
frames problem)
- to be able to remux for bluray (because, as I understand it, I'd have 
to remux anyway)

I'm fine with the whole process except for audio encoding.  I think 
there is something fundamental that I don't understand about encoding 
audio or the way that audio is muxed into a stream.

I've hit a road block in understanding how AAC is encoded and how it is 
synced in a stream.

In all of my tests, I can't seem to get AAC audio to match the exact 
length of the video it is paired with.

Here is an example: 


** Note that all of my attempts are based on uncompressed avi files or 
wav files and/or raw audio/video coming from a Framesserver.


I've got a video source with 305 frames with audio that lasts exactly 
305 frames at 24 fps = 12.7083333 seconds.

For instance, when I encode using the following command line:

mencoder -vf harddup -ovc x264 -x264encopts bitrate=8000 -oac faac 
-faacopts
mpeg=4:object=2:br=224 -channels 2 -srate 48000 -ofps 24 export.avs -o 
h264.avi

I get an h.264 encoded video track with 304 frames (12.667s )(because 
one frame is skipped) and an audio track that is (12.651s).   Why the 
discrepency in length???  This is 16 ms difference.

If I add -mc 0 to the command line, I get back the original 305 frames 
of video (12.708s), but the audio is still (12.651s).  This is a 57 ms 
difference.

Obviously mencoder compensated for the difference in the first example 
and tried to keep the sync close, but shouldn't I be able to get back 
the full 305 frames of video along with the full 12.708s of audio?

So I did a lot more testing of the audio track.   I grabbed the WAV file 
and encoded it with command line encoders to AAC using ffmpeg, faac, 
neroaac.  In the case of ffmpeg I tried encoding to mp3 as well.  In all 
cases, with no video to worry about, the duration of the encoded audio 
was always different from the duration of the WAV audio.

Why is this?

I want to be able to get back the original full length of the video and 
audio so I don't have to worry about sync issues. Is this possible and 
under what circumstances??  Would I still have to worry about sync 
issues if my audio length and video length were the same??

Someone please point me in the right direction.  Thanks!














More information about the MEncoder-users mailing list