diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index 3f3851a3..25e36ff1 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -320,15 +320,22 @@ func DiscontinuityIndicator(f bool) Option { // GetPTSRange retreives the first and last PTS of an MPEGTS clip. func GetPTSRange(clip []byte, pid uint16) (pts [2]uint64, err error) { - // Find the first packet with PID pidType. - pkt, _, err := FindPid(clip, pid) - if err != nil { - return [2]uint64{}, err + var _pkt packet.Packet + // Find the first packet with PID pidType and PUSI. + var i int + for { + pkt, _i, err := FindPid(clip[i:], pid) + if err != nil { + return [2]uint64{}, err + } + copy(_pkt[:], pkt) + if _pkt.PayloadUnitStartIndicator() { + break + } + i = _i + PacketSize } // Get the payload of the packet, which will be the start of the PES packet. - var _pkt packet.Packet - copy(_pkt[:], pkt) payload, err := packet.Payload(&_pkt) if err != nil { return [2]uint64{}, err