changeset 16414:cdb7069d57b0

better bitrate calculation
author reimar
date Tue, 06 Sep 2005 20:35:14 +0000
parents a07354861027
children 94568863c59c
files libmpdemux/demux_mpc.c
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mpc.c	Tue Sep 06 19:50:21 2005 +0000
+++ b/libmpdemux/demux_mpc.c	Tue Sep 06 20:35:14 2005 +0000
@@ -62,6 +62,8 @@
 
   if (hdr[0] != 'M' || hdr[1] != 'P' || hdr[2] != '+')
     return 0;
+  demuxer->movi_start = stream_tell(s) - HDR_SIZE;
+  demuxer->movi_end = s->end_pos;
   demuxer->priv = malloc(HDR_SIZE);
   memcpy(demuxer->priv, hdr, HDR_SIZE);
   return DEMUXER_TYPE_MPC;
@@ -78,16 +80,23 @@
     char *wf = (char *)calloc(1, sizeof(WAVEFORMATEX) + HDR_SIZE);
     char *header = &wf[sizeof(WAVEFORMATEX)];
     const int freqs[4] = {44100, 48000, 37800, 32000};
+    int frames;
+    int seconds;
     sh_audio->format = mmioFOURCC('M', 'P', 'C', ' ');
     memcpy(header, priv, HDR_SIZE);
     free(priv);
+    frames = header[4] | header[5] << 8 | header[6] << 16 | header[7] << 24;
     sh_audio->wf = (WAVEFORMATEX *)wf;
     sh_audio->wf->wFormatTag = sh_audio->format;
     sh_audio->wf->nChannels = 2;
     sh_audio->wf->nSamplesPerSec = freqs[header[10] & 3];
     sh_audio->wf->nBlockAlign = 32 * 36;
     sh_audio->wf->wBitsPerSample = 16;
-    sh_audio->wf->nAvgBytesPerSec = 128 * 1024; // dummy to make mencoder not hang
+    seconds = 1152 * frames / sh_audio->wf->nSamplesPerSec;
+    if (demuxer->movi_end > demuxer->movi_start && seconds > 0)
+      sh_audio->wf->nAvgBytesPerSec = (demuxer->movi_end - demuxer->movi_start) / seconds;
+    else
+      sh_audio->wf->nAvgBytesPerSec = 32 * 1024; // dummy to make mencoder not hang
     sh_audio->wf->cbSize = HDR_SIZE;
     demuxer->movi_start = stream_tell(s);
     demuxer->movi_end = s->end_pos;