fix(hls): correct LLHLS timestamps and SPS context handling - #402
Open
tadebao wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes LL-HLS output correctness and stability in the HLS plugin by correcting timestamp units passed into gohlslib and avoiding stale (captured) video codec parameter sets when SPS/PPS/VPS changes at runtime.
Changes:
- Pass real presentation timestamps (
Timestamp + CTS,time.Durationin nanoseconds) toMuxer.WriteH264/WriteH265instead ofGetPTS()(90kHz ticks). - On IDR frames, fetch the latest video codec context from the publisher and prepend current SPS/PPS (H264) or VPS/SPS/PPS (H265) into the access unit to prevent crashes caused by outdated parameter sets.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
LL-HLS 输出不可用(针对 GB28181 摄像头实测):
切片时长 0.54ms / bitrate 5.6Gbps:
llhls.go用v.GetPTS()作为gohlslib.WriteH264/WriteH265的时间参数。但GetPTS()返回的是 90kHz tick 数((Timestamp+CTS)*90/time.Millisecond),而 gohlslib 期望真实time.Duration(纳秒)。帧间隔 40ms 被解释为 3.6µs,一个 GOP(150 帧)只有 540µs → 切片 0.54ms、BANDWIDTH 5.6Gbps。Muxer 每 2 秒崩溃重试:
videoFunc闭包捕获了Run()开始时的旧 codec context。摄像头 SPS 变化后,DTS extractor 报invalid SPS: invalid pic_order_cnt_type: 6,Muxer 崩溃 → subscribe → 读取几帧 → 又崩溃,无限循环,stream.m3u8时常为空。修复
时间单位修正:
v.GetPTS()→ts + v.CTS(Timestamp本身是纳秒time.Duration,v.CTS同理)。H264/H265 两条路径都改。动态获取最新编码上下文:IDR 帧时不再使用闭包捕获的
ctx,而是subscriber.Publisher.GetVideoCodecCtx()现场取最新 SPS/PPS/VPS,避免旧 context 的 SPS 与当前流不匹配导致 extractor 崩溃。验证(真实 GB28181 摄像头 + watch 页面双流)
index.m3u8/stream.m3u8参数正常)-tags sqlite编译(纯 Go sqlite driver,无 CGO),本地 smoke test 插件加载正常后部署备注
改动最小化:仅
plugin/hls/llhls.go,+15/-4。