[MPlayer-dev-eng] [PATCH] Mencoder AV sync

Rudolf Polzer divVerent at alientrap.org
Sat Feb 19 13:56:16 CET 2011


On Sat, Feb 19, 2011 at 12:36:36AM -0800, Tim Xiao wrote:
> Hi mplayer devs,
> 
> I found an AV sync issue with mencoder. For certain audio formats
> (like FLAC), the encoder would mistakenly think that the audio is
> ahead. This causes it to skip a frame every 0.3 seconds or so, and the
> resulting encode would have horrible AV sync issues. After some
> experimenting, I discovered that copying a portion of the mplayer.c AV
> sync code to mencoder.c fixes the problem. While I don't think copying
> code is the best approach, its the best I could come up with. On a
> related note, I couldn't figure out if I was supposed to use 4 spaces,
> 2 spaces or tabs for indentation. So I guessed 2 spaces. :P
> 
> Tim Xiao

This fix was already sent by me before, but did not get applied. See:
http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2010-July/065487.html

Maybe you won't get ignored like I did.

> Index: mencoder.c
> ===================================================================
> --- mencoder.c	(revision 32927)
> +++ mencoder.c	(working copy)
> @@ -1549,9 +1549,18 @@
>  #endif
>      {
>        // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
> -      a_pts=d_audio->pts;
> -      if(!delay_corrected) if(a_pts) delay_corrected=1;
> -      a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
> +      if (a_pts != MP_NOPTS_VALUE) {
> +        a_pts = sh_audio->pts;
> +        a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps;
> +      }
> +      else {
> +        a_pts = d_audio->pts;
> +        if (sh_audio->i_bps) {
> +          a_pts += (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len) /
> +                   (double)sh_audio->i_bps;
> +        }
> +      }
> +      a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps;
>      }
>      v_pts=sh_video ? sh_video->pts : d_video->pts;
>      // av = compensated (with out buffering delay) A-V diff

This is exactly what I did, except that I did it inside a function.

Best regards,

Rudolf Polzer


More information about the MPlayer-dev-eng mailing list