diff --git a/mpegtsmod.py b/mpegtsmod.py index 3ef734b..042ba35 100644 --- a/mpegtsmod.py +++ b/mpegtsmod.py @@ -344,7 +344,27 @@ class MultiMPEGTS(FSObject, StorageFolder): if doupdate: StorageFolder.doUpdate(self) +def findtsstream(fp, pktsz=188): + d = fp.read(200*pktsz) + i = 5 + pos = 0 + while i and pos < len(d) and pos != -1: + if d[pos] == 'G': + i -= 1 + pos += pktsz + else: + i = 5 + pos = d.find('G', pos + 1) + + if i or pos == -1: + return False + + return True + def detectmpegts(path, fobj): + if not findtsstream(fobj): + return None, None + f = mpegts.TSPStream(_LimitedFile(path, size= 2*1024*1024)) tvct = mpegts.GetTVCT(f)