Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions plugin/hls/llhls.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ func (ll *LLMuxer) Run() (err error) {
ts := v.Timestamp
var au [][]byte
if subscriber.VideoReader.Value.IDR {
au = append(au, ctx.SPS(), ctx.PPS())
// 动态获取最新编码上下文,避免闭包捕获旧 SPS 导致 extractor 崩溃
if c := subscriber.Publisher.GetVideoCodecCtx(); c != nil {
if hc, ok := c.GetBase().(*codec.H264Ctx); ok {
au = append(au, hc.SPS(), hc.PPS())
}
}
}
for buffer := range v.Raw.(*pkg.Nalus).RangePoint {
au = append(au, buffer.Buffers...)
}
return ll.Muxer.WriteH264(time.Now().Add(ts-ll.Muxer.SegmentMinDuration), v.GetPTS(), au)
// GetPTS() 返回 90kHz tick 数,gohlslib 期望真实时间 Duration,改用 ts+v.CTS
return ll.Muxer.WriteH264(time.Now().Add(ts-ll.Muxer.SegmentMinDuration), ts+v.CTS, au)
}
case *codec.H265Ctx:
ll.Muxer.VideoTrack.Codec = &codecs.H265{
Expand All @@ -142,12 +148,17 @@ func (ll *LLMuxer) Run() (err error) {
videoFunc = func(v *pkg.AVFrame) (err error) {
var au [][]byte
if subscriber.VideoReader.Value.IDR {
au = append(au, ctx.VPS(), ctx.SPS(), ctx.PPS())
// 动态获取最新编码上下文
if c := subscriber.Publisher.GetVideoCodecCtx(); c != nil {
if hc, ok := c.GetBase().(*codec.H265Ctx); ok {
au = append(au, hc.VPS(), hc.SPS(), hc.PPS())
}
}
}
for buffer := range v.Raw.(*pkg.Nalus).RangePoint {
au = append(au, buffer.Buffers...)
}
return ll.Muxer.WriteH265(time.Now().Add(v.Timestamp-ll.Muxer.SegmentMinDuration), v.GetPTS(), au)
return ll.Muxer.WriteH265(time.Now().Add(v.Timestamp-ll.Muxer.SegmentMinDuration), v.Timestamp+v.CTS, au)
}
}
}
Expand Down