--- /build/local/MPlayer-1.0rc2/libmpdemux/demux_ty.c.orig	2008-03-05 20:00:23.000000000 -0800
+++ /build/local/MPlayer-1.0rc2/libmpdemux/demux_ty.c	2008-03-05 20:19:10.000000000 -0800
@@ -427,11 +427,25 @@
 
                if ( readSize == CHUNKSIZE && AV_RB32(chunk) == TIVO_PES_FILEID )
                {
-                     int size = AV_RB24(chunk + 12);
-                     size -= 4;
+                     off_t size = AV_RB24(chunk + 12);
                      size *= CHUNKSIZE;
-                     tivo->size = numberParts * TIVO_PART_LENGTH;
-                     tivo->size += size;
+		     size += numberParts * TIVO_PART_LENGTH;
+
+		     if (tivo->tmf != 1) {
+			 /* If this isn't TMF, there may be more chained
+			  * PES headers on the end of this PART */
+			 while ( size + CHUNKSIZE * 2 <
+				 demux->stream->end_pos ) {
+			     stream_seek( demux->stream, size + CHUNKSIZE );
+			     readSize = stream_read(demux->stream, chunk,
+						    CHUNKSIZE);
+			     if ( readSize != CHUNKSIZE ||
+				  AV_RB32(chunk) != TIVO_PES_FILEID ) break;
+			     size += (AV_RB24(chunk + 12) + 1) * CHUNKSIZE;
+			 }
+		     }
+                     size -= 4 * CHUNKSIZE;
+                     tivo->size = size;
                      mp_msg( MSGT_DEMUX, MSGL_DBG3,
                         "ty:Header Calc Stream Size %"PRId64"\n", tivo->size );
                }
