[MPlayer-dev-eng] [PATCH] Duration of VBR-encoded MP3s was wrong

Nico Sabbi nicola_sabbi at fastwebnet.it
Fri Mar 30 00:04:06 CEST 2007


Carl Eugen Hoyos wrote:

> 
> The original patch didn't compile for me (libmpdemux/muxer_mpeg.c &
> libmpcodecs/ad_hwmpa.c), broke DVB playback (sh->wf is not always
> initialized) and I removed one cosmetic change.
> 
> Somebody else should comment if the patch overall is a good idea. It
> fixes duration of at least some of my mp3 files.
> 
> Carl Eugen
> 

I don't see the usefulness of a patch like this (or at least it 
doesn't give an advantage the compensates the increase in code 
complexity), but anyway...

>  
>    switch(frmt) {
> -  case MP3:
> +  case MP3: {
> +    // Search for VBR header and compute correct bitrate if necessary
> +    uint8_t vbrhdr[4];
> +    uint8_t framesnb_hdr[4];
> +    int frames_nb = -1;
> +    uint8_t frames_field;
> +    stream_seek(s,mpeghdr_pos+4+mp3_found->mpa_ssize);
> +    stream_read(s,vbrhdr,4);
> +    if(!s->eof)
> +      if( (vbrhdr[0] == 'X' && vbrhdr[1] == 'i' && vbrhdr[2] == 'n' && vbrhdr[3] == 'g')
> +	  || (vbrhdr[0] == 'I' && vbrhdr[1] == 'n' && vbrhdr[2] == 'f' && vbrhdr[3] == 'o') ) { // We found a XING header
> +	stream_seek(s,mpeghdr_pos+11+mp3_found->mpa_ssize);
> +	stream_read(s,&frames_field,1);
> +	if( frames_field & 1 ) {
> +	  stream_seek(s,mpeghdr_pos+12+mp3_found->mpa_ssize); // We jump to Frames number
> +	  stream_read(s,framesnb_hdr,4);
> +	  if(s->eof)
> +	    break;
> +	  frames_nb = (framesnb_hdr[0]<<24) | (framesnb_hdr[1]<<16) | (framesnb_hdr[2]<<8) | (framesnb_hdr[3]);
> +	}
> +      }
> +      else {
> +	stream_seek(s,mpeghdr_pos+36);
> +	stream_read(s,vbrhdr,4);
> +	if( vbrhdr[0] == 'V' && vbrhdr[1] == 'B' && vbrhdr[2] == 'R' && vbrhdr[3] == 'I' ) { // We found a VBRI header
> +	  stream_seek(s,mpeghdr_pos+50); // We jump to Frames number
> +	  stream_read(s,framesnb_hdr,4);
> +	  if(s->eof)
> +	    break;
> +	  frames_nb = (framesnb_hdr[0]<<24) | (framesnb_hdr[1]<<16) | (framesnb_hdr[2]<<8) | (framesnb_hdr[3]);
> +	}
> +      }
> +    

all this seeking is harmful in network streams. they can be avoided 
buffering the necessary data and when done pushing it back in the 
demux_stream with stream_skip(stream, -n) ; if n is small enough it 
will be back in
the buffer, otherwise it will be lost as much as after all this 
seeking if the stream is not seekable

-- 
"Without a frontend, mplayer is useless" - someone in mplayer-users



More information about the MPlayer-dev-eng mailing list