From 78a516a68f98f31830ba502f77dc151c6f1ad807 Mon Sep 17 00:00:00 2001 From: qydysky Date: Thu, 5 Oct 2023 16:06:52 +0800 Subject: [PATCH] =?utf8?q?Fix=20=20=E9=87=8D=E7=BD=AE=E6=97=B6=E9=97=B4?= =?utf8?q?=E6=88=B3=E5=90=8E=E7=9A=84=E6=96=87=E4=BB=B6=E5=AF=BC=E8=87=B4f?= =?utf8?q?fmpeg=20error=20#88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../F/reSetMp4TimeStamp/reSetMp4TimeStamp.go | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Reply/F/reSetMp4TimeStamp/reSetMp4TimeStamp.go b/Reply/F/reSetMp4TimeStamp/reSetMp4TimeStamp.go index 3f44123..bf5b664 100644 --- a/Reply/F/reSetMp4TimeStamp/reSetMp4TimeStamp.go +++ b/Reply/F/reSetMp4TimeStamp/reSetMp4TimeStamp.go @@ -143,7 +143,11 @@ func resetTS(ctx context.Context, ptr *string) error { case 0: ts := int64(btoi32(byte16, 12)) if eddts[trackID] != 0 && zdts[trackID] != 0 { - ts = eddts[trackID] + zdts[trackID] + guessTs := eddts[trackID] + zdts[trackID] + if diff(guessTs, ts, 10000) { + fmt.Println("diff ts >10", ts, guessTs) + ts = guessTs + } } if e := f.SeekIndex(-4, file.AtCurrent); e != nil { return e @@ -157,7 +161,11 @@ func resetTS(ctx context.Context, ptr *string) error { } else if chosenId == trackID { chosenT = float64(cu) / float64(zdts[trackID]) } else { - cu = int64(chosenT * float64(zdts[trackID])) + guessCu := int64(chosenT * float64(zdts[trackID])) + if diff(cu, guessCu, 10) { + fmt.Println("diff cu >10", cu, guessCu) + cu = guessCu + } } if _, e := f.Write(itob32(int32(cu)), false); e != nil { return e @@ -166,7 +174,11 @@ func resetTS(ctx context.Context, ptr *string) error { case 1: ts := btoi64(byte16, 8) if eddts[trackID] != 0 && zdts[trackID] != 0 { - ts = eddts[trackID] + zdts[trackID] + guessTs := eddts[trackID] + zdts[trackID] + if diff(guessTs, ts, 10000) { + fmt.Println("diff ts >10", ts, guessTs) + ts = guessTs + } } if e := f.SeekIndex(-8, file.AtCurrent); e != nil { return e @@ -180,7 +192,11 @@ func resetTS(ctx context.Context, ptr *string) error { } else if chosenId == trackID { chosenT = float64(cu) / float64(zdts[trackID]) } else { - cu = int64(chosenT * float64(zdts[trackID])) + guessCu := int64(chosenT * float64(zdts[trackID])) + if diff(cu, guessCu, 10) { + fmt.Println("diff cu >10", cu, guessCu) + cu = guessCu + } } if _, e := f.Write(itob64(cu), false); e != nil { return e @@ -305,3 +321,7 @@ func itob32(v int32) []byte { b[3] = byte(v) return b } + +func diff(a, b int64, c uint64) bool { + return a-b > int64(c) || a-b < -int64(c) +} -- 2.39.2