diff --git a/demuxer.go b/demuxer.go index 3c4fec2..dbcdefa 100644 --- a/demuxer.go +++ b/demuxer.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "time" "github.com/nareix/av" "github.com/nareix/av/pktqueue" "github.com/nareix/codec/aacparser" @@ -41,9 +42,9 @@ func (self *Demuxer) Streams() (streams []av.CodecData, err error) { return } -func (self *Demuxer) CurrentTime() (time float32) { +func (self *Demuxer) CurrentTime() (tm time.Duration) { if self.pktque != nil { - time = self.pktque.CurrentTime() + tm = self.pktque.CurrentTime() } return } @@ -158,11 +159,11 @@ func (self *Stream) payloadEnd() (err error) { IsKeyFrame: self.tshdr.RandomAccessIndicator, Data: payload, } - time := float32(dts) / float32(PTS_HZ) + tm := time.Duration(dts)*time.Second / time.Duration(PTS_HZ) if pts != dts { - pkt.CompositionTime = float32(pts-dts) / float32(PTS_HZ) + pkt.CompositionTime = time.Duration(pts-dts)*time.Second / time.Duration(PTS_HZ) } - self.demuxer.pktque.WriteTimePacket(self.idx, time, pkt) + self.demuxer.pktque.WriteTimePacket(self.idx, tm, pkt) self.demuxer.gotpkt = true if self.CodecData == nil { diff --git a/stream.go b/stream.go index 3c6b8ed..6410aea 100644 --- a/stream.go +++ b/stream.go @@ -1,6 +1,7 @@ package ts import ( + "time" "bytes" "github.com/nareix/av" ) @@ -25,13 +26,13 @@ type Stream struct { idx int pkt av.Packet - time float32 + time time.Duration } -func timeToPesTs(time float32) uint64 { - return uint64(time*PTS_HZ) + PTS_HZ +func timeToPesTs(tm time.Duration) uint64 { + return uint64(tm*PTS_HZ/time.Second) + PTS_HZ } -func timeToPCR(time float32) uint64 { - return uint64(time*PCR_HZ) + PCR_HZ +func timeToPCR(tm time.Duration) uint64 { + return uint64(tm*PCR_HZ/time.Second) + PCR_HZ }