-   Linux - Software (
-   -   Mencoder: audio delay when encoding in slices!? (

J_Szucs 01-15-2005 01:49 PM

Mencoder: audio delay when encoding in slices!?
I tried to slice up a dvd into chapters and encode each chapter separately to avi, then merge the avi's again, like this:
# slicing
mencoder dvd://1 -ovc copy -oac copy -chapter 1-1 -o chapter01.mpeg
mencoder dvd://1 -ovc copy -oac copy -chapter 2-2 -o chapter02.mpeg
# encoding the slices
mencoder chapter01.mpeg -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000 -oac mp3lame -lameopts cbr:br=64 -o chapter01.avi
mencoder chapter02.mpeg -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000 -oac mp3lame -lameopts cbr:br=64 -o chapter02.avi
# merging
cat chapter01.avi chapter02.avi > chapters01-02.avi
# fixing
mencoder chapters01-02.avi -noidx -avc copy -oac copy chapters01-02.fixed.avi

The problem: there will be an audio delay of cca. 2s inside the merged avi, starting from the original boundary of the two avi's (so, the first half of the avi will be correct, the other half corrupted).
When I play chapter02.avi, there is no audio delay, so the delay may be caused by mencoder, when fixing the merged avi.

Is it a known bug? Is there a workaround?

J_Szucs 01-17-2005 03:25 AM

Problem solved.

It turned out that it was actually a mencoder bug that affected the splitting command. But there was a workaround: just add a single mencoder command line option and everything is OK.

So, one can use mencoder for splitting and joining avi's, too.

acid_kewpie 01-17-2005 03:30 AM

and that option would be?

J_Szucs 01-17-2005 03:41 AM

-audio-preload 0.0

I just realized that mencoder preloads the audio data during encoding. What is worse: it does not seem to throw away the preloaded, surplus audio-data at the end of the encoding process, but inserts them into the last encoded frame.

You do not notice this when you play the slices: the playback of each slice will be correct.
But, when you merge the slices, the surplus audio data at the end of the first slice will delay the audio data of the second slice by cca. 1s, when you merge the avi slices as described in the mencoder documentation. If you have more slices, then the audio delay will gradually increase all along the merged avi.

J_Szucs 01-22-2005 09:58 PM

Problem not solved :-(.

My findings seem to be valid for avi files, only, and not for dvds :-(:

I splitted an avi into 38 parts by mencoder, then I merged them by mencoder again, and I got an audio delay of cca. 19s (which in fact equals to 38 times the 0.5s default audio-preload value).

If I splitted the avi into 38 parts but used the -audio-preload 0.0 switch meanwhile, then there was no audio delay after merging the avi parts.

But: If I split a dvd into chapters, I get several errors like this during encoding of the parts into avi:
a52: CRC error...
Flushing video

Then I always get an audio delay after merging the separately-encoded avi parts.

I wonder why dvds behave differently in this case? Maybe it is a dvd seek problem with mencoder?

netpup 06-24-2006 05:18 PM

force video delay
for mpeg encoding with -mpegopts option, i messed about with init_apts (eg=init_apts=700) and init_vpts (eg init_vpts=100).

works for me using the following:

(other parts of the script are similar, ony ss (start time) and endpos are different... plus i dont use init parts on the first slice)

mencoder -audio-preload 0.0 \
-oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd:init_vpts=700:init_apts=100 -vf \
scale=352:288,harddup -srate 44100 -lavcopts \
vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 25 \
-ss 01:00:00 -endpos 02:00:00 -o /disk2/videos/converted/$1.out.2.mpg $1

hope this solves


also :)... put the result through vcdimager and cdrdao, hey presto a a/v synced vcd

theYinYeti 06-24-2006 07:19 PM

Do you mean you can create a SVCD with several chapters or even several titles this way?


netpup 06-25-2006 06:30 PM

svcd / vcd
you cn make vcd slice with my code... would have to alter for SuperVCD (format, bitrate and the like).

the main reason for posting was to show a working example (for me anyway) of how you can delay the video slightly when chopping up a video from DVD, AVI or similar source.

which i wanted to do for the purposes of creating VideoCD's for watching stuff on my standalone dvd player, which I now can...

although I have been experiencing some delay in audio near the end of some AVI type movies but i blame the source (ie leeched).

All times are GMT -5. The time now is 10:53 AM.