Log in

View Full Version : A/V Sync problems after encoding audio seperatly


Sitron
20th May 2008, 22:18
I am trying to convert a range of DVDs to MP4 so I can play it on my PS3. However, since the PS3 sees everything as media-files (not DVD's) it will not deinterlace and such, so I need to do it.

Now I have a file ($FILE.vob) which is NTSC and telecined. (I checked following step 14.2.2.2 on http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-telecine.html)

I encode it (3-pass) with this line: mencoder $FILE.vob -vf pullup,softskip -ovc x264 -x264encopts $X264PASS3 -passlogfile $FILE.log -oac pcm -ofps 24000/1001 -o $FILE.avi (For 1st and 2nd pass the line is the same except -o is /dev/null)

When I play this movie, everything seems fine. The video is H.264, running at 23.976 FPS and the audio is in sync. However, it's in an AVI-container, so I need encode the sound to aac and mux this into an mp4.

Extract the video: mencoder $FILE.avi -ovc copy -oac copy -of rawvideo -o $FILE.h264
Extract the audio: mplayer $FILE.avi -ao pcm:file=$FILE.wav -vc dummy -vo null -channels 2
Encode the audio: neroAacEnc -q 0.8 -lc -if $FILE.wav -of $FILE.aac
Mux them to a MP4: MP4Box -add $FILE.h264#video -add $FILE.aac#audio -fps 23.976 -new $FILE.mp4

However, when playing this new .mp4-file the audio and video start off in sync, but the video seems to have a faster speed. So at the end the video is finished before the audio.
But why? Is there any obvious errors with my commands, have I overlooked something? Or is there a different way of doing this (without ditching NeroAacEnc)?

Some additional info: $FILE.avi is 254.2 seconds (6094 frames), $FILE.mp4 is 252.6 seconds (6057 frames) according to MPlayer. Both are at 23.976 fps. MPlayer also states that the $FILE.avi is [h264], but the .mp4 is [avc1]

roozhou
21st May 2008, 01:08
pullup will generate a VFR output
you can either use harddup to make a cfr output:
mencoder $FILE.vob -vf pullup,softskip,harddup -ovc x264 -x264encopts $X264PASS3 -passlogfile $FILE.log -oac pcm -ofps 24000/1001 -o $FILE.avi

or get the timecode after your encoding and make a VFR mp4:
first stop before the 3rd pass and extract timecode using cfr2tc
cfr2tc $FILE.avi NUL tc.txt 4
now change your 3rd-pass command line to
mencoder $FILE.vob -vf pullup,softskip,harddup -ovc x264 -x264encopts $X264PASS3 -passlogfile $FILE.log -oac pcm -ofps 24000/1001 -of rawvideo -o $FILE.264
after 3rd-pass and audio encoding you get $FILE.264, tc.txt and $FILE.mp4
note that neroaacenc can only output .mp4.
Mux 264 to mp4
MP4Box -add $FILE.h264#video -new cfr.mp4
Insert timecode using tc2mp4
tc2mp4 -i cfr.mp4 -o vfr.mp4 -t tc.txt
Mux audio
MP4Box vfr.mp4 -add $FILE.mp4
delete all intermediate files and vfr.mp4 is your final product.

Sitron
21st May 2008, 18:22
Thanks. The harddup-option worked perfectly :-)

However, I could not find linux binaries or sourcecode for the cfr2tc and tc2mp4-tools. Do you have a link?
And yes, I should have called the audio-file .m4a, even my Playstation 3 accepted that name :-)

roozhou
22nd May 2008, 07:42
Thanks. The harddup-option worked perfectly :-)

However, I could not find linux binaries or sourcecode for the cfr2tc and tc2mp4-tools. Do you have a link?
And yes, I should have called the audio-file .m4a, even my Playstation 3 accepted that name :-)

Unfortunately no source codes.