From 651e92335a5f90a4e914920ff74122c0a25e33e4 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Sun, 13 Sep 2026 22:14:36 +0200 Subject: [PATCH] Use the chunk id to detect the first chunk of a segment --- src/remux/passthrough-remuxer.ts | 7 +------ tests/unit/remux/passthrough-remuxer.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/remux/passthrough-remuxer.ts b/src/remux/passthrough-remuxer.ts index c2f7a72..55eb5da 100644 --- a/src/remux/passthrough-remuxer.ts +++ b/src/remux/passthrough-remuxer.ts @@ -49,7 +49,6 @@ class PassThroughRemuxer extends Logger implements Remuxer { private initPTS: TimestampOffset | null = null; private initTracks?: TrackSet; private lastEndTime: number | null = null; - private lastChunkKey: string | null = null; private isVideoContiguous: boolean = false; private videoOnlyRemux: boolean = false; private decryptdata: DecryptData | null = null; @@ -75,7 +74,6 @@ class PassThroughRemuxer extends Logger implements Remuxer { public resetTimeStamp(defaultInitPTS: TimestampOffset | null) { this.lastEndTime = null; - this.lastChunkKey = null; const initPTS = this.initPTS; if (initPTS && defaultInitPTS) { if ( @@ -91,7 +89,6 @@ class PassThroughRemuxer extends Logger implements Remuxer { public resetNextTimestamp() { this.isVideoContiguous = false; this.lastEndTime = null; - this.lastChunkKey = null; } public resetInitSegment( @@ -446,9 +443,7 @@ class PassThroughRemuxer extends Logger implements Remuxer { // Every chunk of a progressive segment is remuxed with the segment's // timeOffset, so only the first chunk's decode time lines up with it - const chunkKey = `${chunkMeta.level}_${chunkMeta.sn}_${chunkMeta.part}`; - const segmentStart = chunkKey !== this.lastChunkKey; - this.lastChunkKey = chunkKey; + const segmentStart = chunkMeta.id === 1; if ( ((accurateTimeOffset && segmentStart) || !initPTS) && diff --git a/tests/unit/remux/passthrough-remuxer.ts b/tests/unit/remux/passthrough-remuxer.ts index 5f2a45b..f6fdfee 100644 --- a/tests/unit/remux/passthrough-remuxer.ts +++ b/tests/unit/remux/passthrough-remuxer.ts @@ -108,6 +108,7 @@ describe('passthrough-remuxer', function () { fragmentData: Uint8Array, timeOffset: number, flush: boolean, + chunkId: number, ) { return remuxer.remux( audioTrack(), @@ -118,7 +119,16 @@ describe('passthrough-remuxer', function () { true, flush, PlaylistLevelType.MAIN, - new ChunkMetadata(0, 0, 0, fragmentData.byteLength, -1, true, 4, false), + new ChunkMetadata( + 0, + 0, + chunkId, + fragmentData.byteLength, + -1, + true, + 4, + false, + ), ); } @@ -441,8 +451,8 @@ describe('passthrough-remuxer', function () { const firstChunk = mp4FragmentAt(0, [sample(180000, 4, 0)]); const secondChunk = mp4FragmentAt(180000, [sample(180000, 4, 0)]); - const first = remuxProgressiveChunk(firstChunk, 0, false); - const second = remuxProgressiveChunk(secondChunk, 0, true); + const first = remuxProgressiveChunk(firstChunk, 0, false, 1); + const second = remuxProgressiveChunk(secondChunk, 0, true, 2); expect(first.video, 'first chunk video track').to.exist; expect(first.video!.startDTS, 'first chunk startDTS').to.equal(0);