diff -rub vlc-0.7.2/modules/demux/mpeg/system.c vlc-0.7.2-phil/modules/demux/mpeg/system.c
--- vlc-0.7.2/modules/demux/mpeg/system.c	2004-03-17 05:27:19.000000000 -0500
+++ vlc-0.7.2-phil/modules/demux/mpeg/system.c	2004-06-03 21:06:10.281250000 -0400
@@ -65,6 +75,9 @@
     static mpeg_demux_t mpeg_demux =
                     { NULL, ReadPS, ParsePS, DemuxPS, ReadTS, DemuxTS };
     mpeg_demux.cur_scr_time = -1;
+    mpeg_demux.base_scr_time = -1;
+    mpeg_demux.base_file_offset = -1;
+    mpeg_demux.i_mux_rate_changes = 0;
     memcpy( p_this->p_private, &mpeg_demux, sizeof( mpeg_demux ) );
 
     return VLC_SUCCESS;
@@ -1035,6 +1048,7 @@
 static void DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
 {
     uint32_t i_code;
+	uint64_t i_file_delta;
     vlc_bool_t b_trash = 0;
     es_descriptor_t * p_es = NULL;
     mpeg_demux_t *p_mpeg_demux = (mpeg_demux_t *)p_input->p_private;
@@ -1051,7 +1065,7 @@
             {
                 /* Read the SCR. */
                 mtime_t scr_time;
-                uint32_t i_mux_rate;
+                uint32_t i_mux_rate = 0;
 
                 if( (p_data->p_demux_start[4] & 0xC0) == 0x40 )
                 {
@@ -1075,6 +1089,32 @@
                             | (mtime_t)U16_AT(p_header + 8) ) & 0x03FFF800)
                                         >> 11);
 
+		    if((p_mpeg_demux->base_scr_time == -1) && (p_mpeg_demux->base_file_offset == -1)) {
+			p_mpeg_demux->base_scr_time = scr_time;
+			p_mpeg_demux->base_file_offset = p_input->stream.p_selected_area->i_tell;
+		    }
+		    if(p_mpeg_demux->i_mux_rate_changes >= 10) {
+	    	        /* ReplayTV hack - back-compute mux rate from file position and scr_time */
+    			/* scr_time reference clock is 27MHz / 300, or 90,000 counts/second */
+			/* mux_rate scaled such that 1 mux_rate = 50 bytes/second */
+		        /* Only use this calculation if the mux rate is constantly changing */
+
+		        if(scr_time != p_mpeg_demux->base_scr_time) {
+			    i_file_delta = p_input->stream.p_selected_area->i_tell - p_mpeg_demux->base_file_offset;
+			    i_file_delta *= 1800;
+			    i_mux_rate = i_file_delta / ( scr_time - p_mpeg_demux->base_scr_time );
+			    /*
+			    printf("mux_rate=%u, pos=%u, len=%u, last_cr=%u, scr=%u\n", 
+				i_mux_rate,
+				(unsigned int)p_input->stream.p_selected_area->i_tell,
+				(unsigned int)p_input->stream.p_selected_area->i_size,\
+				(unsigned int)p_input->stream.p_selected_program->last_cr,
+				(unsigned int)scr_time);
+			    */
+			}
+		    }
+		    if(i_mux_rate <= 0) {
+
                     /* mux_rate */
                     i_mux_rate = ((uint32_t)U16_AT(p_header + 10) << 6)
                                    | (p_header[12] >> 2);
@@ -1085,6 +1125,7 @@
                     i_mux_rate <<= 1;
                     i_mux_rate /= 3;
                 }
+                }
                 else
                 {
                     /* MPEG-1 SCR is like PTS. */
@@ -1148,15 +1189,28 @@
                                   p_input->stream.p_selected_program,
                                   p_mpeg_demux->cur_scr_time );
           
+	    if( p_mpeg_demux->i_mux_rate_changes < 10 )
+	    {
             if( p_mpeg_demux->i_cur_mux_rate != p_input->stream.i_mux_rate
                 && p_input->stream.i_mux_rate )
             {
+    		    if(++p_mpeg_demux->i_mux_rate_changes < 10) {
                 msg_Warn( p_input,
                           "mux_rate changed prev: %ud, cur: %ud;"
                           " expect cosmetic errors" , 
                           (unsigned int) p_input->stream.i_mux_rate, 
                           (unsigned int) p_mpeg_demux->i_cur_mux_rate );
+		    } else {
+			/* When this happens frequently, switch to using byte offsets
+		         * and timestamp values so that ReplayTV files are handled 
+			 * nicely, without messing up files that have
+		         * well-conditioned mux_rate values */
+			msg_Warn( p_input, "Switching to offset/timestamp mux rate calculation"
+				" because the stream mux rate changed too frequently" );
+		    }
             }
+            }
+
             p_input->stream.i_mux_rate = p_mpeg_demux->i_cur_mux_rate;
         }
         vlc_mutex_lock( &p_input->stream.control.control_lock );
diff -rub vlc-0.7.2/modules/demux/mpeg/system.h vlc-0.7.2-phil/modules/demux/mpeg/system.h
--- vlc-0.7.2/modules/demux/mpeg/system.h	2004-04-22 04:08:15.000000000 -0400
+++ vlc-0.7.2-phil/modules/demux/mpeg/system.h	2004-06-03 19:58:33.515625000 -0400
@@ -128,6 +128,9 @@
     */
     uint32_t i_cur_mux_rate;
     mtime_t  cur_scr_time;
+    mtime_t  base_scr_time;
+    int64_t  base_file_offset;
+    uint32_t i_mux_rate_changes;
 
 } mpeg_demux_t;
 

