]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix 重置时间戳后的文件导致ffmpeg error #88
authorqydysky <qydysky@foxmail.com>
Thu, 5 Oct 2023 08:06:52 +0000 (16:06 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 5 Oct 2023 08:06:52 +0000 (16:06 +0800)
Reply/F/reSetMp4TimeStamp/reSetMp4TimeStamp.go

index 3f44123112b63805de4750a94197c5c71c5d3f68..bf5b664870534d9b4faab5602b88c71412b7c039 100644 (file)
@@ -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)
+}