 					break;
 				case _pmtId:
 					todo -= _readPMT();
+			    if(_pmtParsed == false) {
+			      _pmtParsed = true;
+			    // if PMT was not parsed before, and some unknown packets have been skipped in between, 
+			    // rewind to beginning of the stream, it helps recovering bad segmented content
+			    // in theory there should be no A/V packets before PAT/PMT)
+			      if (_packetsBeforePMT) {
+			        Log.txt("late PMT found, rewinding at beginning of TS");
+			        _data.position = 0;
+			        return;
+			      }
+		      }
 					break;
 				case _aacId:
 				case _mp3Id:

			var todo:uint = TS.PACKETSIZE;
			// Sync byte.
			if(_data.readByte() != TS.SYNCBYTE) {
				throw new Error("Could not parse TS file: sync byte not found @ offset/len " + _data.position + "/"+ _data.length);
			}
			todo--;
			// Payload unit start indicator.

		/* callback function upon read complete */
		private var _callback:Function;
		
		
		public static function probe(data:ByteArray):Boolean {
		  var pos:Number = data.position;
		  var len:Number = Math.min(data.bytesAvailable,188);
		  for(var i:Number = 0; i < len ; i++) {
		    if(data.readByte() == SYNCBYTE) {
		      data.position = pos+i;
		      return true;
		    }
		  }
		  data.position = pos;
		  return false;
		}
		
		/** Transmux the M2TS file into an FLV file. **/
		public function TS(data:ByteArray,callback:Function) {
			// Extract the elementary streams.
