Audio sync problems
I'm a returning user to mencoder (last used in 2003 under Linux), so my apologies if the answer to my question seems obvious. I've been trying to backup a DVD to H.264/AAC on MacOS X 10.4 (Tiger). I managed to compile mplayer/mencoder from CVS last night (2006/11/25) with x264 and faac support, so no problems there. However, I've been having major problems with lip sync, with audio being a significant fraction of a second ahead of video. I suspect that the problem I'm having is due to the input being mixed progressive and telecine NTSC, a format I've never used before, as I used to live in a PAL country. The following is my attempt at a first pass: mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS \ -alang eng -oac faac -faacopts br=128 \ -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 \ -ofps 24000/1001 -o title1.mp4 I have also tried using -mc (values of 0, 0.1 and 1), with no success. -oac copy seems to produce similarly out of sync results. mplayer dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS works fine. I can't find any clues to solve this in the documentation (which only has -nosound examples for mixed progressive and telecine) or man page, and would greatly appreciate any help. On the plus side, this basic first-pass H.264 encode seems to already be producing extremely good video results at only 1200 kbps. I look forward to seeing the second-pass results. Regards, -Karl P.S. mplayer.hu (as opposed to www.mplayer.hu) appears to be down, and so I had to subscribe to this list in the old-fashioned (unadvertised) way, i.e. by sending a blank e-mail to mencoder-users-join@mplayerhq.hu.
On Saturday, 26 November 2005 at 21:43, Karl Mitchell wrote:
I'm a returning user to mencoder (last used in 2003 under Linux), so my apologies if the answer to my question seems obvious.
I've been trying to backup a DVD to H.264/AAC on MacOS X 10.4 (Tiger). I managed to compile mplayer/mencoder from CVS last night (2006/11/25) with x264 and faac support, so no problems there. However, I've been having major problems with lip sync, with audio being a significant fraction of a second ahead of video. I suspect that the problem I'm having is due to the input being mixed progressive and telecine NTSC, a format I've never used before, as I used to live in a PAL country. The following is my attempt at a first pass:
mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS \ -alang eng -oac faac -faacopts br=128 \ -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 \ -ofps 24000/1001 -o title1.mp4
I have also tried using -mc (values of 0, 0.1 and 1), with no success. -oac copy seems to produce similarly out of sync results.
mplayer dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS works fine.
I can't find any clues to solve this in the documentation (which only has -nosound examples for mixed progressive and telecine) or man page, and would greatly appreciate any help.
On the plus side, this basic first-pass H.264 encode seems to already be producing extremely good video results at only 1200 kbps. I look forward to seeing the second-pass results.
Try encoding audio and video separately. I've had good results encoding video with -nosound (I know this is not recommended, but try) and muxing two audio tracks dumped with mencoder -of rawaudio into Matroska container while still maintaing perfect lip-sync. Regards, R. -- MPlayer RPMs maintainer: http://rpm.greysector.net/mplayer/ "I am Grey. I stand between the candle and the star. We are Grey. We stand between the darkness ... and the light." -- Delenn in Grey Council in Babylon 5:"Babylon Squared"
On Saturday, 26 November 2005 at 21:43, Karl Mitchell wrote:
I'm a returning user to mencoder (last used in 2003 under Linux), so my apologies if the answer to my question seems obvious.
I've been trying to backup a DVD to H.264/AAC on MacOS X 10.4 (Tiger). I managed to compile mplayer/mencoder from CVS last night (2006/11/25) with x264 and faac support, so no problems there. However, I've been having major problems with lip sync, with audio being a significant fraction of a second ahead of video. I suspect that the problem I'm having is due to the input being mixed progressive and telecine NTSC, a format I've never used before, as I used to live in a PAL country. The following is my attempt at a first pass:
mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS \ -alang eng -oac faac -faacopts br=128 \ -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 \ -ofps 24000/1001 -o title1.mp4
I have also tried using -mc (values of 0, 0.1 and 1), with no success. -oac copy seems to produce similarly out of sync results.
mplayer dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS works fine.
I can't find any clues to solve this in the documentation (which only has -nosound examples for mixed progressive and telecine) or man page, and would greatly appreciate any help.
On the plus side, this basic first-pass H.264 encode seems to already be producing extremely good video results at only 1200 kbps. I look forward to seeing the second-pass results.
Try encoding audio and video separately. I've had good results encoding video with -nosound (I know this is not recommended, but try) and muxing two audio tracks dumped with mencoder -of rawaudio into Matroska container while still maintaing perfect lip-sync.
Regards, R.
Hi Rathann, Thanks for your suggestion. With a little experimenting I managed to put everything into the mkv container and it played back well within mplayer. I have to admit that I do not understand why the sync should work using this method and not using the internal mencoder method. I'm sure there's got to be a better way of doing this than I used (commands below), and I would appreciate your recommendations. I was only able to use the -of rawaudio dump if I did it at the same time as doing full x264 compression, which is very slow. In addition, it turns out that my method was actually putting the data into an AVI container, which is certainly not what I wanted, so I had to use "--engage allow_avc_in_vfw_mode" in mkvmerge. Any suggestions? However, my aim was to create an MP4 container, for the sake of portability. If your or anyone can tell me how to do this, I'd be grateful. Regards, -Karl mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang eng -nosound -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 -o test.mp4 mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang eng -oac faac -faacopts br=128 -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 -o test.aac -of rawaudio mkvmerge -o test.mkv test.mp4 test.aac --engage allow_avc_in_vfw_mode-engage allow_avc_in_vfw_mode
On Saturday, 26 November 2005 at 23:33, Karl Mitchell wrote: [...]
Thanks for your suggestion. With a little experimenting I managed to put everything into the mkv container and it played back well within mplayer. I have to admit that I do not understand why the sync should work using this method and not using the internal mencoder method.
I'm sure there's got to be a better way of doing this than I used (commands below), and I would appreciate your recommendations. I was only able to use the -of rawaudio dump if I did it at the same time as doing full x264 compression, which is very slow.
Huh? I got my rawaudio dumps using -ovc copy. Try it.
In addition, it turns out that my method was actually putting the data into an AVI container, which is certainly not what I wanted, so I had to use "--engage allow_avc_in_vfw_mode" in mkvmerge. Any suggestions?
That's what mencoder does by default. You could try -of lavc -o file.mp4, though I don't know how well it'd work. R. -- MPlayer RPMs maintainer: http://rpm.greysector.net/mplayer/ "I am Grey. I stand between the candle and the star. We are Grey. We stand between the darkness ... and the light." -- Delenn in Grey Council in Babylon 5:"Babylon Squared"
Hi Rathann,
Thanks for your suggestion. With a little experimenting I managed to put everything into the mkv container and it played back well within mplayer. I have to admit that I do not understand why the sync should work using this method and not using the internal mencoder method.
I'm sure there's got to be a better way of doing this than I used (commands below), and I would appreciate your recommendations. I was only able to use the -of rawaudio dump if I did it at the same time as doing full x264 compression, which is very slow.
Huh? I got my rawaudio dumps using -ovc copy. Try it.
Sensible. Still slower than it should be, but much better than I was using.
In addition, it turns out that my method was actually putting the data into an AVI container, which is certainly not what I wanted, so I had to use "--engage allow_avc_in_vfw_mode" in mkvmerge. Any suggestions?
That's what mencoder does by default. You could try -of lavc -o file.mp4, though I don't know how well it'd work.
Brilliant! This seems to work fine! I thought I'd tried this before with no luck, but perhaps it was another option causing me problems. I used the command: mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang en \ -oac faac -faacopts br=128 \ -ofps 24000/1001 -vf pullup,softskip \ -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 \ -o test.mp4 -of lavf -lavfopts format=mp4 Not too fast, and I'm sure the second pass, when I get to it, will be a lot slower, but it at least works now, and is producing easily transportable mp4 files (Quicktime compatible). I managed an alternative solution using MP4Box and the "-of rawvideo" in mencoder to produce a raw .h264 file. I'll also keep an eye on the Matroska containers in the future. They look like they have a lot of potential. Cheers, -k
On Saturday, 26 November 2005 at 21:43, Karl Mitchell wrote: so I had to use "--engage allow_avc_in_vfw_mode" in mkvmerge. Any suggestions?
However, my aim was to create an MP4 container, for the sake of portability. If your or anyone can tell me how to do this, I'd be grateful.
Regards,
-Karl
mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang eng -nosound -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 -o test.mp4
mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang eng -oac faac -faacopts br=128 -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 -o test.aac -of rawaudio
mkvmerge -o test.mkv test.mp4 test.aac --engage allow_avc_in_vfw_mode-engage allow_avc_in_vfw_mode
hi. I've been looking for info about whether MEncoder uses vfw mode or not. such as "packed Bframes" or "Delay frames". I'm using commands below, to make x264+aac.mp4. On MacOSX 10.4.3,MEncoder dev-CVS-051115-06:05-4.0.1 #1st PASS (may be -ni is not needed ) mencoder XXX.mpeg -oac copy -ovc x264 -x264encopts threads=2:me=3:bitrate=1024:qp_min=16:qp_max=51:i4x4:frameref=5:subq=6:keyint=230:cabac:deblock:nob_adapt:bframes=1:turbo=1:pass=1 -passlogfile XXX.avi.log -vf pullup,softskip,crop=704:464:8:8,scale=640:480,hqdn3d=4:3:6,pp=l5,harddup -ni -sws 9 -ofps 23.976 -of avi -o /dev/null #2nd PASS mencoder XXX.mpeg -oac copy -ovc x264 -x264encopts threads=2:me=3:bitrate=1024:qp_min=16:qp_max=51:i4x4:frameref=5:subq=6:keyint=230:cabac:deblock:nob_adapt:bframes=1:pass=2 -passlogfile XXX.avi.log -vf pullup,softskip,crop=704:464:8:8,scale=640:480,hqdn3d=4:3:6,pp=l5,harddup -ni -sws 9 -ofps 23.976 -of avi -o XXX.avi #extract rawvideo mp4box -aviraw video XXX.avi #Audio encode ffmpeg -i XXX.mpeg -y -vn -f mp4 -acodec aac -ar 48000 -ac 2 -ab 64 -map 0.1:0.0 XXX_aac.mp4 #mux mp4box -fps 23.976 -add XXX_video.h264 -add XXX_aac.mp4 -new XXX.mp4 Good points: 1. Playable in QuickTime Player 7.0.3 Pro, VLC, MPlayer OSX. (not tested on Win nor any *nix distros) Bad points: 1. Durations of Audio & Video has some slight difference. Video is always longer, Up to 0.22sec~0.15sec. encoding Audio & Video is not good thing any way. but encoding all on ffmpeg has same problem, So I may try to trim Video or scale Audio. 2. Not editable in QuickTime Player 7.0.3 Pro. "Edit", I mean correcting Audio durations, changing aspect ratio for playing,,,. After these operations, QT7 claims that I have to encode again. This never take place when I use no bframes. 3. I guess -oac faac could result more accurate durations, but sometimes MEncoder says "bus erroer". not always, but so far there, seems to be no rule. Bad points 2. seems to be caused by vfw mode. Is there any way to enable other modes in MEncoder? -- http://htffmpegx.seesaa.net/
HTUME 20051111 wrote:
On Saturday, 26 November 2005 at 21:43, Karl Mitchell wrote:
so I had to use "--engage allow_avc_in_vfw_mode" in mkvmerge. Any suggestions?
However, my aim was to create an MP4 container, for the sake of portability. If your or anyone can tell me how to do this, I'd be grateful.
Regards,
-Karl
mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang eng -nosound -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 -o test.mp4
mencoder dvd://1 -dvd-device /Volumes/Neptune/Movies/DVD/VIDEO_TS -alang eng -oac faac -faacopts br=128 -vf pullup,softskip -ovc x264 -x264encopts bitrate=1200:turbo=1:pass=1 -ofps 24000/1001 -o test.aac -of rawaudio
mkvmerge -o test.mkv test.mp4 test.aac --engage allow_avc_in_vfw_mode-engage allow_avc_in_vfw_mode
hi. I've been looking for info about whether MEncoder uses vfw mode or not. such as "packed Bframes" or "Delay frames".
I'm using commands below, to make x264+aac.mp4. On MacOSX 10.4.3,MEncoder dev-CVS-051115-06:05-4.0.1
#1st PASS (may be -ni is not needed ) mencoder XXX.mpeg -oac copy -ovc x264 -x264encopts threads=2:me=3:bitrate=1024:qp_min=16:qp_max=51:i4x4:frameref=5:subq=6:keyint=230:cabac:deblock:nob_adapt:bframes=1:turbo=1:pass=1 -passlogfile XXX.avi.log -vf pullup,softskip,crop=704:464:8:8,scale=640:480,hqdn3d=4:3:6,pp=l5,harddup -ni -sws 9 -ofps 23.976 -of avi -o /dev/null
#2nd PASS mencoder XXX.mpeg -oac copy -ovc x264 -x264encopts threads=2:me=3:bitrate=1024:qp_min=16:qp_max=51:i4x4:frameref=5:subq=6:keyint=230:cabac:deblock:nob_adapt:bframes=1:pass=2 -passlogfile XXX.avi.log -vf pullup,softskip,crop=704:464:8:8,scale=640:480,hqdn3d=4:3:6,pp=l5,harddup -ni -sws 9 -ofps 23.976 -of avi -o XXX.avi
#extract rawvideo mp4box -aviraw video XXX.avi
#Audio encode ffmpeg -i XXX.mpeg -y -vn -f mp4 -acodec aac -ar 48000 -ac 2 -ab 64 -map 0.1:0.0 XXX_aac.mp4
#mux mp4box -fps 23.976 -add XXX_video.h264 -add XXX_aac.mp4 -new XXX.mp4
Good points: 1. Playable in QuickTime Player 7.0.3 Pro, VLC, MPlayer OSX. (not tested on Win nor any *nix distros)
Bad points: 1. Durations of Audio & Video has some slight difference. Video is always longer, Up to 0.22sec~0.15sec. encoding Audio & Video is not good thing any way. but encoding all on ffmpeg has same problem, So I may try to trim Video or scale Audio. 2. Not editable in QuickTime Player 7.0.3 Pro. "Edit", I mean correcting Audio durations, changing aspect ratio for playing,,,. After these operations, QT7 claims that I have to encode again. This never take place when I use no bframes. 3. I guess -oac faac could result more accurate durations, but sometimes MEncoder says "bus erroer". not always, but so far there, seems to be no rule.
Bad points 2. seems to be caused by vfw mode. Is there any way to enable other modes in MEncoder?
I've been wondering about the same thing myself: mencoder-cvs -ffourcc avc1 -of lavf -lavfopts format=mp4 dvd://2 -chapter 1-1 -vf pullup,softskip,crop=704:480:10:0,harddup -ofps 24000/1001 -nosound -ovc x264 -x264encopts bitrate=1330:keyint=300:frameref=15:bframes=16:qp_max=40:qp_step=5:qcomp=0.7:weight_b:4x4mv:8x8dct:me=3:me_range=20:subq=6:pass=3 -o CCS.try1.mp4 when I try to run the resulting file through mkvmerge it tells me: Warning: Quicktime/MP4 reader: MPEG4 part 10/AVC track 1 is missing its decoder config. Skipping this track. the only way I've been able to create a "real" mkv file with x264 video with mencoder is to use -of rawvideo, mux it with MP4Box (MP4Box -fps 23.976 -add file.h264 file.mp4), and then mux it with mkvmerge. However, since you can't specify fps as exact in mp4box as you can in mencoder, the output will be wrong, and the audio will be out of sync. it would be nice if the mp4 muxer created a file that is compadible with mkvmerge... Fredrik
On Fri, Dec 02, 2005 at 09:00:29AM +0100, Fredrik Eriksson wrote:
Bad points 2. seems to be caused by vfw mode. Is there any way to enable other modes in MEncoder?
I've been wondering about the same thing myself:
mencoder-cvs -ffourcc avc1 -of lavf -lavfopts format=mp4 dvd://2 -chapter 1-1 -vf pullup,softskip,crop=704:480:10:0,harddup -ofps 24000/1001 -nosound -ovc x264 -x264encopts bitrate=1330:keyint=300:frameref=15:bframes=16:qp_max=40:qp_step=5:qcomp=0.7:weight_b:4x4mv:8x8dct:me=3:me_range=20:subq=6:pass=3 -o CCS.try1.mp4
This is hopeless. mencoder knows nothing about pts, and thus lavf muxing can NEVER work in the presence of B frames. We really need to forcibly disable this since it's generating CORRUPT files. The only solution is using rawvideo. Rich
On Sat, 26 Nov 2005 12:43:20 -0800 Karl Mitchell <karl.l.mitchell@jpl.nasa.gov> wrote:
However, I've been having major problems with lip sync, with audio being a significant fraction of a second ahead of video.
Some details could help. Is it a fixed offset from the very begining, or a gradually increasing desync? Are you sure the sync problem is with the encoding and not being introduced during playback?
I suspect that the problem I'm having is due to the input being mixed progressive and telecine NTSC,
I don't see any reason to believe that's the cause.
-o title1.mp4
I hope you realize that naming it ".mp4" doesn't actually put it in an mp4 container. It's still an AVI file.
Hi, On Sat, Nov 26, 2005 at 12:43:20PM -0800, Karl Mitchell wrote:
I have also tried using -mc (values of 0, 0.1 and 1), with no success. -oac copy seems to produce similarly out of sync results.
If using -mc 0 you should usually use -noskip as well. Just in case you could also add -vf harddup Greetings, Reimar Döffinger
On Sun, Nov 27, 2005 at 11:15:16AM +0100, Reimar Döffinger wrote:
Hi, On Sat, Nov 26, 2005 at 12:43:20PM -0800, Karl Mitchell wrote:
I have also tried using -mc (values of 0, 0.1 and 1), with no success. -oac copy seems to produce similarly out of sync results.
If using -mc 0 you should usually use -noskip as well.
No, they're really unrelated aside from the fact that both affect if/how frames are dropped and duplicated. -mc 0 prevents frame drop/dup for a/v sync purposes. -noskip prevents correction of the video stream (independent of audio) for excess or too few frames in the case of framerate change, vfr->cfr encoding, frame-dropping filters, ...
Just in case you could also add -vf harddup
It's not needed for avi, but may be needed if remuxing into different formats later. Rich
participants (7)
-
Dominik 'Rathann' Mierzejewski -
Fredrik Eriksson -
HTUME 20051111 -
Karl Mitchell -
RC -
Reimar Döffinger -
Rich Felker