[MEncoder-users] Audio misaligned when encoding segments with -ss/-endpos

Attila Szegedi szegedia at freemail.hu
Sun Nov 21 22:30:18 CET 2004


Hi folks,

I'm using mencoder to convert MPEG2-encoded shows I capture from TV  
through a Hauppauge PVR-250 card to DIVX, with commercials skipped (I'm  
archiving them so I don't want the space taken up). To skip commercials,  
I'm cutting two parts from the encoded show (before the commercial block  
and after the commercial block - luckily the channels I'm recording from  
usually only put a single block of commercials in the show), and  
concatenate the parts together.

I'm running the whole thing on a Windows 200 box, using the cygmp port  
available from <http://armory.nicewarrior.org/projects/cygmp/>

The basic script I use is like what you see below. It's invoked with  
following parameters:
%1 the name of the .mpg file as produced by the Hauppauge card
%2 start of the first segment
%3 duration of the first segment
%4 start of the second segment
%5 duration of the second segment

-------------
rem two-pass encode the show
"c:\program files\mplayer\mencoder" -ovc lavc -lavcopts  
vcodec=mpeg4:vpass=1:vbitrate=1300 -oac mp3lame -lameopts vbr=3 -vf pp=lb  
-o p.divx "%1"
"c:\program files\mplayer\mencoder" -ovc lavc -lavcopts  
vcodec=mpeg4:vpass=2:vbitrate=1300 -oac mp3lame -lameopts vbr=3 -vf pp=lb  
-o p.divx "%1"

rem delete original file
del "%1"

rem cut the two parts
"c:\program files\mplayer\mencoder" -ss %2 -endpos %3 -ovc copy -oac copy  
-o p1.divx p.divx
"c:\program files\mplayer\mencoder" -ss %4 -endpos %5 -ovc copy -oac copy  
-o p2.divx p.divx
del p.divx

rem concatenate the parts
copy p1.divx /B + p2.divx /B nc.divx /B
del p1.divx
del p2.divx
"c:\program files\mplayer\mencoder" -noidx -ovc copy -oac copy -o  
"%~1.divx" nc.divx
del nc.divx
-------------
(Yes, I know about named pipes. No, I wasn't able to get them to work...)

The part that's troubling me is under the comment "cut the two parts". The  
result of the second cut will have audio misaligned - it's coming one  
second too early. I guess the first part also has audio coming early too,  
but because of a relatively small offset (3-4 minutes into the show), it's  
not noticable, whereas with offset of the second part (usually about 35  
minutes into the show) it is.

I've tried using "-audio-delay 1" on the second segment, but it looks like  
it's being lost (since it's a simple header param) when I concatenate the  
parts.

Any advice? Preferrably one that can execute in a batch operation - I  
don't want to do the cutting interactively...

I have searched the archives, but except for finding out in them that  
others also experienced inaccuracies with -ss on MPEG2 files[*], I found  
nothing that'd help me... Any pointers appreciated.

TIA,
   Attila.

-- 
home: http://www.szegedi.org
Visit Szegedi Butterfly fractals at:
   http://www.szegedi.org/fractals/butterfly/index.html

[*] I tried cutting and encoding the MPEG2 stream in one operation, but  
-ss was very innacurate; my measurements showed it's late by a factor of  
between 1.18 and 1.22, depending on the file. That's why I first encode  
the whole stuff (commercials included) to DIVX and cut the DIVX; -ss seems  
to be precise on DIVX.

-- 
home: http://www.szegedi.org
Visit Szegedi Butterfly fractals at:
   http://www.szegedi.org/fractals/butterfly/index.html




More information about the MEncoder-users mailing list