change float64->float32
This commit is contained in:
parent
366f7b4dfa
commit
c463a3678f
@ -42,4 +42,3 @@ func WalkFile(w Walker, r io.Reader) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -93,4 +93,3 @@ func (self Dumper) Bytes(val []byte) {
|
||||
func (self Dumper) TimeStamp(val TimeStamp) {
|
||||
self.Println(fmt.Sprintf("%s: %d", self.name, int(val)))
|
||||
}
|
||||
|
||||
|
12
demuxer.go
12
demuxer.go
@ -4,10 +4,10 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/nareix/av"
|
||||
"github.com/nareix/mp4/atom"
|
||||
"github.com/nareix/mp4/isom"
|
||||
"github.com/nareix/codec/aacparser"
|
||||
"github.com/nareix/codec/h264parser"
|
||||
"github.com/nareix/mp4/atom"
|
||||
"github.com/nareix/mp4/isom"
|
||||
"io"
|
||||
)
|
||||
|
||||
@ -322,7 +322,7 @@ func (self *Demuxer) ReadPacket() (streamIndex int, pkt av.Packet, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (self *Demuxer) CurrentTime() (time float64) {
|
||||
func (self *Demuxer) CurrentTime() (time float32) {
|
||||
if len(self.streams) > 0 {
|
||||
stream := self.streams[0]
|
||||
time = stream.tsToTime(stream.dts)
|
||||
@ -330,7 +330,7 @@ func (self *Demuxer) CurrentTime() (time float64) {
|
||||
return
|
||||
}
|
||||
|
||||
func (self *Demuxer) SeekToTime(time float64) (err error) {
|
||||
func (self *Demuxer) SeekToTime(time float32) (err error) {
|
||||
for _, stream := range self.streams {
|
||||
if stream.IsVideo() {
|
||||
if err = stream.seekToTime(time); err != nil {
|
||||
@ -395,7 +395,7 @@ func (self *Stream) readPacket() (pkt av.Packet, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (self *Stream) seekToTime(time float64) (err error) {
|
||||
func (self *Stream) seekToTime(time float32) (err error) {
|
||||
index := self.timeToSampleIndex(time)
|
||||
if err = self.setSampleIndex(index); err != nil {
|
||||
return
|
||||
@ -406,7 +406,7 @@ func (self *Stream) seekToTime(time float64) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (self *Stream) timeToSampleIndex(time float64) int {
|
||||
func (self *Stream) timeToSampleIndex(time float32) int {
|
||||
targetTs := self.timeToTs(time)
|
||||
targetIndex := 0
|
||||
|
||||
|
8
muxer.go
8
muxer.go
@ -184,7 +184,7 @@ func (self *Muxer) WritePacket(streamIndex int, pkt av.Packet) (err error) {
|
||||
}
|
||||
newpkt := pkt
|
||||
newpkt.Data = payload
|
||||
newpkt.Duration = float64(samples)/float64(sampleRate)
|
||||
newpkt.Duration = float32(samples) / float32(sampleRate)
|
||||
if err = stream.writePacket(newpkt); err != nil {
|
||||
return
|
||||
}
|
||||
@ -258,21 +258,21 @@ func (self *Muxer) WriteTrailer() (err error) {
|
||||
NextTrackId: 2,
|
||||
}
|
||||
|
||||
maxDur := float64(0)
|
||||
maxDur := float32(0)
|
||||
timeScale := 10000
|
||||
for _, stream := range self.streams {
|
||||
if err = stream.fillTrackAtom(); err != nil {
|
||||
return
|
||||
}
|
||||
dur := stream.tsToTime(stream.duration)
|
||||
stream.trackAtom.Header.Duration = int(float64(timeScale) * dur)
|
||||
stream.trackAtom.Header.Duration = int(float32(timeScale) * dur)
|
||||
if dur > maxDur {
|
||||
maxDur = dur
|
||||
}
|
||||
moov.Tracks = append(moov.Tracks, stream.trackAtom)
|
||||
}
|
||||
moov.Header.TimeScale = timeScale
|
||||
moov.Header.Duration = int(float64(timeScale) * maxDur)
|
||||
moov.Header.Duration = int(float32(timeScale) * maxDur)
|
||||
|
||||
if err = self.mdatWriter.Close(); err != nil {
|
||||
return
|
||||
|
10
stream.go
10
stream.go
@ -14,7 +14,7 @@ type Stream struct {
|
||||
idx int
|
||||
|
||||
timeScale int64
|
||||
duration int64
|
||||
duration int64
|
||||
|
||||
muxer *Muxer
|
||||
|
||||
@ -39,10 +39,10 @@ type Stream struct {
|
||||
cttsEntry *atom.CompositionOffsetEntry
|
||||
}
|
||||
|
||||
func (self *Stream) timeToTs(time float64) int64 {
|
||||
return int64(time * float64(self.timeScale))
|
||||
func (self *Stream) timeToTs(time float32) int64 {
|
||||
return int64(time * float32(self.timeScale))
|
||||
}
|
||||
|
||||
func (self *Stream) tsToTime(ts int64) float64 {
|
||||
return float64(ts) / float64(self.timeScale)
|
||||
func (self *Stream) tsToTime(ts int64) float32 {
|
||||
return float32(ts) / float32(self.timeScale)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user