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

Michael Niedermayer michaelni at gmx.at
Sun Jan 22 12:10:15 CET 2006


Hi

On Sat, Jan 21, 2006 at 09:22:06PM -0800, Corey Hickey wrote:
> On Sat, January 21, 2006 17:48, Loren Merritt wrote:
> >>>> --- libmpcodecs/ve_lavc.c	10 Jan 2006 11:09:02 -0000	1.125
> >>>> +++ libmpcodecs/ve_lavc.c	21 Jan 2006 05:44:32 -0000
> >>>> @@ -750,6 +750,9 @@
> >>>>         mux_v->bih->biSize= sizeof(BITMAPINFOHEADER) +
> >>>> lavc_venc_context->extradata_size;
> >>>>     }
> >>>>
> >>>> +    if (lavc_venc_context->max_b_frames)
> >>>> +        mux_v->encoder_delay = lavc_venc_context->max_b_frames + 1;
> >>>> +
> >>>
> >>> Why the +1? This seems incorrect,
> >>
> >> I don't know. That's what Michael suggested and I've been assuming it to
> >> be correct. I know I can't really notice 1/24 second sync difference.
> >>
> >> http://www1.mplayerhq.hu/pipermail/mplayer-dev-eng/2005-December/039425.html
> >
> > I think the +1 is for decoding delay. So it is true that total delay =
> > bframes+1, but it is incorrect to put the +1 in the muxer.
> 
> Huh. That makes sense. If I'm reading things right, then that's the way x264
> does it:
> 
> x264/encoder/encoder.c:562
> h->frames.i_delay = h->param.i_bframe;
> 
> ...however, libavcodec adds the +1 whenever B-frames are present.
> 
> libavcodec/mpegvideo.c: 1195
> s->low_delay= s->max_b_frames ? 0 : 1
> avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
> 
> I really don't know if either is incorrect. That would have to be up to
> Michael or yourself.

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

[...]
-- 
Michael




More information about the MPlayer-dev-eng mailing list