Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h	(revision 7818)
+++ libavcodec/avcodec.h	(working copy)
@@ -837,6 +837,7 @@
     int frame_size;
     int frame_number;   ///< audio or video frame number
     int real_pict_num;  ///< returns the real picture number of previous encoded frame
+    int total_frames;   ///< Total number of frames provided by some VBR headers
 
     /**
      * number of frames the decoded output will be delayed relative to
Index: libavcodec/mpegaudiodec.c
===================================================================
--- libavcodec/mpegaudiodec.c	(revision 7818)
+++ libavcodec/mpegaudiodec.c	(working copy)
@@ -169,6 +169,11 @@
     SCALE_GEN(4.0 / 9.0), /* 9 steps */
 };
 
+static const int side_info_size[2][2] = {
+    {32,17}, /* MPEG 1 */
+    {17,9}   /* MPEG 2/2.5 */
+};
+
 static MPA_INT window[512] __attribute__((aligned(16)));
 
 /* layer 1 unscaling */
@@ -2549,6 +2554,7 @@
     MPADecodeContext *s = avctx->priv_data;
     uint32_t header;
     int out_size;
+    int offset;
     OUT_INT *out_samples = data;
 
 retry:
@@ -2572,6 +2578,7 @@
     avctx->channels = s->nb_channels;
     avctx->bit_rate = s->bit_rate;
     avctx->sub_id = s->layer;
+    avctx->total_frames=0;
     switch(s->layer) {
     case 1:
         avctx->frame_size = 384;
@@ -2587,6 +2594,18 @@
         break;
     }
 
+	/* look for Xing or Info VBR header */
+    offset = HEADER_SIZE + side_info_size[s->lsf][s->mode == MPA_MONO ? 1 : 0];
+
+    if ((buf[offset]  == 'X' && buf[offset+1] == 'i' && buf[offset+2] == 'n' && buf[offset+3] == 'g') ||
+        (buf[offset]  == 'I' && buf[offset+1] == 'n' && buf[offset+2] == 'f' && buf[offset+3] == 'o')) {
+        uint32_t vbr_flags = (buf[offset+4] << 24) | (buf[offset+5] << 16) | (buf[offset+6] << 8) | buf[offset+7];
+
+        /* Look for frame count */
+        if (vbr_flags & 0x0001) 
+            avctx->total_frames=(buf[offset+8] << 24) | (buf[offset+9] << 16) | (buf[offset+10] << 8) | buf[offset+11];
+    }
+
     if(s->frame_size<=0 || s->frame_size > buf_size){
         av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
         return -1;
Index: libavformat/utils.c
===================================================================
--- libavformat/utils.c	(revision 7818)
+++ libavformat/utils.c	(working copy)
@@ -1550,6 +1550,8 @@
                     st->start_time = 0;
                     st->duration = duration;
                 }
+                if (st->codec->total_frames)
+                    st->duration = av_rescale(st->codec->total_frames * st->codec->frame_size / st->codec->sample_rate, st->time_base.den, st->time_base.num);	
             }
         }
     }
@@ -1643,6 +1645,8 @@
                 if (st->duration == AV_NOPTS_VALUE ||
                     st->duration < duration)
                     st->duration = duration;
+                if (st->codec->total_frames)
+                    st->duration = av_rescale(st->codec->total_frames * st->codec->frame_size / st->codec->sample_rate, st->time_base.den, st->time_base.num);	
             }
         }
         av_free_packet(pkt);
@@ -2110,6 +2114,7 @@
     if (s->iformat) {
         /* no default bitrate if decoding */
         st->codec->bit_rate = 0;
+        st->codec->total_frames = 0;
     }
     st->index = s->nb_streams;
     st->id = id;
