[MPlayer-dev-eng] Proposed patch for allowing some jitter in mencoder (improved sync handling)

Oded Shimon ods15 at ods15.dyndns.org
Fri Feb 24 21:22:59 CET 2006


On Fri, Feb 24, 2006 at 06:46:09PM +0100, Matthias Hopf wrote:
> 4) Combining of v_timer_corr and v_pts_corr has been done in the least
>    intrusive way. In the very end I hope to nuke one of them. However,
>    if someone can tell me why and how these should be handled
>    differently, I'd be glad to update my patch.

There are some differences between v_timer_corr and v_pts_corr .
v_timer_corr is the difference between frame time and fps.
For ex., 'mencoder -fps 10 -ofps 20 bla.avi'
the frame_time is 0.1s, and the fps is 0.05s, so v_timer_corr will grow by 
0.05s on every frame and will cause each frame to be duplicated.

v_timer_corr is disabled by -noskip . This is what skip_limit does...

v_pts_corr is something completely different - it's the pts difference 
between audio and video, maintaining sync between the 2. it is disabled by 
-mc 0, and ignores -noskip.

> +#include <math.h>

Can you avoid math.h dependency?.. it doesn't matter much, but for all you 
floor() purposes unless you're doing funny stuff with sign a simple cast to 
int will do fine...

> +    v_timer_corr += v_pts_corr;
> +    v_pts_corr = 0;
> +    v_delta = v_timer_corr/mux_frametime;
> +    if ((v_delta >=0 && v_jitter_sum >= 0) ||
> +	(v_delta <=0 && v_jitter_sum <= 0)) {
> +	v_jitter_sum += ABS(v_delta)*v_delta;
> +	if (ABS(v_delta) > jitter_max) {
> +	    double v_delta_trunc = COPYSGN(v_delta, floor (ABS(v_delta) - 0.5));
> +//	    double v_delta_trunc = trunc (v_delta);
> +	    skip_flag    += (int) v_delta_trunc;
> +	    v_timer_corr -= v_delta_trunc * mux_frametime;
> +	    v_jitter_sum  = COPYSGN (v_delta, jitter_delay);
> +	} else if (ABS(v_delta) > jitter_min &&
> +		   ABS(v_jitter_sum) >= jitter_delay) {
> +	    skip_flag    += COPYSGN (v_delta, 1);
> +	    v_timer_corr -= COPYSGN (v_delta, mux_frametime);
> +	    v_jitter_sum -= COPYSGN (v_delta, jitter_min*2); // jitter_delay/2? jitter_max?
> +	}
> +    } else {
> +	if (ABS(v_jitter_sum) > jitter_min && ABS(v_delta) < jitter_min)
> +	    v_jitter_sum /= 2;
> +	else
> +	    v_jitter_sum = 0;
> +    }

I'm horribly confused by this algo. :(
Is v_jitter_sum supposed to be a "power of 2" (with sign) of v_delta?
What is this code supposed to do, could explain it in detail in words...

> +	mp_msg(MSGT_AVSYNC,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %5.2ffps Trem:%4dmin %3dmb  A-V:%5.3f [%d:%d] jitter %4.2f/%4.2f \r",

Possibly not a good idea as would break line on 80 width terminals...

> Index: DOCS/man/en/mplayer.1
> ===================================================================
> RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v
> retrieving revision 1.1232
> diff -u -p -u -r1.1232 mplayer.1
> --- DOCS/man/en/mplayer.1	20 Feb 2006 23:50:40 -0000	1.1232
> +++ DOCS/man/en/mplayer.1	24 Feb 2006 17:04:08 -0000
> @@ -6195,6 +6195,23 @@ general comments about the work
>  .RE
>  .
>  .TP
> +.B \-allowjitter <option1:option2:...>
> +Specify parameters for jitter correction. Jitter is the varying time stamp
> +difference for connected video and audio frames and measured in fractional
> +numbers of frames here.
> +.sp 1
> +Available options are:
> +.RSs
> +.IPs min=<value>
> +minimum jitter necessary for drops/skips (default is 1.5)
> +.IPs max=<value>
> +maximum allowed jitter - overshooting results in immediate drops/skips
> +(default is 2.5)
> +.IPs delay=<value>
> +accumulated squared jitter necessary for drops/skips (default is 40)
> +.RE
> +.
> +.TP

Gonna need more explaining than that, I don't understand this at all :/

- ods15




More information about the MPlayer-dev-eng mailing list