container/mts: GetPTSRange checks for PUSI when looking for first PTS

This commit is contained in:
Saxon 2019-07-01 12:36:11 +09:30
parent 74d22dde2e
commit 0497ee5302
1 changed files with 13 additions and 6 deletions

View File

@ -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)
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