From 5fe982544b9db357c94b851f898f64f43eeb5e1b Mon Sep 17 00:00:00 2001 From: lm Date: Thu, 31 Oct 2024 15:17:05 +0100 Subject: [PATCH] fix: Add explicit DTS/CTS in video export --- demo/frontend/src/common/codecs/VideoEncoder.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/demo/frontend/src/common/codecs/VideoEncoder.ts b/demo/frontend/src/common/codecs/VideoEncoder.ts index c21af2258..8a889a6d2 100644 --- a/demo/frontend/src/common/codecs/VideoEncoder.ts +++ b/demo/frontend/src/common/codecs/VideoEncoder.ts @@ -32,6 +32,7 @@ export function encode( let encodedFrameIndex = 0; let nextKeyFrameTimestamp = 0; let trackID: number | null = null; + let totalDuration = 0; const durations: number[] = []; const outputFile = createFile(); @@ -52,9 +53,14 @@ export function encode( } const shiftedDuration = durations.shift(); if (shiftedDuration != null) { + const scaledDuration = getScaledDuration(shiftedDuration); + totalDuration += scaledDuration; + outputFile.addSample(trackID, uint8, { - duration: getScaledDuration(shiftedDuration), - is_sync: chunk.type === 'key', + duration: scaledDuration, + is_sync: chunk.type === 'key', + dts: totalDuration, // Add explicit DTS + cts: totalDuration, // Add explicit CTS }); encodedFrameIndex++; progressCallback?.(encodedFrameIndex / numFrames);