diff --git a/example/test.go b/example/test.go index 0b11c3f..7666aed 100644 --- a/example/test.go +++ b/example/test.go @@ -15,6 +15,7 @@ type Stream struct { Header *ts.PESHeader Title string Data bytes.Buffer + Type uint } func main() { @@ -39,10 +40,11 @@ func main() { if stream == nil { stream = &Stream{ PID: pid, + Type: info.StreamType, } - if info.StreamType == ts.ElementaryStreamTypeH264 { + if stream.Type == ts.ElementaryStreamTypeH264 { stream.Title = "h264" - } else if info.StreamType == ts.ElementaryStreamTypeAdtsAAC { + } else if stream.Type == ts.ElementaryStreamTypeAdtsAAC { stream.Title = "aac" } streams[pid] = stream @@ -64,7 +66,7 @@ func main() { return } if stream.Data.Len() == int(stream.Header.DataLength) { - fmt.Println(stream.Title, stream.Data.Len(), "total") + fmt.Println(stream.Type, stream.Title, stream.Data.Len(), "total") fmt.Println(hex.Dump(stream.Data.Bytes())) } return diff --git a/reader.go b/reader.go index 9012cf5..6054f8a 100644 --- a/reader.go +++ b/reader.go @@ -516,7 +516,8 @@ func ReadPESHeader(r io.Reader) (res *PESHeader, err error) { self.PTS = PESUIntToTs(v) if debug { - fmt.Printf("pes: pts %d %f\n", self.PTS, float64(self.PTS)/90000) + fmt.Printf("pes: pts %x(%x)=>%x %f\n", + v, (v>>1)&0xef, self.PTS, float64(self.PTS)/90000) } } diff --git a/ts.go b/ts.go index 4cf1ff4..bfebd1b 100644 --- a/ts.go +++ b/ts.go @@ -64,7 +64,7 @@ type PESHeader struct { func PESUIntToTs(v uint64) (ts uint64) { // 0010 PTS 32..30 1 PTS 29..15 1 PTS 14..00 1 - return (((v>>33)&0x7)<<30) | (((v>>17)&0xef)<<15) | ((v>>1)&0xef) + return (((v>>33)&0x7)<<30) | (((v>>17)&0x7fff)<<15) | ((v>>1)&0x7fff) } func UIntToPCR(v uint64) uint64 {