From fc6283a5edde85adf09c65745affd79a710574cb Mon Sep 17 00:00:00 2001 From: qydysky Date: Sat, 7 Oct 2023 02:40:22 +0800 Subject: [PATCH] =?utf8?q?Fix=20=20chrome=E4=B8=8A=E9=9F=B3=E7=94=BB?= =?utf8?q?=E4=B8=8D=E5=90=8C=E6=AD=A5=E3=80=81=E8=80=8Cfirefox=E5=88=99?= =?utf8?q?=E4=B8=8D=E4=BC=9A=20#89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F/comp.go | 2 +- Reply/fmp4Decode.go | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Reply/F/comp.go b/Reply/F/comp.go index 70a05e8..39cf657 100644 --- a/Reply/F/comp.go +++ b/Reply/F/comp.go @@ -11,7 +11,7 @@ func init() { var linkMap = map[string][]string{ "github.com/qydysky/bili_danmu/Reply.startRecDanmu.stop": { comp.Sign[danmuXml.Sign](`toXml`), - comp.Sign[reSetMp4TimeStamp.Sign](`resetTS`), + comp.Sign[reSetMp4TimeStamp.Sign](`_resetTS`), // comp.Sign[fmp4Tomp4.Sign](`conver`), }, "github.com/qydysky/bili_danmu/Reply.SerF.player.ws": { diff --git a/Reply/fmp4Decode.go b/Reply/fmp4Decode.go index ba055cd..21e5620 100644 --- a/Reply/fmp4Decode.go +++ b/Reply/fmp4Decode.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "io" + "math" "github.com/dustin/go-humanize" F "github.com/qydysky/bili_danmu/F" @@ -41,24 +42,25 @@ type ie struct { } type trak struct { - timescale int - trackID int - handlerType byte + firstTimeStamp int + timescale int + trackID int + handlerType byte } type timeStamp struct { - timeStamp int - data []byte - timescale int - handlerType byte + timeStamp int + data []byte + firstTimeStamp int + handlerType byte } func (t *timeStamp) getT() float64 { - return float64(t.timeStamp) / float64(t.timescale) + return float64(t.timeStamp) / float64(t.firstTimeStamp) } type Fmp4Decoder struct { - traks map[int]trak + traks map[int]*trak buf *slice.Buf[byte] } @@ -89,12 +91,13 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) (b []byte, err error) { func(m []ie) bool { tackId := int(F.Btoi(buf, m[0].i+20, 4)) if t.traks == nil { - t.traks = make(map[int]trak) + t.traks = make(map[int]*trak) } - t.traks[tackId] = trak{ - trackID: tackId, - timescale: int(F.Btoi(buf, m[2].i+20, 4)), - handlerType: buf[m[3].i+16], + t.traks[tackId] = &trak{ + trackID: tackId, + firstTimeStamp: -1, + timescale: int(F.Btoi(buf, m[2].i+20, 4)), + handlerType: buf[m[3].i+16], } return false }) @@ -151,8 +154,11 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte]) track, ok := t.traks[int(F.Btoi(buf, tfhd+12, 4))] if ok { ts := get_timeStamp(tfdt) + if track.firstTimeStamp == -1 { + track.firstTimeStamp = ts.timeStamp + } ts.handlerType = track.handlerType - ts.timescale = track.timescale + ts.firstTimeStamp = track.firstTimeStamp return ts, track.handlerType } return @@ -324,8 +330,8 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte]) } //sync audio timeStamp - if audio.getT() != video.getT() { - date := F.Itob64(int64(video.getT() * float64(audio.timescale))) + if diff := math.Abs(audio.getT() - video.getT()); diff > 0.00001 { + date := F.Itob64(int64(video.getT() * float64(audio.firstTimeStamp))) copy(audio.data, date) } -- 2.39.2