Use the chunk id to detect the first chunk of a segment

This commit is contained in:
dualfroz committed 2026-09-13 22:14:36 +02:00
1 parent 155a6b6c90
commit 651e92335a
2 files changed
+14 -9

No files matched your search

+1 -6
View File
@@ -49,7 +49,6 @@ class PassThroughRemuxer extends Logger implements Remuxer {
private initPTS: TimestampOffset | null = null; private initPTS: TimestampOffset | null = null;
private initTracks?: TrackSet; private initTracks?: TrackSet;
private lastEndTime: number | null = null; private lastEndTime: number | null = null;
private lastChunkKey: string | null = null;
private isVideoContiguous: boolean = false; private isVideoContiguous: boolean = false;
private videoOnlyRemux: boolean = false; private videoOnlyRemux: boolean = false;
private decryptdata: DecryptData | null = null; private decryptdata: DecryptData | null = null;
@@ -75,7 +74,6 @@ class PassThroughRemuxer extends Logger implements Remuxer {
public resetTimeStamp(defaultInitPTS: TimestampOffset | null) { public resetTimeStamp(defaultInitPTS: TimestampOffset | null) {
this.lastEndTime = null; this.lastEndTime = null;
this.lastChunkKey = null;
const initPTS = this.initPTS; const initPTS = this.initPTS;
if (initPTS && defaultInitPTS) { if (initPTS && defaultInitPTS) {
if ( if (
@@ -91,7 +89,6 @@ class PassThroughRemuxer extends Logger implements Remuxer {
public resetNextTimestamp() { public resetNextTimestamp() {
this.isVideoContiguous = false; this.isVideoContiguous = false;
this.lastEndTime = null; this.lastEndTime = null;
this.lastChunkKey = null;
} }
public resetInitSegment( public resetInitSegment(
@@ -446,9 +443,7 @@ class PassThroughRemuxer extends Logger implements Remuxer {
// Every chunk of a progressive segment is remuxed with the segment's // 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 // timeOffset, so only the first chunk's decode time lines up with it
const chunkKey = `${chunkMeta.level}_${chunkMeta.sn}_${chunkMeta.part}`; const segmentStart = chunkMeta.id === 1;
const segmentStart = chunkKey !== this.lastChunkKey;
this.lastChunkKey = chunkKey;
if ( if (
((accurateTimeOffset && segmentStart) || !initPTS) && ((accurateTimeOffset && segmentStart) || !initPTS) &&
+13 -3
View File
@@ -108,6 +108,7 @@ describe('passthrough-remuxer', function () {
fragmentData: Uint8Array<ArrayBuffer>, fragmentData: Uint8Array<ArrayBuffer>,
timeOffset: number, timeOffset: number,
flush: boolean, flush: boolean,
chunkId: number,
) { ) {
return remuxer.remux( return remuxer.remux(
audioTrack(), audioTrack(),
@@ -118,7 +119,16 @@ describe('passthrough-remuxer', function () {
true, true,
flush, flush,
PlaylistLevelType.MAIN, 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 firstChunk = mp4FragmentAt(0, [sample(180000, 4, 0)]);
const secondChunk = mp4FragmentAt(180000, [sample(180000, 4, 0)]); const secondChunk = mp4FragmentAt(180000, [sample(180000, 4, 0)]);
const first = remuxProgressiveChunk(firstChunk, 0, false); const first = remuxProgressiveChunk(firstChunk, 0, false, 1);
const second = remuxProgressiveChunk(secondChunk, 0, true); const second = remuxProgressiveChunk(secondChunk, 0, true, 2);
expect(first.video, 'first chunk video track').to.exist; expect(first.video, 'first chunk video track').to.exist;
expect(first.video!.startDTS, 'first chunk startDTS').to.equal(0); expect(first.video!.startDTS, 'first chunk startDTS').to.equal(0);