[MPlayer-dev-eng] [PATCH] Fix demux_avi >=2GB overflow & enhance avi info output

Arpi arpi at thot.banki.hu
Thu Dec 19 01:03:37 CET 2002


Hi,

ok, the problem is right (and known, by me) but your fix is buggy too:

> -  // calculating video bitrate:
> -  sh_video->i_bps=demuxer->movi_end-demuxer->movi_start-priv->idx_size*8;
> -  if(sh_audio) sh_video->i_bps-=sh_audio->audio.dwLength;
> -  mp_msg(MSGT_DEMUX,MSGL_V,"AVI video length=%lu\n",(unsigned long)sh_video->i_bps);
> -  sh_video->i_bps=((float)sh_video->i_bps/(float)sh_video->video.dwLength)*sh_video->fps;
> -  
> -  if((priv->numberofframes=sh_video->video.dwLength)<=1)
> -    // bad video header, try to get number of frames from audio
> -    if(sh_audio && sh_audio->wf->nAvgBytesPerSec) priv->numberofframes=sh_video->fps*sh_audio->audio.dwLength/sh_audio->wf->nAvgBytesPerSec;

this code shouldn't be removed, but used as fallback if no index (maybe with
a warning saying that values are inaccurate, and/or printing '~' sign before
teh numbers)

> +  // calc video bitrate, count idx, calc a/v size & fix dwLength if needed:

> +    sh_video->video.dwLength=0;
> +    sh_audio->audio.dwLength=0;
> +    for(i=0;i<priv->idx_size;i++){ 
> +      if(sh_video->ds->id == avi_stream_id(((AVIINDEXENTRY *)priv->idx)[i].ckid)) {
> +        vsize+=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
> +        sh_video->video.dwLength++;
> +      }
> +      else if(sh_audio->ds->id == avi_stream_id(((AVIINDEXENTRY *)priv->idx)[i].ckid)) {
> +        asize+=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
> +        sh_audio->audio.dwLength++;
> +      }

this is BAD.
dwLength is counted in samples, not in chunks.
also, calculating the right sample number is very tricky for audio, esp. for
VBR. you need to round up chunksize to N * nBlockAlign, so:

dwLength += (dwChunkLength+nBlockAlign-1)/nBlockAlign;

but also check that nBlockAlign is valid, and fallback to dwSampleSize if
that valid and fallback to nBitsPerSample/8*mChannels and so on...
see demux_avi.c, for the "right" way of calculating number of samples...


A'rpi / Astral & ESP-team

--
Developer of MPlayer, the Movie Player for Linux - http://www.MPlayerHQ.hu



More information about the MPlayer-dev-eng mailing list