fix PESUIntToTs problem

This commit is contained in:
nareix 2015-12-05 14:26:52 +08:00
parent 841ebf6b90
commit 77392eddb2
3 changed files with 8 additions and 5 deletions

View File

@ -15,6 +15,7 @@ type Stream struct {
Header *ts.PESHeader Header *ts.PESHeader
Title string Title string
Data bytes.Buffer Data bytes.Buffer
Type uint
} }
func main() { func main() {
@ -39,10 +40,11 @@ func main() {
if stream == nil { if stream == nil {
stream = &Stream{ stream = &Stream{
PID: pid, PID: pid,
Type: info.StreamType,
} }
if info.StreamType == ts.ElementaryStreamTypeH264 { if stream.Type == ts.ElementaryStreamTypeH264 {
stream.Title = "h264" stream.Title = "h264"
} else if info.StreamType == ts.ElementaryStreamTypeAdtsAAC { } else if stream.Type == ts.ElementaryStreamTypeAdtsAAC {
stream.Title = "aac" stream.Title = "aac"
} }
streams[pid] = stream streams[pid] = stream
@ -64,7 +66,7 @@ func main() {
return return
} }
if stream.Data.Len() == int(stream.Header.DataLength) { 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())) fmt.Println(hex.Dump(stream.Data.Bytes()))
} }
return return

View File

@ -516,7 +516,8 @@ func ReadPESHeader(r io.Reader) (res *PESHeader, err error) {
self.PTS = PESUIntToTs(v) self.PTS = PESUIntToTs(v)
if debug { 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)
} }
} }

2
ts.go
View File

@ -64,7 +64,7 @@ type PESHeader struct {
func PESUIntToTs(v uint64) (ts uint64) { func PESUIntToTs(v uint64) (ts uint64) {
// 0010 PTS 32..30 1 PTS 29..15 1 PTS 14..00 1 // 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 { func UIntToPCR(v uint64) uint64 {