From c4cd9741056a94121cd9fde86ac3de77f3fe0ac8 Mon Sep 17 00:00:00 2001 From: Sudev Kiyada Date: Tue, 3 Jun 2025 13:32:35 +0530 Subject: [PATCH] fixes lint and svelte-check --- .../ScrollyVideo/demo/WithScrollerBase.svelte | 18 ------ .../ScrollyVideo/js/videoDecoder.ts | 55 +++++++++++++++++-- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/components/ScrollyVideo/demo/WithScrollerBase.svelte b/src/components/ScrollyVideo/demo/WithScrollerBase.svelte index 3d877521..a6252096 100644 --- a/src/components/ScrollyVideo/demo/WithScrollerBase.svelte +++ b/src/components/ScrollyVideo/demo/WithScrollerBase.svelte @@ -118,24 +118,6 @@ } } - #debugger { - width: 100%; - height: 100vh; - background-color: hotpink; - position: absolute; - top: 0; - left: 0; - z-index: 1; - - img { - width: 100%; - height: 100%; - object-fit: cover; - padding: 0; - margin: 0; - } - } - .step-foreground-container { height: 100vh; width: 100%; diff --git a/src/components/ScrollyVideo/js/videoDecoder.ts b/src/components/ScrollyVideo/js/videoDecoder.ts index ae59c0d3..a96af7ba 100644 --- a/src/components/ScrollyVideo/js/videoDecoder.ts +++ b/src/components/ScrollyVideo/js/videoDecoder.ts @@ -50,9 +50,14 @@ class Writer { * @param avccBox * @returns {*} */ +interface NALUnit { + length: number; + nalu: number[]; +} + const getExtradata = (avccBox: { - SPS: string | unknown[]; - PPS: string | unknown[]; + SPS: NALUnit[]; + PPS: NALUnit[]; configurationVersion: number; AVCProfileIndication: number; profile_compatibility: number; @@ -65,11 +70,11 @@ const getExtradata = (avccBox: { let size = 7; for (i = 0; i < avccBox.SPS.length; i += 1) { // nalu length is encoded as a uint16. - size += 2 + avccBox.SPS[i].length; + size += 2 + (avccBox.SPS[i] as { length: number }).length; } for (i = 0; i < avccBox.PPS.length; i += 1) { // nalu length is encoded as a uint16. - size += 2 + avccBox.PPS[i].length; + size += 2 + (avccBox.PPS[i] as { length: number }).length; } const writer = new Writer(size); @@ -164,9 +169,47 @@ const decodeVideo = ( if (debug) console.info('Video with codec:', codec); scrollyVideoState.framesData.codec = codec; + // Define a type for moov to avoid using 'any' + interface AvcCBox { + SPS: NALUnit[]; + PPS: NALUnit[]; + configurationVersion: number; + AVCProfileIndication: number; + profile_compatibility: number; + AVCLevelIndication: number; + lengthSizeMinusOne: number; + nb_SPS_nalus: number; + nb_PPS_nalus: number; + } + interface StsdEntry { + avcC: AvcCBox; + } + interface Stsd { + entries: StsdEntry[]; + } + interface Stbl { + stsd: Stsd; + } + interface Minf { + stbl: Stbl; + } + interface Mdia { + minf: Minf; + } + interface Trak { + mdia: Mdia; + } + interface Moov { + traks: Trak[]; + } + // Gets the avccbox used for reading extradata - const avccBox = - mp4boxfile.moov.traks[0].mdia.minf.stbl.stsd.entries[0].avcC; + const moov = mp4boxfile.moov as Moov | undefined; + const avccBox = moov?.traks[0].mdia.minf.stbl.stsd.entries[0].avcC; + if (!avccBox) { + reject(new Error('Could not find avcC box for extradata.')); + return; + } const extradata = getExtradata(avccBox); // configure decoder