[MPlayer-dev-eng] [PATCH] mencoder, B-frames, and video/audio delay

Michael Niedermayer michaelni at gmx.at
Mon Jan 23 02:00:14 CET 2006


Hi

On Sun, Jan 22, 2006 at 02:23:05PM -0800, Loren Merritt wrote:
> On Sun, 22 Jan 2006, Michael Niedermayer wrote:
> 
> >well "avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);" is the 
> >encoder
> >input to decoder output delay
> >
> >the delay between encoder input and encoder output (=pts difference) is
> >variable and between 0 and s->max_b_frames + 1 if b frames are used or 0 
> >if not
> >
> >0 1 2 3 4 5
> >I B P B P
> >|  \|  \|
> >|   |\  |\
> >I   P B P B
> >
> >if the encoder can output several frames at once with no input then its 
> >delay
> >can be between 0 and s->max_b_frames
> >
> >the difference between encoder input pts and encoder output dts / decoder
> >input dts should be "avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 
> >1);"
> >too
> 
> Method 0: ideally, decoder's pts = encoder's pts
> 
> -1 0 1 2 3 4 5
>    I B P B P      pts
>    |  \|  \|
>    |   |\  |\   encode
>    I   P B P B
>   /   / / / /
>  |  / / / /     muxer compensates for delay (subtract up to bframes+1)
>  I P B P B        dts
>   \ \|  \|
>    | |\  |\     decode
>    I B P B P      pts
> 
> ...but that's not how dts is stored in avi or mp4.
> Method 1: if negative timestamps aren't allowed
> 
> 0 1 2 3 4 5
> I B P B P         pts (encoder)
> |  \|  \|
> |   |\  |\      encode
> I   P B P B
> |  / / / /
> | | | | |       muxer compensates for delay (subtract up to bframes)
> I P B P B         dts
>  \ \|  \|
>   | |\  |\      decode
>   I B P B P       pts (decoder)
>  / / / / /
> | | | | |       player compensates for delay (subtract 1)
> I B P B P         pts (display)

well, i certainly agree that the muxer cant end up storing a frame with dts=-1
in avi/mp4/... but IMHO the correct dts/pts/delay are the ones in method 0
not 1

a muxer should then add +1 to all timestamps of all streams (with correct
timebase of course) to avoid the dts=-1 and if the fileformat supports it
then store that +1 offset too

[...]
-- 
Michael




More information about the MPlayer-dev-eng mailing list