From: qydysky Date: Thu, 5 Oct 2023 08:06:52 +0000 (+0800) Subject: Fix 重置时间戳后的文件导致ffmpeg error #88 X-Git-Tag: v0.11.2~5 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=78a516a68f98f31830ba502f77dc151c6f1ad807;p=bili_danmu%2F.git Fix 重置时间戳后的文件导致ffmpeg error #88 --- 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) +}