]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix 高清状态下出现时间戳不匹配 #96
authorqydysky <qydysky@foxmail.com>
Thu, 4 Jan 2024 13:00:26 +0000 (21:00 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 4 Jan 2024 13:00:26 +0000 (21:00 +0800)
Reply/fmp4Decode.go
Reply/stream.go
demo/config/config_K_v.json

index d03ded16412475ca2a01716f6219c7ad25b2be74..b4955243b7d1a755958a7d357f65fe4200ee18f2 100644 (file)
@@ -75,6 +75,8 @@ func (t *timeStamp) getT() float64 {
 type Fmp4Decoder struct {
        traks map[int]*trak
        buf   *slice.Buf[byte]
+
+       AVTDiff float64 // 音视频时间戳容差
 }
 
 func (t *Fmp4Decoder) Init_fmp4(buf []byte) (b []byte, err error) {
@@ -352,8 +354,11 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte])
                                }
 
                                //sync audio timeStamp
-                               if math.Abs(video.getT()-audio.getT()) > 0.1 {
-                                       return false, fmt.Errorf("时间戳不匹配%v %v", video.timeStamp, audio.timeStamp)
+                               if t.AVTDiff <= 0.1 {
+                                       t.AVTDiff = 0.1
+                               }
+                               if diff := math.Abs(video.getT() - audio.getT()); diff > t.AVTDiff {
+                                       return false, fmt.Errorf("时间戳不匹配 %v %v (或许应调整fmp4音视频时间戳容差s>%.2f)", video.timeStamp, audio.timeStamp, diff)
                                        // copy(video.data, F.Itob64(int64(audio.getT()*float64(video.timescale))))
                                }
 
index d4249e21563392ea57274202092e3a8102ae750d..f1bfd68e60e4607d9fe0c324ea0632da43aeca9e 100644 (file)
@@ -900,6 +900,9 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                fmp4ListUpdateTo = 5.0
        )
 
+       if v, ok := t.common.K_v.LoadV(`fmp4音视频时间戳容差s`).(float64); ok && v > 0.1 {
+               fmp4Decoder.AVTDiff = v
+       }
        if v, ok := t.common.K_v.LoadV(`fmp4切片下载超时s`).(float64); ok && to < int(v) {
                to = int(v)
        }
index 7137078409ed530ff953f4a6924876b344e90f6c..9b86b9df8b4c9204758ef25a67015943433ceb8c 100644 (file)
@@ -75,6 +75,8 @@
     "flv断流续接": true,
     "fmp4切片下载超时s": 3,
     "fmp4列表更新超时s": 7,
+    "fmp4音视频时间戳容差s-help": "默认0.1,小于默认无效,调大可以允许较差的流,但可能会音画不同步",
+    "fmp4音视频时间戳容差s": 0.2,
     "分段时长min-help": "=0为不启动功能,>0为指定分钟数时分段",
     "分段时长min": 0,
     "直播流保存位置": "./live",