From 00599e556e8da14fcd866cff0100ea01172838d7 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Mon, 15 Jun 2026 16:23:53 +0200 Subject: [PATCH] Properly handle zero-sample track fragments again (fixes #411) --- src/isobmff/isobmff-demuxer.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/isobmff/isobmff-demuxer.ts b/src/isobmff/isobmff-demuxer.ts index 450c6ce..72b142d 100644 --- a/src/isobmff/isobmff-demuxer.ts +++ b/src/isobmff/isobmff-demuxer.ts @@ -2069,8 +2069,14 @@ export class IsobmffDemuxer extends Demuxer { // referenced in the track fragment header. if (this.currentTrack) { const trackData = this.currentFragment.trackData.get(this.currentTrack.id); + cond: if (trackData) { - this.currentFragment.implicitBaseDataOffset = trackData.currentOffset; + if (trackData.samples.length === 0) { + // Don't associate the fragment with the track if it has no samples, this simplifies + // other code + this.currentFragment.trackData.delete(this.currentTrack.id); + break cond; + } trackData.presentationTimestamps = trackData.samples .map((x, i) => ({ presentationTimestamp: x.presentationTimestamp, sampleIndex: i })) @@ -2260,12 +2266,6 @@ export class IsobmffDemuxer extends Demuxer { this.currentFragment.trackData.set(track.id, trackData); } - if (sampleCount === 0) { - // Don't associate the fragment with the track if it has no samples, this simplifies other code - this.currentFragment.implicitBaseDataOffset = trackData.currentOffset; - break; - } - for (let i = 0; i < sampleCount; i++) { let sampleDuration: number; if (sampleDurationPresent) { @@ -2317,6 +2317,8 @@ export class IsobmffDemuxer extends Demuxer { trackData.currentOffset += sampleSize; trackData.currentTimestamp += sampleDuration; } + + this.currentFragment.implicitBaseDataOffset = trackData.currentOffset; }; break; case 'saiz': {