def ReadPESHeader(self, offset, buffer, id=0):
        """
        Parse a PES header.
        Since it starts with 0x00 0x00 0x01 like 'normal' mpegs, this
        function will return (0, None) when it is no PES header or
        (packet length, timestamp position (maybe None))

        http://dvd.sourceforge.net/dvdinfo/pes-hdr.html
        """
        if not buffer[0:3] == '\x00\x00\x01':
            return 0, None

        packet_length = (indexbytes(buffer, 4) << 8) + indexbytes(buffer, 5) + 6
        align = indexbytes(buffer, 6) & 4
        header_length = indexbytes(buffer, 8)

        # PES ID (starting with 001)
        if indexbytes(buffer, 3) & 0xE0 == 0xC0:
            id = id or indexbytes(buffer, 3) & 0x1F
            for a in self.audio:
                if a.id == id:
                    break
            else:
                self.audio.append(core.AudioStream())
                self.audio[-1]._set('id', id)

        elif indexbytes(buffer, 3) & 0xF0 == 0xE0:
            id = id or indexbytes(buffer, 3) & 0xF
            for v in self.video:
                if v.id == id:
                    break
            else:
                self.video.append(core.VideoStream())
                self.video[-1]._set('id', id)

            # new mpeg starting
            if buffer[header_length + 9:header_length + 13] == \
                    '\x00\x00\x01\xB3' and not self.sequence_header_offset:
                # yes, remember offset for later use
                self.sequence_header_offset = offset + header_length + 9
        elif indexbytes(buffer, 3) == 189 or indexbytes(buffer, 3) == 191:
            # private stream. we don't know, but maybe we can guess later
            id = id or indexbytes(buffer, 3) & 0xF
            if align and \
                    buffer[header_length + 9:header_length + 11] == '\x0b\x77':
                # AC3 stream
                for a in self.audio:
                    if a.id == id:
                        break
                else:
                    self.audio.append(core.AudioStream())
                    self.audio[-1]._set('id', id)
                    self.audio[-1].codec = 0x2000  # AC3

        else:
            # unknown content
            pass

        ptsdts = indexbytes(buffer, 7) >> 6

        if ptsdts and ptsdts == indexbytes(buffer, 9) >> 4:
            if indexbytes(buffer, 9) >> 4 != ptsdts:
                log.warning(u'WARNING: bad PTS/DTS, please contact us')
                return packet_length, None

            # timestamp = self.ReadPTS(buffer[9:14])
            high = ((indexbytes(buffer, 9) & 0xF) >> 1)
            med = (indexbytes(buffer, 10) << 7) + (indexbytes(buffer, 11) >> 1)
            low = (indexbytes(buffer, 12) << 7) + (indexbytes(buffer, 13) >> 1)
            return packet_length, 9

        return packet_length, None