Browse Source

hls muxer: stop normalizing PTS

pull/1003/head
aler9 3 years ago
parent
commit
4073013f68
  1. 2
      go.mod
  2. 4
      go.sum
  3. 1
      internal/core/rtmp_conn.go
  4. 16
      internal/hls/muxer_variant_fmp4_segmenter.go
  5. 3
      internal/hls/muxer_variant_mpegts_segment.go
  6. 1
      internal/hls/muxer_variant_mpegts_segmenter.go

2
go.mod

@ -5,7 +5,7 @@ go 1.17 @@ -5,7 +5,7 @@ go 1.17
require (
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
github.com/abema/go-mp4 v0.7.2
github.com/aler9/gortsplib v0.0.0-20220602183811-46253a74b083
github.com/aler9/gortsplib v0.0.0-20220602202513-787c516d791e
github.com/asticode/go-astits v1.10.1-0.20220319093903-4abe66a9b757
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.7.2

4
go.sum

@ -6,8 +6,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo @@ -6,8 +6,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20220602183811-46253a74b083 h1:VmY5jw7jBl4PTX7J9UIrslRRco1ELt9oDteq9CmecqU=
github.com/aler9/gortsplib v0.0.0-20220602183811-46253a74b083/go.mod h1:i1e4CEs42IrbidMUNTSNOKmeGPCOHVX9P3BvPxzyMtI=
github.com/aler9/gortsplib v0.0.0-20220602202513-787c516d791e h1:OCMAhEoYzacPQ6et2EKt/xy4kXksSoYFLXP9ROlH/1c=
github.com/aler9/gortsplib v0.0.0-20220602202513-787c516d791e/go.mod h1:i1e4CEs42IrbidMUNTSNOKmeGPCOHVX9P3BvPxzyMtI=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc=
github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82 h1:9WgSzBLo3a9ToSVV7sRTBYZ1GGOZUpq4+5H3SN0UZq4=

1
internal/core/rtmp_conn.go

@ -367,6 +367,7 @@ func (c *rtmpConn) runRead(ctx context.Context) error { @@ -367,6 +367,7 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
videoDTSExtractor = h264.NewDTSExtractor()
}
// normalize as this is expected in RTMP
pts -= videoFirstIDRPTS
dts, err := videoDTSExtractor.Extract(data.h264NALUs, pts)

16
internal/hls/muxer_variant_fmp4_segmenter.go

@ -57,7 +57,6 @@ type muxerVariantFMP4Segmenter struct { @@ -57,7 +57,6 @@ type muxerVariantFMP4Segmenter struct {
videoFirstIDRReceived bool
videoDTSExtractor *h264.DTSExtractor
videoSPS []byte
startPTS time.Duration
currentSegment *muxerVariantFMP4Segment
nextSegmentID uint64
nextPartID uint64
@ -157,9 +156,6 @@ func (m *muxerVariantFMP4Segmenter) writeH264Entry(sample *fmp4VideoSample) erro @@ -157,9 +156,6 @@ func (m *muxerVariantFMP4Segmenter) writeH264Entry(sample *fmp4VideoSample) erro
}
sample.nalus = nil
sample.pts -= m.startPTS
sample.dts -= m.startPTS
// put samples into a queue in order to
// - allow to compute sample duration
// - check if next sample is IDR
@ -184,12 +180,6 @@ func (m *muxerVariantFMP4Segmenter) writeH264Entry(sample *fmp4VideoSample) erro @@ -184,12 +180,6 @@ func (m *muxerVariantFMP4Segmenter) writeH264Entry(sample *fmp4VideoSample) erro
m.genPartID,
m.onPartFinalized,
)
m.startPTS = sample.pts
sample.pts = 0
sample.dts = 0
sample.next.pts -= m.startPTS
sample.next.dts -= m.startPTS
}
m.adjustPartDuration(sample.duration())
@ -252,8 +242,6 @@ func (m *muxerVariantFMP4Segmenter) writeAAC(pts time.Duration, aus [][]byte) er @@ -252,8 +242,6 @@ func (m *muxerVariantFMP4Segmenter) writeAAC(pts time.Duration, aus [][]byte) er
}
func (m *muxerVariantFMP4Segmenter) writeAACEntry(sample *fmp4AudioSample) error {
sample.pts -= m.startPTS
// put samples into a queue in order to
// allow to compute the sample duration
sample, m.nextAudioSample = m.nextAudioSample, sample
@ -278,10 +266,6 @@ func (m *muxerVariantFMP4Segmenter) writeAACEntry(sample *fmp4AudioSample) error @@ -278,10 +266,6 @@ func (m *muxerVariantFMP4Segmenter) writeAACEntry(sample *fmp4AudioSample) error
m.genPartID,
m.onPartFinalized,
)
m.startPTS = sample.pts
sample.pts = 0
sample.next.pts -= m.startPTS
}
} else {
// wait for the video track

3
internal/hls/muxer_variant_mpegts_segment.go

@ -188,7 +188,8 @@ func (t *muxerVariantMPEGTSSegment) writeAAC( @@ -188,7 +188,8 @@ func (t *muxerVariantMPEGTSSegment) writeAAC(
OptionalHeader: &astits.PESOptionalHeader{
MarkerBits: 2,
PTSDTSIndicator: astits.PTSDTSIndicatorOnlyPTS,
PTS: &astits.ClockReference{Base: int64((pts + mpegtsPTSDTSOffset + mpegtsPCROffset).Seconds() * 90000)},
PTS: &astits.ClockReference{Base: int64((pts + mpegtsPTSDTSOffset +
mpegtsPCROffset).Seconds() * 90000)},
},
PacketLength: uint16(len(enc) + 8),
StreamID: 192, // audio

1
internal/hls/muxer_variant_mpegts_segmenter.go

@ -95,6 +95,7 @@ func (m *muxerVariantMPEGTSSegmenter) writeH264(pts time.Duration, nalus [][]byt @@ -95,6 +95,7 @@ func (m *muxerVariantMPEGTSSegmenter) writeH264(pts time.Duration, nalus [][]byt
m.videoDTSExtractor = h264.NewDTSExtractor()
pts = 0
} else {
// normalize in order to sync with PCR
pts -= m.startPTS
// switch segment

Loading…
Cancel
Save