From 3a12676854acb7a2a449ccc434009090ab7b14b4 Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Mon, 26 May 2025 11:40:54 +0200 Subject: [PATCH 1/7] feat: fix onReady, onMoovStart and onSidx callbacks typing --- src/isofile.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/isofile.ts b/src/isofile.ts index 46ed768d..73ba2702 100644 --- a/src/isofile.ts +++ b/src/isofile.ts @@ -157,11 +157,11 @@ export class ISOFile { /** Boolean used to fire moov start event only once */ moovStartFound = false; /** Callback called when the moov parsing starts */ - onMoovStart = null; + onMoovStart: (() => void) | null = null; /** Boolean keeping track of the call to onMoovStart, to avoid double calls */ moovStartSent = false; /** Callback called when the moov is entirely parsed */ - onReady = null; + onReady: ((info: Movie) => void) | null = null; /** Boolean keeping track of the call to onReady, to avoid double calls */ readySent = false; /** Callback to call when segments are ready */ @@ -195,7 +195,7 @@ export class ISOFile { /** Boolean indicating if the initial list of items has been produced */ itemListBuilt = false; /** Callback called when the sidx box is entirely parsed */ - onSidx = null; + onSidx: ((sidx: sidxBox) => void) | null = null; /** Boolean keeping track of the call to onSidx, to avoid double calls */ sidxSent = false; From 3cb14b60c468e1dd9f8fa71448c8a1d2f19e8a9e Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Mon, 26 May 2025 12:21:23 +0200 Subject: [PATCH 2/7] fix: mark fileStart mandatory on MP4BoxBuffer --- src/mp4boxbuffer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mp4boxbuffer.ts b/src/mp4boxbuffer.ts index d894fe07..7e0825c7 100644 --- a/src/mp4boxbuffer.ts +++ b/src/mp4boxbuffer.ts @@ -1,4 +1,4 @@ export class MP4BoxBuffer extends ArrayBuffer { - fileStart?: number; + fileStart: number; usedBytes?: number; } From bdf5e29ca776e251dc00d656ca29cae5eac05b77 Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Mon, 26 May 2025 14:55:11 +0200 Subject: [PATCH 3/7] fix: make most write function bound by default --- src/box.ts | 8 ++++---- src/boxes/avcC.ts | 5 +++-- src/boxes/co64.ts | 4 ++-- src/boxes/cslg.ts | 4 ++-- src/boxes/ctts.ts | 4 ++-- src/boxes/dref.ts | 4 ++-- src/boxes/elng.ts | 4 ++-- src/boxes/elst.ts | 4 ++-- src/boxes/emsg.ts | 4 ++-- src/boxes/ftyp.ts | 4 ++-- src/boxes/hdlr.ts | 4 ++-- src/boxes/kind.ts | 4 ++-- src/boxes/mdhd.ts | 4 ++-- src/boxes/mehd.ts | 4 ++-- src/boxes/mfhd.ts | 4 ++-- src/boxes/mvhd.ts | 4 ++-- src/boxes/sampleentries/base.ts | 12 ++++++------ src/boxes/sampleentries/stpp.ts | 4 ++-- src/boxes/sbgp.ts | 4 ++-- src/boxes/sgpd.ts | 4 ++-- src/boxes/sidx.ts | 4 ++-- src/boxes/smhd.ts | 4 ++-- src/boxes/stco.ts | 4 ++-- src/boxes/stsc.ts | 4 ++-- src/boxes/stsd.ts | 4 ++-- src/boxes/stsh.ts | 4 ++-- src/boxes/stss.ts | 4 ++-- src/boxes/stsz.ts | 4 ++-- src/boxes/stts.ts | 4 ++-- src/boxes/styp.ts | 4 ++-- src/boxes/tfdt.ts | 4 ++-- src/boxes/trex.ts | 4 ++-- src/boxes/trun.ts | 4 ++-- src/boxes/url.ts | 4 ++-- src/boxes/urn.ts | 4 ++-- src/boxes/vmhd.ts | 4 ++-- 36 files changed, 79 insertions(+), 78 deletions(-) diff --git a/src/box.ts b/src/box.ts index 21c15685..88dac746 100644 --- a/src/box.ts +++ b/src/box.ts @@ -212,7 +212,7 @@ export class ContainerBox extends Box { subBoxNames?: ReadonlyArray; /** @bundle box-write.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.size = 0; this.writeHeader(stream); for (let i = 0; i < this.boxes.length; i++) { @@ -224,7 +224,7 @@ export class ContainerBox extends Box { /* adjusting the size, now that all sub-boxes are known */ Log.debug('BoxWriter', 'Adjusting box ' + this.type + ' with new size ' + this.size); stream.adjustUint32(this.sizePosition, this.size); - } + }; /** @bundle box-print.js */ print(output: Output) { @@ -278,9 +278,9 @@ export class SampleGroupEntry { constructor(public grouping_type: string) {} /** @bundle writing/samplegroups/samplegroup.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { stream.writeUint8Array(this.data); - } + }; /** @bundle parsing/samplegroups/samplegroup.js */ parse(stream: MultiBufferStream) { diff --git a/src/boxes/avcC.ts b/src/boxes/avcC.ts index b8190b53..8f9e0c6b 100644 --- a/src/boxes/avcC.ts +++ b/src/boxes/avcC.ts @@ -53,7 +53,8 @@ export class avcCBox extends Box { } /** @bundle writing/avcC.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { + console.log(this); this.size = 7; for (let i = 0; i < this.SPS.length; i++) { this.size += 2 + this.SPS[i].length; @@ -83,5 +84,5 @@ export class avcCBox extends Box { if (this.ext) { stream.writeUint8Array(this.ext); } - } + }; } diff --git a/src/boxes/co64.ts b/src/boxes/co64.ts index 112e3843..1e90aeda 100644 --- a/src/boxes/co64.ts +++ b/src/boxes/co64.ts @@ -19,7 +19,7 @@ export class co64Box extends FullBox { } /** @bundle writing/co64.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 8 * this.chunk_offsets.length; @@ -28,5 +28,5 @@ export class co64Box extends FullBox { for (let i = 0; i < this.chunk_offsets.length; i++) { stream.writeUint64(this.chunk_offsets[i]); } - } + }; } diff --git a/src/boxes/cslg.ts b/src/boxes/cslg.ts index 41f4d0cc..d543608f 100644 --- a/src/boxes/cslg.ts +++ b/src/boxes/cslg.ts @@ -31,7 +31,7 @@ export class cslgBox extends FullBox { } /** @bundle writing/cslg.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; if ( this.compositionToDTSShift > INT32_MAX || @@ -60,5 +60,5 @@ export class cslgBox extends FullBox { stream.writeInt64(this.compositionStartTime); stream.writeInt64(this.compositionEndTime); } - } + }; } diff --git a/src/boxes/ctts.ts b/src/boxes/ctts.ts index c1ade417..3b083b30 100644 --- a/src/boxes/ctts.ts +++ b/src/boxes/ctts.ts @@ -36,7 +36,7 @@ export class cttsBox extends FullBox { } /** @bundle writing/ctts.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 8 * this.sample_counts.length; @@ -50,7 +50,7 @@ export class cttsBox extends FullBox { stream.writeUint32(this.sample_offsets[i]); /* unsigned */ } } - } + }; /** @bundle box-unpack.js */ unpack(samples: Array) { diff --git a/src/boxes/dref.ts b/src/boxes/dref.ts index c1191369..2fcee7ec 100644 --- a/src/boxes/dref.ts +++ b/src/boxes/dref.ts @@ -25,7 +25,7 @@ export class drefBox extends FullBox { } /** @bundle writing/dref.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4; // @@ -38,5 +38,5 @@ export class drefBox extends FullBox { /* adjusting the size, now that all sub-boxes are known */ Log.debug('BoxWriter', 'Adjusting box ' + this.type + ' with new size ' + this.size); stream.adjustUint32(this.sizePosition, this.size); - } + }; } diff --git a/src/boxes/elng.ts b/src/boxes/elng.ts index 6eea2a18..0556ef3f 100644 --- a/src/boxes/elng.ts +++ b/src/boxes/elng.ts @@ -13,11 +13,11 @@ export class elngBox extends FullBox { } /** @bundle writing/elng.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = this.extended_language.length; this.writeHeader(stream); stream.writeString(this.extended_language); - } + }; } diff --git a/src/boxes/elst.ts b/src/boxes/elst.ts index 7cc49e79..fabbeb76 100644 --- a/src/boxes/elst.ts +++ b/src/boxes/elst.ts @@ -24,7 +24,7 @@ export class elstBox extends FullBox { } /** @bundle writing/elst.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 12 * this.entries.length; @@ -37,5 +37,5 @@ export class elstBox extends FullBox { stream.writeInt16(entry.media_rate_integer); stream.writeInt16(entry.media_rate_fraction); } - } + }; } diff --git a/src/boxes/emsg.ts b/src/boxes/emsg.ts index 71448fdc..8e910a78 100644 --- a/src/boxes/emsg.ts +++ b/src/boxes/emsg.ts @@ -42,7 +42,7 @@ export class emsgBox extends FullBox { } /** @bundle writing/emsg.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = @@ -55,5 +55,5 @@ export class emsgBox extends FullBox { stream.writeUint32(this.event_duration); stream.writeUint32(this.id); stream.writeUint8Array(this.message_data); - } + }; } diff --git a/src/boxes/ftyp.ts b/src/boxes/ftyp.ts index 107ddc80..06b2f610 100644 --- a/src/boxes/ftyp.ts +++ b/src/boxes/ftyp.ts @@ -24,7 +24,7 @@ export class ftypBox extends Box { } /** @bundle writing/ftyp.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.size = 8 + 4 * this.compatible_brands.length; this.writeHeader(stream); stream.writeString(this.major_brand, null, 4); @@ -32,5 +32,5 @@ export class ftypBox extends Box { for (let i = 0; i < this.compatible_brands.length; i++) { stream.writeString(this.compatible_brands[i], null, 4); } - } + }; } diff --git a/src/boxes/hdlr.ts b/src/boxes/hdlr.ts index 64eb4076..e00f5cce 100644 --- a/src/boxes/hdlr.ts +++ b/src/boxes/hdlr.ts @@ -23,7 +23,7 @@ export class hdlrBox extends FullBox { } /** @bundle writing/hldr.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.size = 5 * 4 + this.name.length + 1; this.version = 0; this.flags = 0; @@ -34,5 +34,5 @@ export class hdlrBox extends FullBox { stream.writeUint32(0); stream.writeUint32(0); stream.writeCString(this.name); - } + }; } diff --git a/src/boxes/kind.ts b/src/boxes/kind.ts index 76c055b5..baa3d671 100644 --- a/src/boxes/kind.ts +++ b/src/boxes/kind.ts @@ -15,12 +15,12 @@ export class kindBox extends FullBox { } /** @bundle writing/kind.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = this.schemeURI.length + 1 + (this.value.length + 1); this.writeHeader(stream); stream.writeCString(this.schemeURI); stream.writeCString(this.value); - } + }; } diff --git a/src/boxes/mdhd.ts b/src/boxes/mdhd.ts index e83ac8db..3668055b 100644 --- a/src/boxes/mdhd.ts +++ b/src/boxes/mdhd.ts @@ -28,7 +28,7 @@ export class mdhdBox extends FullBox { } /** @bundle writing/mdhd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.size = 4 * 4 + 2 * 2; this.flags = 0; this.version = 0; @@ -39,5 +39,5 @@ export class mdhdBox extends FullBox { stream.writeUint32(this.duration); stream.writeUint16(this.language); stream.writeUint16(0); - } + }; } diff --git a/src/boxes/mehd.ts b/src/boxes/mehd.ts index fadb8540..75543d14 100644 --- a/src/boxes/mehd.ts +++ b/src/boxes/mehd.ts @@ -22,11 +22,11 @@ export class mehdBox extends FullBox { } /** @bundle writing/mehd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4; this.writeHeader(stream); stream.writeUint32(this.fragment_duration); - } + }; } diff --git a/src/boxes/mfhd.ts b/src/boxes/mfhd.ts index 9f246b2c..7f8dabe4 100644 --- a/src/boxes/mfhd.ts +++ b/src/boxes/mfhd.ts @@ -13,11 +13,11 @@ export class mfhdBox extends FullBox { } /** @bundle writing/mfhd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4; this.writeHeader(stream); stream.writeUint32(this.sequence_number); - } + }; } diff --git a/src/boxes/mvhd.ts b/src/boxes/mvhd.ts index 87f45c46..1713f3c1 100644 --- a/src/boxes/mvhd.ts +++ b/src/boxes/mvhd.ts @@ -38,7 +38,7 @@ export class mvhdBox extends FullBox { } /** @bundle writing/mvhd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 23 * 4 + 2 * 2; @@ -60,7 +60,7 @@ export class mvhdBox extends FullBox { stream.writeUint32(0); stream.writeUint32(0); stream.writeUint32(this.next_track_id); - } + }; /** @bundle box-print.js */ print(output: Output) { diff --git a/src/boxes/sampleentries/base.ts b/src/boxes/sampleentries/base.ts index aa19a935..c525f5a1 100644 --- a/src/boxes/sampleentries/base.ts +++ b/src/boxes/sampleentries/base.ts @@ -127,13 +127,13 @@ export class SampleEntry extends ContainerBox { } /** @bundle writing/sampleentry.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.writeHeader(stream); stream.writeUint8Array(this.data); this.size += this.data.length; Log.debug('BoxWriter', 'Adjusting box ' + this.type + ' with new size ' + this.size); stream.adjustUint32(this.sizePosition, this.size); - } + }; } // Base SampleEntry types with default parsing @@ -205,7 +205,7 @@ export class VisualSampleEntry extends SampleEntry { } /** @bundle writing/sampleentries/sampleentry.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.writeHeader(stream); this.size += 2 * 7 + 6 * 4 + 32; stream.writeUint16(0); @@ -224,7 +224,7 @@ export class VisualSampleEntry extends SampleEntry { stream.writeUint16(this.depth); stream.writeInt16(-1); this.writeFooter(stream); - } + }; } export class AudioSampleEntry extends SampleEntry { @@ -264,7 +264,7 @@ export class AudioSampleEntry extends SampleEntry { } /** @bundle writing/sampleentry.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.writeHeader(stream); this.size += 2 * 4 + 3 * 4; stream.writeUint32(0); @@ -275,5 +275,5 @@ export class AudioSampleEntry extends SampleEntry { stream.writeUint16(0); stream.writeUint32(this.samplerate << 16); this.writeFooter(stream); - } + }; } diff --git a/src/boxes/sampleentries/stpp.ts b/src/boxes/sampleentries/stpp.ts index 998e9dfb..f336b921 100644 --- a/src/boxes/sampleentries/stpp.ts +++ b/src/boxes/sampleentries/stpp.ts @@ -17,7 +17,7 @@ export class stppSampleEntry extends SubtitleSampleEntry { } /** @bundle writing/sampleentry.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.writeHeader(stream); this.size += this.namespace.length + @@ -30,5 +30,5 @@ export class stppSampleEntry extends SubtitleSampleEntry { stream.writeCString(this.schema_location); stream.writeCString(this.auxiliary_mime_types); this.writeFooter(stream); - } + }; } diff --git a/src/boxes/sbgp.ts b/src/boxes/sbgp.ts index 7482b0a8..96dfb2fe 100644 --- a/src/boxes/sbgp.ts +++ b/src/boxes/sbgp.ts @@ -33,7 +33,7 @@ export class sbgpBox extends FullBox { } /** @bundle writing/sbgp.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 1; this.flags = 0; this.size = 12 + 8 * this.entries.length; @@ -46,5 +46,5 @@ export class sbgpBox extends FullBox { stream.writeInt32(entry.sample_count); stream.writeInt32(entry.group_description_index); } - } + }; } diff --git a/src/boxes/sgpd.ts b/src/boxes/sgpd.ts index 91c111ba..34c57806 100644 --- a/src/boxes/sgpd.ts +++ b/src/boxes/sgpd.ts @@ -82,7 +82,7 @@ export class sgpdBox extends FullBox { } /** @bundle writing/sgpd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { // leave version as read // this.version; this.flags = 0; @@ -114,5 +114,5 @@ export class sgpdBox extends FullBox { } entry.write(stream); } - } + }; } diff --git a/src/boxes/sidx.ts b/src/boxes/sidx.ts index 08f7c151..70ed1f4a 100644 --- a/src/boxes/sidx.ts +++ b/src/boxes/sidx.ts @@ -56,7 +56,7 @@ export class sidxBox extends FullBox { } /** @bundle writing/sidx.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 * 4 + 2 + 2 + 12 * this.references.length; @@ -73,5 +73,5 @@ export class sidxBox extends FullBox { stream.writeUint32(ref.subsegment_duration); stream.writeUint32((ref.starts_with_SAP << 31) | (ref.SAP_type << 28) | ref.SAP_delta_time); } - } + }; } diff --git a/src/boxes/smhd.ts b/src/boxes/smhd.ts index 31767dae..dad09e58 100644 --- a/src/boxes/smhd.ts +++ b/src/boxes/smhd.ts @@ -14,12 +14,12 @@ export class smhdBox extends FullBox { } /** @bundle writing/smhd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 1; this.size = 4; this.writeHeader(stream); stream.writeUint16(this.balance); stream.writeUint16(0); - } + }; } diff --git a/src/boxes/stco.ts b/src/boxes/stco.ts index f048327a..7b11d294 100644 --- a/src/boxes/stco.ts +++ b/src/boxes/stco.ts @@ -20,14 +20,14 @@ export class stcoBox extends FullBox { } /** @bundle writings/stco.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 4 * this.chunk_offsets.length; this.writeHeader(stream); stream.writeUint32(this.chunk_offsets.length); stream.writeUint32Array(this.chunk_offsets); - } + }; /** @bundle box-unpack.js */ unpack(samples: Array) { diff --git a/src/boxes/stsc.ts b/src/boxes/stsc.ts index c5929290..1bde5b16 100644 --- a/src/boxes/stsc.ts +++ b/src/boxes/stsc.ts @@ -25,7 +25,7 @@ export class stscBox extends FullBox { } } - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 12 * this.first_chunk.length; @@ -36,7 +36,7 @@ export class stscBox extends FullBox { stream.writeUint32(this.samples_per_chunk[i]); stream.writeUint32(this.sample_description_index[i]); } - } + }; unpack(samples: Array) { let l = 0; diff --git a/src/boxes/stsd.ts b/src/boxes/stsd.ts index 33278155..ac4a1712 100644 --- a/src/boxes/stsd.ts +++ b/src/boxes/stsd.ts @@ -52,7 +52,7 @@ export class stsdBox extends FullBox { } /** @bundle writing/stsd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 0; @@ -66,5 +66,5 @@ export class stsdBox extends FullBox { /* adjusting the size, now that all sub-boxes are known */ Log.debug('BoxWriter', 'Adjusting box ' + this.type + ' with new size ' + this.size); stream.adjustUint32(this.sizePosition, this.size); - } + }; } diff --git a/src/boxes/stsh.ts b/src/boxes/stsh.ts index a7d4afe6..3611a6f7 100644 --- a/src/boxes/stsh.ts +++ b/src/boxes/stsh.ts @@ -21,7 +21,7 @@ export class stshBox extends FullBox { } } - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 8 * this.shadowed_sample_numbers.length; @@ -31,5 +31,5 @@ export class stshBox extends FullBox { stream.writeUint32(this.shadowed_sample_numbers[i]); stream.writeUint32(this.sync_sample_numbers[i]); } - } + }; } diff --git a/src/boxes/stss.ts b/src/boxes/stss.ts index 4957f7d0..639196a9 100644 --- a/src/boxes/stss.ts +++ b/src/boxes/stss.ts @@ -19,12 +19,12 @@ export class stssBox extends FullBox { } /** @bundle writing/stss.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 4 * this.sample_numbers.length; this.writeHeader(stream); stream.writeUint32(this.sample_numbers.length); stream.writeUint32Array(this.sample_numbers); - } + }; } diff --git a/src/boxes/stsz.ts b/src/boxes/stsz.ts index 9a57ca70..b4009ffd 100644 --- a/src/boxes/stsz.ts +++ b/src/boxes/stsz.ts @@ -26,7 +26,7 @@ export class stszBox extends FullBox { } /** @bundle writing/stsz.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { let constant = true; this.version = 0; this.flags = 0; @@ -57,7 +57,7 @@ export class stszBox extends FullBox { if (!constant) { stream.writeUint32Array(this.sample_sizes); } - } + }; /** @bundle box-unpack.js */ unpack(samples) { diff --git a/src/boxes/stts.ts b/src/boxes/stts.ts index ba6e4d28..119407d2 100644 --- a/src/boxes/stts.ts +++ b/src/boxes/stts.ts @@ -32,7 +32,7 @@ export class sttsBox extends FullBox { } /** @bundle writing/stts.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 + 8 * this.sample_counts.length; @@ -42,7 +42,7 @@ export class sttsBox extends FullBox { stream.writeUint32(this.sample_counts[i]); stream.writeUint32(this.sample_deltas[i]); } - } + }; /** @bundle box-unpack.js */ unpack(samples: Array) { diff --git a/src/boxes/styp.ts b/src/boxes/styp.ts index 6a7f2b82..837b9459 100644 --- a/src/boxes/styp.ts +++ b/src/boxes/styp.ts @@ -23,7 +23,7 @@ export class stypBox extends Box { } } - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.size = 8 + 4 * this.compatible_brands.length; this.writeHeader(stream); stream.writeString(this.major_brand, null, 4); @@ -31,5 +31,5 @@ export class stypBox extends Box { for (let i = 0; i < this.compatible_brands.length; i++) { stream.writeString(this.compatible_brands[i], null, 4); } - } + }; } diff --git a/src/boxes/tfdt.ts b/src/boxes/tfdt.ts index 7a4faddc..d7c94bfe 100644 --- a/src/boxes/tfdt.ts +++ b/src/boxes/tfdt.ts @@ -17,7 +17,7 @@ export class tfdtBox extends FullBox { } /** @bundle writing/tdft.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { const UINT32_MAX = Math.pow(2, 32) - 1; // use version 1 if baseMediaDecodeTime does not fit 32 bits this.version = this.baseMediaDecodeTime > UINT32_MAX ? 1 : 0; @@ -32,5 +32,5 @@ export class tfdtBox extends FullBox { } else { stream.writeUint32(this.baseMediaDecodeTime); } - } + }; } diff --git a/src/boxes/trex.ts b/src/boxes/trex.ts index 48230cf8..1aa91288 100644 --- a/src/boxes/trex.ts +++ b/src/boxes/trex.ts @@ -20,7 +20,7 @@ export class trexBox extends FullBox { this.default_sample_flags = stream.readUint32(); } - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = 4 * 5; @@ -30,5 +30,5 @@ export class trexBox extends FullBox { stream.writeUint32(this.default_sample_duration); stream.writeUint32(this.default_sample_size); stream.writeUint32(this.default_sample_flags); - } + }; } diff --git a/src/boxes/trun.ts b/src/boxes/trun.ts index 00e4b038..5955fe66 100644 --- a/src/boxes/trun.ts +++ b/src/boxes/trun.ts @@ -66,7 +66,7 @@ export class trunBox extends FullBox { } /** @bundle writing/trun.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.size = 4; if (this.flags & TRUN_FLAGS_DATA_OFFSET) { @@ -114,5 +114,5 @@ export class trunBox extends FullBox { } } } - } + }; } diff --git a/src/boxes/url.ts b/src/boxes/url.ts index c2230c23..02c26b81 100644 --- a/src/boxes/url.ts +++ b/src/boxes/url.ts @@ -15,7 +15,7 @@ export class urlBox extends FullBox { } /** @bundle writing/url.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; if (this.location) { this.flags = 0; @@ -28,5 +28,5 @@ export class urlBox extends FullBox { if (this.location) { stream.writeCString(this.location); } - } + }; } diff --git a/src/boxes/urn.ts b/src/boxes/urn.ts index d13a61eb..042df8c0 100644 --- a/src/boxes/urn.ts +++ b/src/boxes/urn.ts @@ -17,7 +17,7 @@ export class urnBox extends FullBox { } /** @bundle writing/urn.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 0; this.size = this.name.length + 1 + (this.location ? this.location.length + 1 : 0); @@ -26,5 +26,5 @@ export class urnBox extends FullBox { if (this.location) { stream.writeCString(this.location); } - } + }; } diff --git a/src/boxes/vmhd.ts b/src/boxes/vmhd.ts index f15d43d8..6ba1a3aa 100644 --- a/src/boxes/vmhd.ts +++ b/src/boxes/vmhd.ts @@ -15,12 +15,12 @@ export class vmhdBox extends FullBox { } /** @bundle writing/vmhd.js */ - write(stream: MultiBufferStream) { + write = (stream: MultiBufferStream) => { this.version = 0; this.flags = 1; this.size = 8; this.writeHeader(stream); stream.writeUint16(this.graphicsmode); stream.writeUint16Array(this.opcolor); - } + }; } From 767ce19c0b233142b399d18a82599a697c4a5047 Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Mon, 26 May 2025 14:56:48 +0200 Subject: [PATCH 4/7] fix: mark optional boxes --- src/boxes/defaults.ts | 4 ++-- src/isofile.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boxes/defaults.ts b/src/boxes/defaults.ts index 65238cbe..cb32fecb 100644 --- a/src/boxes/defaults.ts +++ b/src/boxes/defaults.ts @@ -130,7 +130,7 @@ export class moovBox extends ContainerBox { timescale: number; mvhd: mvhdBox; mvhds: Array; - mvex: mvexBox; + mvex: mvexBox | undefined; mvexs: Array; iods: iodsBox; iodss: Array; @@ -243,7 +243,7 @@ export class mvexBox extends ContainerBox { type = 'mvex' as const; box_name = 'MovieExtendsBox'; trex: trexBox; - mehd: mehdBox; + mehd: mehdBox | undefined; mehds: Array; trexs: Array = []; diff --git a/src/isofile.ts b/src/isofile.ts index 73ba2702..1fba6fea 100644 --- a/src/isofile.ts +++ b/src/isofile.ts @@ -503,7 +503,7 @@ export class ISOFile { } const _1904 = new Date('1904-01-01T00:00:00Z').getTime(); - const isFragmented = this.moov.mvex !== null; + const isFragmented = this.moov.mvex !== undefined; const movie: Movie = { hasMoov: true, From 73a09901c041e1672f763de2a50c2bda31d1fc7a Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Mon, 26 May 2025 14:57:44 +0200 Subject: [PATCH 5/7] fix: fix few MP4Buffer typings --- src/DataStream.ts | 12 +++++------- src/boxes/esds.ts | 10 +++++++++- src/buffer.ts | 21 +++++++++++++-------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/DataStream.ts b/src/DataStream.ts index 19ffc4ed..761dbf7e 100644 --- a/src/DataStream.ts +++ b/src/DataStream.ts @@ -36,7 +36,7 @@ export class DataStream { _buffer?: MP4BoxBuffer; _byteOffset?: number; - _dataView?: DataView; + _dataView?: DataView; endianness: boolean; position: number; @@ -50,14 +50,12 @@ export class DataStream { * @param endianness DataStream.BIG_ENDIAN or DataStream.LITTLE_ENDIAN (the default). */ constructor( - arrayBuffer?: ArrayBuffer | DataView | number, + arrayBuffer?: DataView | number, byteOffset?: number, endianness?: boolean | null, ) { this._byteOffset = byteOffset || 0; - if (arrayBuffer instanceof ArrayBuffer) { - this.buffer = arrayBuffer; - } else if (arrayBuffer instanceof DataView) { + if (arrayBuffer instanceof DataView) { this.dataView = arrayBuffer; if (byteOffset) this._byteOffset += byteOffset; } else { @@ -181,7 +179,7 @@ export class DataStream { get dataView() { return this._dataView; } - set dataView(value: DataView) { + set dataView(value: DataView) { this._byteOffset = value.byteOffset; this._buffer = value.buffer; this._dataView = new DataView(this._buffer, this._byteOffset); @@ -346,7 +344,7 @@ export class DataStream { * @param e Endianness of the data to read. * @return The read Uint8Array. */ - readUint8Array(length: number | null) { + readUint8Array(length: number | null): Uint8Array { length = length === null ? this.byteLength - this.position : length; const arr = new Uint8Array(length); DataStream.memcpy( diff --git a/src/boxes/esds.ts b/src/boxes/esds.ts index be60e7f1..c2f7404b 100644 --- a/src/boxes/esds.ts +++ b/src/boxes/esds.ts @@ -2,6 +2,7 @@ import { FullBox } from '#/box'; import type { MultiBufferStream } from '#/buffer'; import { DataStream } from '#/DataStream'; import type { ES_Descriptor } from '#/descriptor'; +import type { MP4BoxBuffer } from '#/mp4boxbuffer'; import { DescriptorRegistry } from '#/registry'; export class esdsBox extends FullBox { @@ -16,8 +17,15 @@ export class esdsBox extends FullBox { // NOTE: This used to be `typeof MPEG4DescriptorParser !== 'undefined'` if ('MPEG4DescriptorParser' in DescriptorRegistry) { const esd_parser = new DescriptorRegistry.MPEG4DescriptorParser(); + const arrayBuffer = new ArrayBuffer(esd_data.length); + const uint8Array = new Uint8Array(arrayBuffer); + uint8Array.set(esd_data); + + const mp4Buffer: MP4BoxBuffer = Object.assign(arrayBuffer, { fileStart: 0 }); + const mp4Dataview = new DataView(mp4Buffer, 0, arrayBuffer.byteLength); + this.esd = esd_parser.parseOneDescriptor( - new DataStream(esd_data.buffer, 0, DataStream.BIG_ENDIAN), + new DataStream(mp4Dataview, 0, DataStream.BIG_ENDIAN), ) as ES_Descriptor; } } diff --git a/src/buffer.ts b/src/buffer.ts index dceda729..acd992e5 100644 --- a/src/buffer.ts +++ b/src/buffer.ts @@ -8,7 +8,7 @@ import type { MP4BoxBuffer } from './mp4boxbuffer'; * @param buffer2 * @return the concatenation of buffer1 and buffer2 in that order */ -function concatBuffers(buffer1: ArrayBuffer, buffer2: ArrayBuffer) { +function concatBuffers(buffer1: MP4BoxBuffer, buffer2: MP4BoxBuffer): MP4BoxBuffer { Log.debug( 'ArrayBuffer', 'Trying to create a new buffer of size: ' + (buffer1.byteLength + buffer2.byteLength), @@ -16,7 +16,13 @@ function concatBuffers(buffer1: ArrayBuffer, buffer2: ArrayBuffer) { const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength); tmp.set(new Uint8Array(buffer1), 0); tmp.set(new Uint8Array(buffer2), buffer1.byteLength); - return tmp.buffer as MP4BoxBuffer; + + const arrayBuffer = tmp.buffer; + + return Object.assign(arrayBuffer, { + fileStart: buffer1.fileStart, + usedBytes: buffer1.usedBytes + buffer2.usedBytes, + }); } /** @@ -31,7 +37,7 @@ export class MultiBufferStream extends DataStream { bufferIndex: number; constructor(buffer?: MP4BoxBuffer) { - super(new ArrayBuffer(), 0, DataStream.BIG_ENDIAN); + super(undefined, 0, DataStream.BIG_ENDIAN); // List of ArrayBuffers, with a fileStart property, sorted in fileStart order and non-overlapping this.buffers = []; this.bufferIndex = -1; @@ -73,14 +79,13 @@ export class MultiBufferStream extends DataStream { * @param {ArrayBuffer} buffer * @param {Number} offset the start of new buffer * @param {Number} newLength the length of the new buffer - * @return {ArrayBuffer} the new buffer + * @return {MP4BoxBuffer} the new buffer */ - reduceBuffer(buffer: MP4BoxBuffer, offset: number, newLength: number) { + reduceBuffer(buffer: MP4BoxBuffer, offset: number, newLength: number): MP4BoxBuffer { const smallB = new Uint8Array(newLength); smallB.set(new Uint8Array(buffer, offset, newLength)); - (smallB.buffer as MP4BoxBuffer).fileStart = buffer.fileStart + offset; - (smallB.buffer as MP4BoxBuffer).usedBytes = 0; - return smallB.buffer as MP4BoxBuffer; + + return Object.assign(smallB.buffer, { fileStart: buffer.fileStart + offset, usedBytes: 0 }); } /** From 48eabb0e7960142771928c80a97fd033c78d401f Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Mon, 26 May 2025 14:58:06 +0200 Subject: [PATCH 6/7] fix: replace declare by types --- src/boxes/defaults.ts | 2 +- src/boxes/sampleentries/sampleentry.ts | 8 ++++---- src/boxes/tref.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/boxes/defaults.ts b/src/boxes/defaults.ts index cb32fecb..ba798f83 100644 --- a/src/boxes/defaults.ts +++ b/src/boxes/defaults.ts @@ -348,7 +348,7 @@ export class ipcoBox extends ContainerBox { export class grplBox extends ContainerBox { type = 'grpl' as const; box_name = 'GroupsListBox'; - declare boxes: Array; + boxes: Array = []; } export class j2kHBox extends ContainerBox { type = 'j2kH' as const; diff --git a/src/boxes/sampleentries/sampleentry.ts b/src/boxes/sampleentries/sampleentry.ts index 3eaed865..d7d8bcd3 100644 --- a/src/boxes/sampleentries/sampleentry.ts +++ b/src/boxes/sampleentries/sampleentry.ts @@ -25,8 +25,8 @@ function decimalToHex(d: number | string, padding?: number | null) { } class avcCSampleEntryBase extends VisualSampleEntry { - declare avcC: avcCBox; - declare avcCs: Array; + avcC: avcCBox | undefined; + avcCs: Array = []; /** @bundle box-codecs.js */ getCodec() { @@ -96,8 +96,8 @@ export class dav1SampleEntry extends VisualSampleEntry { } class hvcCSampleEntryBase extends VisualSampleEntry { - declare hvcC: hvcCBox; - declare hvcCs: Array; + hvcC: hvcCBox; + hvcCs: Array = []; /** @bundle box-codecs.js */ getCodec(): string { diff --git a/src/boxes/tref.ts b/src/boxes/tref.ts index d294771f..ca86a399 100644 --- a/src/boxes/tref.ts +++ b/src/boxes/tref.ts @@ -6,7 +6,7 @@ import { Log } from '#/log'; export class trefBox extends ContainerBox { type = 'tref' as const; - declare boxes: Array; + boxes: Array = []; parse(stream: MultiBufferStream) { while (stream.getPosition() < this.start + this.size) { From 078e7c5c640053e479d0200c62e5b3dee3454f84 Mon Sep 17 00:00:00 2001 From: Erwan Vivien Date: Wed, 28 May 2025 10:47:37 +0200 Subject: [PATCH 7/7] fix: mark `| undefined` fields that are optional --- src/boxes/avcC.ts | 6 +++--- src/boxes/sampleentries/sampleentry.ts | 23 +++++++++++++---------- src/boxes/sampleentries/stxt.ts | 2 +- src/boxes/samplegroups/avss.ts | 4 ++-- src/boxes/url.ts | 6 +++--- src/boxes/urn.ts | 4 ++-- src/boxes/vvcC.ts | 8 ++++---- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/boxes/avcC.ts b/src/boxes/avcC.ts index 8f9e0c6b..e296b29e 100644 --- a/src/boxes/avcC.ts +++ b/src/boxes/avcC.ts @@ -17,7 +17,7 @@ export class avcCBox extends Box { SPS: ParameterSetArray; nb_PPS_nalus: number; PPS: ParameterSetArray; - ext: Uint8Array; + ext: Uint8Array | undefined; parse(stream: DataStream | MP4BoxStream) { this.configurationVersion = stream.readUint8(); @@ -62,7 +62,7 @@ export class avcCBox extends Box { for (let i = 0; i < this.PPS.length; i++) { this.size += 2 + this.PPS[i].length; } - if (this.ext) { + if (this.ext !== undefined) { this.size += this.ext.length; } this.writeHeader(stream); @@ -81,7 +81,7 @@ export class avcCBox extends Box { stream.writeUint16(this.PPS[i].length); stream.writeUint8Array(this.PPS[i].data); } - if (this.ext) { + if (this.ext !== undefined) { stream.writeUint8Array(this.ext); } }; diff --git a/src/boxes/sampleentries/sampleentry.ts b/src/boxes/sampleentries/sampleentry.ts index d7d8bcd3..7e8c03bd 100644 --- a/src/boxes/sampleentries/sampleentry.ts +++ b/src/boxes/sampleentries/sampleentry.ts @@ -31,7 +31,7 @@ class avcCSampleEntryBase extends VisualSampleEntry { /** @bundle box-codecs.js */ getCodec() { const baseCodec = super.getCodec(); - if (this.avcC) { + if (this.avcC !== undefined) { return `${baseCodec}.${decimalToHex(this.avcC.AVCProfileIndication)}${decimalToHex( this.avcC.profile_compatibility, )}${decimalToHex(this.avcC.AVCLevelIndication)}`; @@ -96,13 +96,13 @@ export class dav1SampleEntry extends VisualSampleEntry { } class hvcCSampleEntryBase extends VisualSampleEntry { - hvcC: hvcCBox; + hvcC: hvcCBox | undefined; hvcCs: Array = []; /** @bundle box-codecs.js */ getCodec(): string { let baseCodec = super.getCodec(); - if (this.hvcC) { + if (this.hvcC !== undefined) { baseCodec += '.'; switch (this.hvcC.general_profile_space) { case 0: @@ -139,7 +139,7 @@ class hvcCSampleEntryBase extends VisualSampleEntry { let hasByte = false; let constraint_string = ''; for (let i = 5; i >= 0; i--) { - if (this.hvcC.general_constraint_indicator[i] || hasByte) { + if (this.hvcC.general_constraint_indicator[i] !== 0 || hasByte) { constraint_string = '.' + decimalToHex(this.hvcC.general_constraint_indicator[i], 0) + constraint_string; hasByte = true; @@ -147,6 +147,7 @@ class hvcCSampleEntryBase extends VisualSampleEntry { } baseCodec += constraint_string; } + return baseCodec; } } @@ -177,13 +178,14 @@ export class dvheSampleEntry extends VisualSampleEntry { /** @babel box-codecs.js */ class vvcCSampleEntryBase extends VisualSampleEntry { - vvcC: vvcCBox; + vvcC: vvcCBox | undefined; vvcCs: Array; + getCodec() { let baseCodec = super.getCodec(); - if (this.vvcC) { + if (this.vvcC !== undefined) { baseCodec += '.' + this.vvcC.general_profile_idc; - if (this.vvcC.general_tier_flag) { + if (this.vvcC.general_tier_flag !== 0) { baseCodec += '.H'; } else { baseCodec += '.L'; @@ -191,7 +193,7 @@ class vvcCSampleEntryBase extends VisualSampleEntry { baseCodec += this.vvcC.general_level_idc; let constraint_string = ''; - if (this.vvcC.general_constraint_info) { + if (this.vvcC.general_constraint_info !== undefined) { const bytes = []; let byte = 0; byte |= this.vvcC.ptl_frame_only_constraint_flag << 7; @@ -300,14 +302,15 @@ export class uncvSampleEntry extends VisualSampleEntry { } export class mp4aSampleEntry extends AudioSampleEntry { - esds: esdsBox; + esds: esdsBox | undefined; esdss: Array; type = 'mp4a' as const; getCodec() { const baseCodec = super.getCodec(); - if (this.esds && this.esds.esd) { + // TODO: Check if esds.esd can be undefined + if (this.esds !== undefined && this.esds.esd) { const oti = this.esds.esd.getOTI(); const dsi = this.esds.esd.getAudioConfig(); return baseCodec + '.' + decimalToHex(oti) + (dsi ? '.' + dsi : ''); diff --git a/src/boxes/sampleentries/stxt.ts b/src/boxes/sampleentries/stxt.ts index 5580ad01..10f97463 100644 --- a/src/boxes/sampleentries/stxt.ts +++ b/src/boxes/sampleentries/stxt.ts @@ -16,7 +16,7 @@ export class stxtSampleEntry extends SubtitleSampleEntry { getCodec() { const baseCodec = super.getCodec(); - if (this.mime_format) { + if (this.mime_format.length > 0) { return baseCodec + '.' + this.mime_format; } else { return baseCodec; diff --git a/src/boxes/samplegroups/avss.ts b/src/boxes/samplegroups/avss.ts index 2faf81b9..6ee1415f 100644 --- a/src/boxes/samplegroups/avss.ts +++ b/src/boxes/samplegroups/avss.ts @@ -22,10 +22,10 @@ export class avssSampleGroupEntry extends SampleGroupEntry { const tmp_byte = stream.readUint8(); this.durationFlag = tmp_byte >> 7; this.avgRateFlag = (tmp_byte >> 6) & 0x1; - if (this.durationFlag) { + if (this.durationFlag !== 0) { this.duration = stream.readUint32(); } - if (this.avgRateFlag) { + if (this.avgRateFlag !== 0) { this.accurateStatisticsFlag = stream.readUint8(); this.avgBitRate = stream.readUint16(); this.avgFrameRate = stream.readUint16(); diff --git a/src/boxes/url.ts b/src/boxes/url.ts index 02c26b81..c743ba03 100644 --- a/src/boxes/url.ts +++ b/src/boxes/url.ts @@ -5,7 +5,7 @@ export class urlBox extends FullBox { type = 'url ' as const; box_name = 'DataEntryUrlBox'; - location?: string; + location: string | undefined; parse(stream: MultiBufferStream) { this.parseFullHeader(stream); @@ -17,7 +17,7 @@ export class urlBox extends FullBox { /** @bundle writing/url.js */ write = (stream: MultiBufferStream) => { this.version = 0; - if (this.location) { + if (this.location !== undefined) { this.flags = 0; this.size = this.location.length + 1; } else { @@ -25,7 +25,7 @@ export class urlBox extends FullBox { this.size = 0; } this.writeHeader(stream); - if (this.location) { + if (this.location !== undefined) { stream.writeCString(this.location); } }; diff --git a/src/boxes/urn.ts b/src/boxes/urn.ts index 042df8c0..fb234aff 100644 --- a/src/boxes/urn.ts +++ b/src/boxes/urn.ts @@ -6,7 +6,7 @@ export class urnBox extends FullBox { box_name = 'DataEntryUrnBox'; name: string; - location: string; + location: string | undefined; parse(stream: MultiBufferStream) { this.parseFullHeader(stream); @@ -23,7 +23,7 @@ export class urnBox extends FullBox { this.size = this.name.length + 1 + (this.location ? this.location.length + 1 : 0); this.writeHeader(stream); stream.writeCString(this.name); - if (this.location) { + if (this.location !== undefined) { stream.writeCString(this.location); } }; diff --git a/src/boxes/vvcC.ts b/src/boxes/vvcC.ts index 0cd530d5..5282517c 100644 --- a/src/boxes/vvcC.ts +++ b/src/boxes/vvcC.ts @@ -19,7 +19,7 @@ export class vvcCBox extends FullBox { general_level_idc: number; ptl_frame_only_constraint_flag: number; ptl_multilayer_enabled_flag: number; - general_constraint_info: Uint8Array; + general_constraint_info: Uint8Array | undefined; ptl_sublayer_present_mask: number; sublayer_level_idc: Array; ptl_num_sub_profiles: number; @@ -58,7 +58,7 @@ export class vvcCBox extends FullBox { this.lengthSizeMinusOne = bitReader.extract_bits(2); this.ptl_present_flag = bitReader.extract_bits(1); - if (this.ptl_present_flag) { + if (this.ptl_present_flag !== 0) { bitReader.stream_read_2_bytes(stream); this.ols_idx = bitReader.extract_bits(9); this.num_sublayers = bitReader.extract_bits(3); @@ -84,7 +84,7 @@ export class vvcCBox extends FullBox { this.ptl_multilayer_enabled_flag = bitReader.extract_bits(1); this.general_constraint_info = new Uint8Array(this.num_bytes_constraint_info); - if (this.num_bytes_constraint_info) { + if (this.num_bytes_constraint_info !== 0) { for (let i = 0; i < this.num_bytes_constraint_info - 1; i++) { const cnstr1 = bitReader.extract_bits(6); bitReader.stream_read_1_bytes(stream); @@ -120,7 +120,7 @@ export class vvcCBox extends FullBox { this.ptl_num_sub_profiles = stream.readUint8(); this.general_sub_profile_idc = []; - if (this.ptl_num_sub_profiles) { + if (this.ptl_num_sub_profiles !== 0) { for (let i = 0; i < this.ptl_num_sub_profiles; i++) { this.general_sub_profile_idc.push(stream.readUint32()); }