use native timestamps instead of time.Duration (#627)

this improves timestamp precision
This commit is contained in:
Alessandro Ros
2024-10-07 15:58:43 +02:00
committed by GitHub
parent 5ec470c827
commit 2ca0bffa20
33 changed files with 220 additions and 109 deletions

View File

@@ -3,18 +3,21 @@ package main
import (
"bufio"
"os"
"time"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/mediacommon/pkg/formats/mpegts"
)
func durationGoToMPEGTS(v time.Duration) int64 {
return int64(v.Seconds() * 90000)
func multiplyAndDivide(v, m, d int64) int64 {
secs := v / d
dec := v % d
return (secs*m + dec*m/d)
}
// mpegtsMuxer allows to save a MPEG-4 audio stream into a MPEG-TS file.
type mpegtsMuxer struct {
fileName string
format format.Format
track *mpegts.Track
f *os.File
@@ -43,6 +46,6 @@ func (e *mpegtsMuxer) close() {
}
// writeMPEG4Audio writes MPEG-4 audio access units into MPEG-TS.
func (e *mpegtsMuxer) writeMPEG4Audio(aus [][]byte, pts time.Duration) error {
return e.w.WriteMPEG4Audio(e.track, durationGoToMPEGTS(pts), aus)
func (e *mpegtsMuxer) writeMPEG4Audio(aus [][]byte, pts int64) error {
return e.w.WriteMPEG4Audio(e.track, multiplyAndDivide(pts, 90000, int64(e.format.ClockRate())), aus)
}