🎥 Make videos programmatically with React
fix the webm test case
Jonny Burgere2086c0d03b1
diff --git a/packages/media-parser/src/containers/webm/seek/seeking-hints.ts b/packages/media-parser/src/containers/webm/seek/seeking-hints.tsindex a963582f50..a4ceb90b27 100644--- a/packages/media-parser/src/containers/webm/seek/seeking-hints.ts+++ b/packages/media-parser/src/containers/webm/seek/seeking-hints.ts@@ -24,6 +24,7 @@ export const getSeekingHintsFromMatroska = (: null,keyframes,loadedCues,+ timestampMap: webmState.getTimeStampMapForSeekingHints(),};};@@ -36,4 +37,5 @@ export const setSeekingHintsForWebm = ({}) => {state.webm.cues.setFromSeekingHints(hints);state.keyframes.setFromSeekingHints(hints);+ state.webm.setTimeStampMapForSeekingHints(hints.timestampMap);};diff --git a/packages/media-parser/src/seeking-hints.ts b/packages/media-parser/src/seeking-hints.tsindex 8eb673656d..1d27bfe8db 100644--- a/packages/media-parser/src/seeking-hints.ts+++ b/packages/media-parser/src/seeking-hints.ts@@ -35,6 +35,7 @@ export type WebmSeekingHints = {track: null | {timescale: number; trackId: number};keyframes: MediaParserKeyframe[];loadedCues: LazyCuesLoadedOrNull;+ timestampMap: Map<number, number>;};export type SeekingHints =diff --git a/packages/media-parser/src/state/matroska/webm.ts b/packages/media-parser/src/state/matroska/webm.tsindex 44d656a743..489e73de86 100644--- a/packages/media-parser/src/state/matroska/webm.ts+++ b/packages/media-parser/src/state/matroska/webm.ts@@ -61,7 +61,7 @@ export const webmState = ({};};- const timestampMap = new Map<number, number>();+ let timestampMap = new Map<number, number>();const getTimestampOffsetForByteOffset = (byteOffset: number) => {const entries = Array.from(timestampMap.entries());@@ -126,12 +126,24 @@ export const webmState = ({src,});+ const getTimeStampMapForSeekingHints = () => {+ return timestampMap;+ };++ const setTimeStampMapForSeekingHints = (+ newTimestampMap: Map<number, number>,+ ) => {+ timestampMap = newTimestampMap;+ };+return {cues,onTrackEntrySegment,getTrackInfoByNumber: (id: number) => trackEntries[id],setTimestampOffset,getTimestampOffsetForByteOffset,+ getTimeStampMapForSeekingHints,+ setTimeStampMapForSeekingHints,getTimescale,setTimescale,addSegment: (seg: Omit<SegmentSection, 'index'>) => {diff --git a/packages/media-parser/src/test/seeking/webm-cues.test.ts b/packages/media-parser/src/test/seeking/webm-cues.test.tsindex a2e7edad40..2f221fe4da 100644--- a/packages/media-parser/src/test/seeking/webm-cues.test.ts+++ b/packages/media-parser/src/test/seeking/webm-cues.test.ts@@ -38,10 +38,10 @@ test('get webm cues', async () => {]);});-test('should use them for seeking', async () => {- const controller = mediaParserController();+const controller1 = mediaParserController();- controller._experimentalSeek({+test('should use them for seeking', async () => {+ controller1._experimentalSeek({type: 'keyframe-before-time',timeInSeconds: 10,});@@ -53,41 +53,42 @@ test('should use them for seeking', async () => {src: exampleVideos.stretchedVp8,acknowledgeRemotionLicense: true,reader: nodeReader,- controller,+ controller: controller1,onVideoTrack: () => {return (s) => {samples++;+ const timeInSeconds = s.timestamp / s.timescale;if (samples === 1) {- expect(s.timestamp / s.timescale).toBe(9.603);- controller._experimentalSeek({+ expect(timeInSeconds).toBe(9.603);+ controller1._experimentalSeek({type: 'keyframe-before-time',timeInSeconds: 5,});}if (samples === 2) {- expect(s.timestamp / s.timescale).toBe(4.803);- controller._experimentalSeek({+ expect(timeInSeconds).toBe(4.803);+ controller1._experimentalSeek({type: 'keyframe-before-time',timeInSeconds: 0,});}if (samples === 3) {- expect(s.timestamp / s.timescale).toBe(0.003);- controller._experimentalSeek({+ expect(timeInSeconds).toBe(0.003);+ controller1._experimentalSeek({type: 'keyframe-before-time',timeInSeconds: 5,});}if (samples === 4) {- expect(s.timestamp / s.timescale).toBe(4.803);- controller._experimentalSeek({+ expect(timeInSeconds).toBe(4.803);+ controller1._experimentalSeek({type: 'keyframe-before-time',timeInSeconds: 5,});- controller.abort();+ controller1.abort();}};},@@ -98,7 +99,7 @@ test('should use them for seeking', async () => {}}- const seeks = controller._internals.performedSeeksSignal.getPerformedSeeks();+ const seeks = controller1._internals.performedSeeksSignal.getPerformedSeeks();expect(seeks).toEqual([{from: 4552,@@ -123,9 +124,94 @@ test('should use them for seeking', async () => {]);});+test('should be able to use precomputed seeking hints', async () => {+ let samples = 0;++ const controller2 = mediaParserController();+ controller2._experimentalSeek({+ type: 'keyframe-before-time',+ timeInSeconds: 10,+ });++ try {+ await parseMedia({+ src: exampleVideos.stretchedVp8,+ acknowledgeRemotionLicense: true,+ reader: nodeReader,+ controller: controller2,+ seekingHints: await controller1.getSeekingHints(),+ onVideoTrack: () => {+ return (s) => {+ samples++;+ const timeInSeconds = s.timestamp / s.timescale;+ if (samples === 1) {+ expect(timeInSeconds).toBe(9.603);+ controller2._experimentalSeek({+ type: 'keyframe-before-time',+ timeInSeconds: 5,+ });+ }++ if (samples === 2) {+ expect(timeInSeconds).toBe(4.803);+ controller2._experimentalSeek({+ type: 'keyframe-before-time',+ timeInSeconds: 0,+ });+ }++ if (samples === 3) {+ expect(timeInSeconds).toBe(0.003);+ controller2._experimentalSeek({+ type: 'keyframe-before-time',+ timeInSeconds: 5,+ });+ }++ if (samples === 4) {+ expect(timeInSeconds).toBe(4.803);+ controller2._experimentalSeek({+ type: 'keyframe-before-time',+ timeInSeconds: 5,+ });+ controller2.abort();+ }+ };+ },+ });+ } catch (error) {+ if (!hasBeenAborted(error)) {+ throw error;+ }+ }++ const seeks = controller2._internals.performedSeeksSignal.getPerformedSeeks();+ expect(seeks).toEqual([+ {+ from: 4552,+ to: 10318915,+ type: 'user-initiated',+ },+ {+ from: 10539613,+ to: 5081929,+ type: 'user-initiated',+ },+ {+ from: 5279894,+ to: 4540,+ type: 'user-initiated',+ },+ {+ from: 325902,+ to: 5081929,+ type: 'user-initiated',+ },+ ]);+});+test('should work if there are no cues', async () => {const controller = mediaParserController();-controller._experimentalSeek({type: 'keyframe-before-time',timeInSeconds: 10,