@remotion/media-parser 4.0.200 → 4.0.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/av1-codec-string.d.ts +5 -0
- package/dist/av1-codec-string.js +18 -1
- package/dist/bitstream/av1.d.ts +2 -0
- package/dist/bitstream/av1.js +12 -0
- package/dist/boxes/iso-base-media/avcc-hvcc.d.ts +20 -0
- package/dist/boxes/iso-base-media/avcc-hvcc.js +73 -0
- package/dist/boxes/iso-base-media/avcc.d.ts +18 -0
- package/dist/boxes/iso-base-media/avcc.js +27 -0
- package/dist/boxes/iso-base-media/esds-descriptors.d.ts +21 -0
- package/dist/boxes/iso-base-media/esds-descriptors.js +62 -0
- package/dist/boxes/iso-base-media/esds.d.ts +15 -0
- package/dist/boxes/iso-base-media/esds.js +27 -0
- package/dist/boxes/iso-base-media/mdat/mdat.js +2 -1
- package/dist/boxes/iso-base-media/moov/moov.js +1 -0
- package/dist/boxes/iso-base-media/mvhd.js +2 -2
- package/dist/boxes/iso-base-media/process-box.d.ts +4 -2
- package/dist/boxes/iso-base-media/process-box.js +56 -40
- package/dist/boxes/iso-base-media/stsd/keys.js +1 -1
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +2 -1
- package/dist/boxes/iso-base-media/stsd/mebx.js +2 -1
- package/dist/boxes/iso-base-media/stsd/samples.js +3 -0
- package/dist/boxes/iso-base-media/stsd/stco.d.ts +3 -2
- package/dist/boxes/iso-base-media/stsd/stco.js +2 -2
- package/dist/boxes/iso-base-media/trak/trak.js +1 -0
- package/dist/boxes/webm/av1-codec-private.js +1 -1
- package/dist/boxes/webm/bitstream/av1.js +10 -1
- package/dist/boxes/webm/description.d.ts +2 -2
- package/dist/boxes/webm/description.js +2 -2
- package/dist/boxes/webm/ebml.d.ts +2 -2
- package/dist/boxes/webm/ebml.js +23 -1
- package/dist/boxes/webm/get-ready-tracks.d.ts +1 -1
- package/dist/boxes/webm/get-ready-tracks.js +3 -3
- package/dist/boxes/webm/get-sample-from-block.d.ts +17 -0
- package/dist/boxes/webm/get-sample-from-block.js +78 -0
- package/dist/boxes/webm/get-track.d.ts +2 -2
- package/dist/boxes/webm/get-track.js +26 -25
- package/dist/boxes/webm/make-header.d.ts +3 -1
- package/dist/boxes/webm/make-header.js +90 -32
- package/dist/boxes/webm/parse-ebml.d.ts +12 -0
- package/dist/boxes/webm/parse-ebml.js +175 -0
- package/dist/boxes/webm/parse-webm-header.js +8 -9
- package/dist/boxes/webm/segments/all-segments.d.ts +572 -1
- package/dist/boxes/webm/segments/all-segments.js +353 -2
- package/dist/boxes/webm/segments/track-entry.d.ts +5 -189
- package/dist/boxes/webm/segments/track-entry.js +2 -457
- package/dist/boxes/webm/segments.d.ts +3 -16
- package/dist/boxes/webm/segments.js +40 -219
- package/dist/boxes/webm/traversal.d.ts +5 -5
- package/dist/boxes/webm/traversal.js +17 -6
- package/dist/buffer-iterator.d.ts +10 -7
- package/dist/buffer-iterator.js +83 -7
- package/dist/create/create-media.d.ts +2 -0
- package/dist/create/create-media.js +36 -0
- package/dist/create/matroska-header.d.ts +1 -0
- package/dist/create/matroska-header.js +66 -0
- package/dist/create/matroska-info.d.ts +4 -0
- package/dist/create/matroska-info.js +39 -0
- package/dist/create/matroska-segment.d.ts +1 -0
- package/dist/create/matroska-segment.js +12 -0
- package/dist/create/matroska-trackentry.d.ts +21 -0
- package/dist/create/matroska-trackentry.js +191 -0
- package/dist/create-media.d.ts +1 -0
- package/dist/create-media.js +78 -0
- package/dist/from-fetch.js +13 -3
- package/dist/from-input-type-file.d.ts +2 -0
- package/dist/from-input-type-file.js +37 -0
- package/dist/from-node.js +9 -2
- package/dist/from-web-file.js +6 -1
- package/dist/from-web.js +15 -6
- package/dist/get-audio-codec.d.ts +2 -2
- package/dist/get-audio-codec.js +13 -13
- package/dist/get-codec.d.ts +4 -0
- package/dist/get-codec.js +22 -0
- package/dist/get-duration.js +12 -14
- package/dist/get-sample-positions.js +1 -1
- package/dist/get-tracks.js +2 -2
- package/dist/get-video-codec.js +13 -13
- package/dist/has-all-info.js +1 -1
- package/dist/options.d.ts +3 -2
- package/dist/parse-media.js +17 -10
- package/dist/parse-video.js +16 -0
- package/dist/parser-context.d.ts +1 -0
- package/dist/parser-state.d.ts +4 -3
- package/dist/parser-state.js +16 -3
- package/dist/reader.d.ts +1 -1
- package/dist/readers/from-fetch.d.ts +2 -0
- package/dist/readers/from-fetch.js +64 -0
- package/dist/readers/from-node.d.ts +2 -0
- package/dist/readers/from-node.js +40 -0
- package/dist/readers/from-web-file.d.ts +2 -0
- package/dist/readers/from-web-file.js +39 -0
- package/dist/readers/reader.d.ts +11 -0
- package/dist/readers/reader.js +2 -0
- package/dist/traversal.d.ts +19 -17
- package/dist/traversal.js +38 -39
- package/dist/web-file.d.ts +2 -0
- package/dist/web-file.js +37 -0
- package/dist/writers/web-fs.d.ts +2 -0
- package/dist/writers/web-fs.js +28 -0
- package/dist/writers/writer.d.ts +9 -0
- package/dist/writers/writer.js +2 -0
- package/input.webm +0 -0
- package/package.json +2 -2
- package/src/boxes/iso-base-media/mdat/mdat.ts +2 -1
- package/src/boxes/iso-base-media/moov/moov.ts +1 -0
- package/src/boxes/iso-base-media/mvhd.ts +2 -2
- package/src/boxes/iso-base-media/process-box.ts +70 -40
- package/src/boxes/iso-base-media/stsd/keys.ts +1 -1
- package/src/boxes/iso-base-media/stsd/mebx.ts +3 -0
- package/src/boxes/iso-base-media/stsd/samples.ts +3 -0
- package/src/boxes/iso-base-media/stsd/stco.ts +5 -3
- package/src/boxes/iso-base-media/trak/trak.ts +1 -0
- package/src/boxes/webm/av1-codec-private.ts +1 -1
- package/src/boxes/webm/description.ts +7 -4
- package/src/boxes/webm/ebml.ts +24 -4
- package/src/boxes/webm/get-ready-tracks.ts +4 -4
- package/src/boxes/webm/get-sample-from-block.ts +125 -0
- package/src/boxes/webm/get-track.ts +38 -31
- package/src/boxes/webm/make-header.ts +129 -32
- package/src/boxes/webm/parse-ebml.ts +247 -0
- package/src/boxes/webm/parse-webm-header.ts +8 -12
- package/src/boxes/webm/segments/all-segments.ts +539 -1
- package/src/boxes/webm/segments/track-entry.ts +5 -843
- package/src/boxes/webm/segments.ts +48 -435
- package/src/boxes/webm/traversal.ts +28 -15
- package/src/buffer-iterator.ts +104 -10
- package/src/from-fetch.ts +22 -3
- package/src/from-node.ts +18 -4
- package/src/from-web-file.ts +11 -1
- package/src/get-audio-codec.ts +14 -16
- package/src/get-duration.ts +15 -16
- package/src/get-sample-positions.ts +1 -1
- package/src/get-tracks.ts +2 -2
- package/src/get-video-codec.ts +13 -15
- package/src/has-all-info.ts +1 -1
- package/src/options.ts +3 -2
- package/src/parse-media.ts +20 -9
- package/src/parse-video.ts +17 -0
- package/src/parser-context.ts +1 -0
- package/src/parser-state.ts +22 -5
- package/src/reader.ts +1 -0
- package/src/test/create-matroska.test.ts +255 -7
- package/src/test/matroska.test.ts +311 -334
- package/src/test/mvhd.test.ts +1 -1
- package/src/test/parse-esds.test.ts +2 -2
- package/src/test/parse-stco.test.ts +4 -2
- package/src/test/parse-stsc.test.ts +2 -2
- package/src/test/parse-stsz.test.ts +2 -2
- package/src/test/parse-stts.test.ts +1 -1
- package/src/test/stream-local.test.ts +23 -9
- package/src/test/stream-remote.test.ts +23 -19
- package/src/test/stsd.test.ts +6 -2
- package/src/test/tkhd.test.ts +1 -1
- package/src/traversal.ts +62 -85
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/boxes/iso-base-media/ftype.d.ts +0 -9
- package/dist/boxes/iso-base-media/ftype.js +0 -31
- package/dist/get-video-metadata.d.ts +0 -2
- package/dist/get-video-metadata.js +0 -44
- package/dist/read-and-increment-offset.d.ts +0 -28
- package/dist/read-and-increment-offset.js +0 -177
- package/dist/understand-vorbis.d.ts +0 -1
- package/dist/understand-vorbis.js +0 -12
- package/src/boxes/webm/segments/duration.ts +0 -29
- package/src/boxes/webm/segments/info.ts +0 -34
- package/src/boxes/webm/segments/main.ts +0 -6
- package/src/boxes/webm/segments/muxing.ts +0 -18
- package/src/boxes/webm/segments/seek-head.ts +0 -34
- package/src/boxes/webm/segments/seek-position.ts +0 -18
- package/src/boxes/webm/segments/seek.ts +0 -45
- package/src/boxes/webm/segments/timestamp-scale.ts +0 -17
- package/src/boxes/webm/segments/tracks.ts +0 -32
- package/src/boxes/webm/segments/unknown.ts +0 -19
- package/src/boxes/webm/segments/void.ts +0 -18
- package/src/boxes/webm/segments/writing.ts +0 -18
- package/src/combine-uint8array.ts +0 -13
- /package/dist/{boxes/webm/bitstream/av1/frame.d.ts → get-samples.d.ts} +0 -0
- /package/dist/{boxes/webm/bitstream/av1/frame.js → get-samples.js} +0 -0
- /package/dist/{boxes/webm/bitstream/h264/get-h264-descriptor.d.ts → sample-aspect-ratio.d.ts} +0 -0
- /package/dist/{boxes/webm/bitstream/h264/get-h264-descriptor.js → sample-aspect-ratio.js} +0 -0
package/src/test/mvhd.test.ts
CHANGED
|
@@ -11,7 +11,7 @@ test('Parse ESDS box', () => {
|
|
|
11
11
|
0, 0, 0, 4, 226, 0, 0, 4, 226, 0, 6, 128, 128, 128, 1, 2,
|
|
12
12
|
]);
|
|
13
13
|
|
|
14
|
-
const iter = getArrayBufferIterator(buf);
|
|
14
|
+
const iter = getArrayBufferIterator(buf, null);
|
|
15
15
|
iter.counter.increment(8);
|
|
16
16
|
|
|
17
17
|
expect(
|
|
@@ -55,7 +55,7 @@ test('Parse two ESDS', () => {
|
|
|
55
55
|
226, 0, 5, 2, 17, 144, 6, 1, 2, 0, 0, 0, 24, 115, 116, 116, 115,
|
|
56
56
|
]);
|
|
57
57
|
|
|
58
|
-
const iter = getArrayBufferIterator(buf);
|
|
58
|
+
const iter = getArrayBufferIterator(buf, null);
|
|
59
59
|
iter.counter.increment(8);
|
|
60
60
|
|
|
61
61
|
expect(
|
|
@@ -12,12 +12,13 @@ test('Parse stco box', () => {
|
|
|
12
12
|
246,
|
|
13
13
|
]);
|
|
14
14
|
|
|
15
|
-
const iterator = getArrayBufferIterator(buf);
|
|
15
|
+
const iterator = getArrayBufferIterator(buf, null);
|
|
16
16
|
iterator.counter.increment(8);
|
|
17
17
|
const result = parseStco({
|
|
18
18
|
iterator,
|
|
19
19
|
size: buf.length - 8,
|
|
20
20
|
offset: 0,
|
|
21
|
+
mode64Bit: false,
|
|
21
22
|
});
|
|
22
23
|
expect(result).toEqual({
|
|
23
24
|
type: 'stco-box',
|
|
@@ -40,12 +41,13 @@ test('Parse stco box with empty chunk', () => {
|
|
|
40
41
|
172,
|
|
41
42
|
]);
|
|
42
43
|
|
|
43
|
-
const iterator = getArrayBufferIterator(buf);
|
|
44
|
+
const iterator = getArrayBufferIterator(buf, null);
|
|
44
45
|
iterator.counter.increment(8);
|
|
45
46
|
const result = parseStco({
|
|
46
47
|
iterator,
|
|
47
48
|
size: buf.length - 8,
|
|
48
49
|
offset: 0,
|
|
50
|
+
mode64Bit: false,
|
|
49
51
|
});
|
|
50
52
|
expect(result).toEqual({
|
|
51
53
|
type: 'stco-box',
|
|
@@ -11,7 +11,7 @@ test('Parse stsc box', () => {
|
|
|
11
11
|
0, 0, 1, 0, 0, 0, 1,
|
|
12
12
|
]);
|
|
13
13
|
|
|
14
|
-
const iterator = getArrayBufferIterator(buffer);
|
|
14
|
+
const iterator = getArrayBufferIterator(buffer, null);
|
|
15
15
|
iterator.counter.increment(8);
|
|
16
16
|
const result = parseStsc({
|
|
17
17
|
iterator,
|
|
@@ -51,7 +51,7 @@ test('Parse stsc box 2', () => {
|
|
|
51
51
|
0, 0, 0, 1,
|
|
52
52
|
]);
|
|
53
53
|
|
|
54
|
-
const iterator = getArrayBufferIterator(buffer);
|
|
54
|
+
const iterator = getArrayBufferIterator(buffer, null);
|
|
55
55
|
iterator.counter.increment(8);
|
|
56
56
|
const result = parseStsc({
|
|
57
57
|
iterator,
|
|
@@ -11,7 +11,7 @@ test('parse stsz box 1', () => {
|
|
|
11
11
|
186, 0, 0, 2, 83, 0, 0, 2, 36, 0, 0, 2, 99, 0, 0, 2, 189, 0, 0, 2, 23, 0, 0,
|
|
12
12
|
3, 8, 0, 0, 2, 74, 0, 0, 0, 52, 115, 116, 99, 111,
|
|
13
13
|
]);
|
|
14
|
-
const iterator = getArrayBufferIterator(buf);
|
|
14
|
+
const iterator = getArrayBufferIterator(buf, null);
|
|
15
15
|
iterator.counter.increment(8);
|
|
16
16
|
const result = parseStsz({
|
|
17
17
|
iterator,
|
|
@@ -37,7 +37,7 @@ test('parse stsz box 2', () => {
|
|
|
37
37
|
// actual box
|
|
38
38
|
0, 0, 0, 0, 0, 0, 3, 192, 0, 0, 0, 15, 0, 0, 0, 52, 115, 116, 99, 111,
|
|
39
39
|
]);
|
|
40
|
-
const iterator = getArrayBufferIterator(buf);
|
|
40
|
+
const iterator = getArrayBufferIterator(buf, null);
|
|
41
41
|
iterator.counter.increment(8);
|
|
42
42
|
const result = parseStsz({
|
|
43
43
|
iterator,
|
|
@@ -11,7 +11,7 @@ const buffer = new Uint8Array([
|
|
|
11
11
|
]);
|
|
12
12
|
|
|
13
13
|
test('Should parse stts box', () => {
|
|
14
|
-
const iterator = getArrayBufferIterator(buffer);
|
|
14
|
+
const iterator = getArrayBufferIterator(buffer, null);
|
|
15
15
|
iterator.counter.increment(8);
|
|
16
16
|
const result = parseStts({
|
|
17
17
|
data: iterator,
|
|
@@ -18,7 +18,7 @@ test('Should stream ISO base media', async () => {
|
|
|
18
18
|
tracks: true,
|
|
19
19
|
dimensions: true,
|
|
20
20
|
rotation: true,
|
|
21
|
-
|
|
21
|
+
unrotatedDimensions: true,
|
|
22
22
|
},
|
|
23
23
|
reader: nodeReader,
|
|
24
24
|
onVideoTrack: (track) => {
|
|
@@ -46,7 +46,7 @@ test('Should stream ISO base media', async () => {
|
|
|
46
46
|
expect(result.videoTracks.length).toBe(1);
|
|
47
47
|
expect(result.videoTracks[0].codec).toBe('hvc1.2.4.L150.b0');
|
|
48
48
|
expect(result.rotation).toBe(-90);
|
|
49
|
-
expect(result.
|
|
49
|
+
expect(result.unrotatedDimensions).toEqual({
|
|
50
50
|
height: 2160,
|
|
51
51
|
width: 3840,
|
|
52
52
|
});
|
|
@@ -258,7 +258,7 @@ test('Should stream variable fps video', async () => {
|
|
|
258
258
|
videoCodec: true,
|
|
259
259
|
audioCodec: true,
|
|
260
260
|
rotation: true,
|
|
261
|
-
|
|
261
|
+
unrotatedDimensions: true,
|
|
262
262
|
tracks: true,
|
|
263
263
|
boxes: true,
|
|
264
264
|
},
|
|
@@ -278,8 +278,8 @@ test('Should stream variable fps video', async () => {
|
|
|
278
278
|
|
|
279
279
|
expect(parsed.dimensions.width).toBe(1280);
|
|
280
280
|
expect(parsed.dimensions.height).toBe(720);
|
|
281
|
-
expect(parsed.
|
|
282
|
-
expect(parsed.
|
|
281
|
+
expect(parsed.unrotatedDimensions.width).toBe(1280);
|
|
282
|
+
expect(parsed.unrotatedDimensions.height).toBe(720);
|
|
283
283
|
expect(parsed.durationInSeconds).toBe(22.901);
|
|
284
284
|
expect(parsed.videoCodec).toBe('vp8');
|
|
285
285
|
expect(parsed.audioCodec).toBe('opus');
|
|
@@ -413,7 +413,7 @@ test('Should get duration of HEVC video', async () => {
|
|
|
413
413
|
audioCodec: true,
|
|
414
414
|
rotation: true,
|
|
415
415
|
tracks: true,
|
|
416
|
-
|
|
416
|
+
unrotatedDimensions: true,
|
|
417
417
|
videoCodec: true,
|
|
418
418
|
},
|
|
419
419
|
onVideoTrack: () => {
|
|
@@ -437,7 +437,7 @@ test('Should get duration of HEVC video', async () => {
|
|
|
437
437
|
expect(parsed.audioTracks.length).toBe(1);
|
|
438
438
|
expect(parsed.audioTracks[0].codec).toBe('mp4a.40.02');
|
|
439
439
|
expect(parsed.audioTracks[0].description).toEqual(new Uint8Array([18, 16]));
|
|
440
|
-
expect(parsed.
|
|
440
|
+
expect(parsed.unrotatedDimensions).toEqual({
|
|
441
441
|
width: 1920,
|
|
442
442
|
height: 1080,
|
|
443
443
|
});
|
|
@@ -456,7 +456,7 @@ test('Custom DAR', async () => {
|
|
|
456
456
|
tracks: true,
|
|
457
457
|
dimensions: true,
|
|
458
458
|
rotation: true,
|
|
459
|
-
|
|
459
|
+
unrotatedDimensions: true,
|
|
460
460
|
},
|
|
461
461
|
reader: nodeReader,
|
|
462
462
|
});
|
|
@@ -480,7 +480,7 @@ test('Custom DAR', async () => {
|
|
|
480
480
|
expect(parsed.videoTracks[0].codedWidth).toBe(1280);
|
|
481
481
|
expect(parsed.videoTracks[0].codedHeight).toBe(720);
|
|
482
482
|
expect(parsed.rotation).toBe(0);
|
|
483
|
-
expect(parsed.
|
|
483
|
+
expect(parsed.unrotatedDimensions).toEqual({
|
|
484
484
|
height: 720,
|
|
485
485
|
width: 405,
|
|
486
486
|
});
|
|
@@ -729,3 +729,17 @@ test('Should stream transparent video', async () => {
|
|
|
729
729
|
expect(videoSamples).toBe(39);
|
|
730
730
|
expect(keyFrames).toBe(1);
|
|
731
731
|
});
|
|
732
|
+
|
|
733
|
+
test('Acknowledge there are .avi file', () => {
|
|
734
|
+
const parsed = parseMedia({
|
|
735
|
+
src: RenderInternals.exampleVideos.avi,
|
|
736
|
+
fields: {
|
|
737
|
+
tracks: true,
|
|
738
|
+
boxes: true,
|
|
739
|
+
},
|
|
740
|
+
reader: nodeReader,
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
expect(parsed).rejects.toThrow('AVI');
|
|
744
|
+
expect(parsed).rejects.toThrow('not yet supported');
|
|
745
|
+
});
|
|
@@ -20,25 +20,29 @@ test('Should stream', async () => {
|
|
|
20
20
|
expect(result.videoCodec).toEqual('h264');
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
test(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
23
|
+
test(
|
|
24
|
+
'Should stream from Wikipedia',
|
|
25
|
+
async () => {
|
|
26
|
+
const result = await parseMedia({
|
|
27
|
+
src: 'https://upload.wikimedia.org/wikipedia/commons/transcoded/c/c0/Big_Buck_Bunny_4K.webm/Big_Buck_Bunny_4K.webm.720p.vp9.webm',
|
|
28
|
+
fields: {
|
|
29
|
+
durationInSeconds: true,
|
|
30
|
+
fps: true,
|
|
31
|
+
dimensions: true,
|
|
32
|
+
videoCodec: true,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
expect(result.durationInSeconds).toBe(634.571);
|
|
36
|
+
// TODO: Not yet implemented
|
|
37
|
+
expect(result.fps).toBe(null);
|
|
38
|
+
expect(result.dimensions).toEqual({
|
|
39
|
+
width: 1280,
|
|
40
|
+
height: 720,
|
|
41
|
+
});
|
|
42
|
+
expect(result.videoCodec).toEqual('vp9');
|
|
43
|
+
},
|
|
44
|
+
{timeout: 10000},
|
|
45
|
+
);
|
|
42
46
|
|
|
43
47
|
test('Should handle redirect', async () => {
|
|
44
48
|
const result = await parseMedia({
|
package/src/test/stsd.test.ts
CHANGED
|
@@ -35,7 +35,7 @@ test('Should be able to parse a STSD audio box correctly', async () => {
|
|
|
35
35
|
2, 18, 16, 6, 128, 128, 128, 1, 2, 0, 0, 0, 8, 0, 0, 0, 0,
|
|
36
36
|
]);
|
|
37
37
|
|
|
38
|
-
const iterator = getArrayBufferIterator(buffer);
|
|
38
|
+
const iterator = getArrayBufferIterator(buffer, null);
|
|
39
39
|
iterator.discard(8);
|
|
40
40
|
|
|
41
41
|
const parsed = await parseStsd({
|
|
@@ -49,7 +49,9 @@ test('Should be able to parse a STSD audio box correctly', async () => {
|
|
|
49
49
|
parserState: makeParserState({
|
|
50
50
|
hasAudioCallbacks: false,
|
|
51
51
|
hasVideoCallbacks: false,
|
|
52
|
+
signal: undefined,
|
|
52
53
|
}),
|
|
54
|
+
nullifySamples: false,
|
|
53
55
|
},
|
|
54
56
|
});
|
|
55
57
|
|
|
@@ -205,7 +207,7 @@ test('Should be able to parse a STSD video box correctly', async () => {
|
|
|
205
207
|
]);
|
|
206
208
|
|
|
207
209
|
const parsed = await processSample({
|
|
208
|
-
iterator: getArrayBufferIterator(buffer),
|
|
210
|
+
iterator: getArrayBufferIterator(buffer, null),
|
|
209
211
|
options: {
|
|
210
212
|
canSkipVideoData: true,
|
|
211
213
|
onAudioTrack: null,
|
|
@@ -213,7 +215,9 @@ test('Should be able to parse a STSD video box correctly', async () => {
|
|
|
213
215
|
parserState: makeParserState({
|
|
214
216
|
hasAudioCallbacks: false,
|
|
215
217
|
hasVideoCallbacks: false,
|
|
218
|
+
signal: undefined,
|
|
216
219
|
}),
|
|
220
|
+
nullifySamples: false,
|
|
217
221
|
},
|
|
218
222
|
});
|
|
219
223
|
expect(parsed.sample).toEqual({
|
package/src/test/tkhd.test.ts
CHANGED
package/src/traversal.ts
CHANGED
|
@@ -11,20 +11,20 @@ import type {StszBox} from './boxes/iso-base-media/stsd/stsz';
|
|
|
11
11
|
import type {SttsBox} from './boxes/iso-base-media/stsd/stts';
|
|
12
12
|
import type {TkhdBox} from './boxes/iso-base-media/tkhd';
|
|
13
13
|
import type {TrakBox} from './boxes/iso-base-media/trak/trak';
|
|
14
|
-
import type {MainSegment} from './boxes/webm/segments/main';
|
|
15
|
-
import type {TimestampScaleSegment} from './boxes/webm/segments/timestamp-scale';
|
|
16
14
|
import type {
|
|
17
15
|
AudioSegment,
|
|
18
16
|
ClusterSegment,
|
|
19
|
-
|
|
17
|
+
CodecIdSegment,
|
|
20
18
|
DisplayHeightSegment,
|
|
21
19
|
DisplayWidthSegment,
|
|
22
20
|
HeightSegment,
|
|
23
|
-
|
|
21
|
+
MainSegment,
|
|
22
|
+
TimestampScaleSegment,
|
|
23
|
+
TrackEntry,
|
|
24
24
|
TrackTypeSegment,
|
|
25
25
|
VideoSegment,
|
|
26
26
|
WidthSegment,
|
|
27
|
-
} from './boxes/webm/segments/
|
|
27
|
+
} from './boxes/webm/segments/all-segments';
|
|
28
28
|
import type {AnySegment, RegularBox} from './parse-result';
|
|
29
29
|
|
|
30
30
|
export const getFtypBox = (segments: AnySegment[]): FtypBox | null => {
|
|
@@ -242,18 +242,16 @@ export const getStssBox = (trakBox: TrakBox): StssBox | null => {
|
|
|
242
242
|
export const getClusterSegment = (
|
|
243
243
|
segment: MainSegment,
|
|
244
244
|
): ClusterSegment | null => {
|
|
245
|
-
const clusterSegment = segment.
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
const clusterSegment = segment.value.find((b) => b.type === 'Cluster') as
|
|
246
|
+
| ClusterSegment
|
|
247
|
+
| undefined;
|
|
248
248
|
|
|
249
249
|
return clusterSegment ?? null;
|
|
250
250
|
};
|
|
251
251
|
|
|
252
252
|
export const getTracksSegment = (segment: MainSegment) => {
|
|
253
|
-
const tracksSegment = segment.
|
|
254
|
-
|
|
255
|
-
);
|
|
256
|
-
if (!tracksSegment || tracksSegment.type !== 'tracks-segment') {
|
|
253
|
+
const tracksSegment = segment.value.find((b) => b.type === 'Tracks');
|
|
254
|
+
if (!tracksSegment || tracksSegment.type !== 'Tracks') {
|
|
257
255
|
return null;
|
|
258
256
|
}
|
|
259
257
|
|
|
@@ -263,139 +261,120 @@ export const getTracksSegment = (segment: MainSegment) => {
|
|
|
263
261
|
export const getTimescaleSegment = (
|
|
264
262
|
segment: MainSegment,
|
|
265
263
|
): TimestampScaleSegment | null => {
|
|
266
|
-
const infoSegment = segment.
|
|
264
|
+
const infoSegment = segment.value.find((b) => b.type === 'Info');
|
|
267
265
|
|
|
268
|
-
if (!infoSegment || infoSegment.type !== '
|
|
266
|
+
if (!infoSegment || infoSegment.type !== 'Info') {
|
|
269
267
|
return null;
|
|
270
268
|
}
|
|
271
269
|
|
|
272
|
-
const timescale = infoSegment.
|
|
273
|
-
(b) => b.type === 'timestamp-scale-segment',
|
|
274
|
-
);
|
|
270
|
+
const timescale = infoSegment.value.find((b) => b.type === 'TimestampScale');
|
|
275
271
|
|
|
276
|
-
if (!timescale || timescale.type !== '
|
|
272
|
+
if (!timescale || timescale.type !== 'TimestampScale') {
|
|
277
273
|
return null;
|
|
278
274
|
}
|
|
279
275
|
|
|
280
|
-
return timescale;
|
|
276
|
+
return timescale as TimestampScaleSegment;
|
|
281
277
|
};
|
|
282
278
|
|
|
283
|
-
export const getVideoSegment = (
|
|
284
|
-
track
|
|
285
|
-
|
|
286
|
-
const videoSegment = track.children.find((b) => b.type === 'video-segment');
|
|
287
|
-
if (!videoSegment || videoSegment.type !== 'video-segment') {
|
|
279
|
+
export const getVideoSegment = (track: TrackEntry): VideoSegment | null => {
|
|
280
|
+
const videoSegment = track.value.find((b) => b.type === 'Video');
|
|
281
|
+
if (!videoSegment || videoSegment.type !== 'Video') {
|
|
288
282
|
return null;
|
|
289
283
|
}
|
|
290
284
|
|
|
291
285
|
return videoSegment ?? null;
|
|
292
286
|
};
|
|
293
287
|
|
|
294
|
-
export const getAudioSegment = (
|
|
295
|
-
track
|
|
296
|
-
|
|
297
|
-
const audioSegment = track.children.find((b) => b.type === 'audio-segment');
|
|
298
|
-
if (!audioSegment || audioSegment.type !== 'audio-segment') {
|
|
288
|
+
export const getAudioSegment = (track: TrackEntry): AudioSegment | null => {
|
|
289
|
+
const audioSegment = track.value.find((b) => b.type === 'Audio');
|
|
290
|
+
if (!audioSegment || audioSegment.type !== 'Audio') {
|
|
299
291
|
return null;
|
|
300
292
|
}
|
|
301
293
|
|
|
302
294
|
return audioSegment ?? null;
|
|
303
295
|
};
|
|
304
296
|
|
|
305
|
-
export const getSampleRate = (track:
|
|
297
|
+
export const getSampleRate = (track: TrackEntry): number | null => {
|
|
306
298
|
const audioSegment = getAudioSegment(track);
|
|
307
299
|
if (!audioSegment) {
|
|
308
300
|
return null;
|
|
309
301
|
}
|
|
310
302
|
|
|
311
|
-
const samplingFrequency = audioSegment.
|
|
312
|
-
(b) => b.type === '
|
|
303
|
+
const samplingFrequency = audioSegment.value.find(
|
|
304
|
+
(b) => b.type === 'SamplingFrequency',
|
|
313
305
|
);
|
|
314
306
|
|
|
315
|
-
if (
|
|
316
|
-
!samplingFrequency ||
|
|
317
|
-
samplingFrequency.type !== 'sampling-frequency-segment'
|
|
318
|
-
) {
|
|
307
|
+
if (!samplingFrequency || samplingFrequency.type !== 'SamplingFrequency') {
|
|
319
308
|
return null;
|
|
320
309
|
}
|
|
321
310
|
|
|
322
|
-
return samplingFrequency.
|
|
311
|
+
return samplingFrequency.value.value;
|
|
323
312
|
};
|
|
324
313
|
|
|
325
|
-
export const getNumberOfChannels = (track:
|
|
314
|
+
export const getNumberOfChannels = (track: TrackEntry): number => {
|
|
326
315
|
const audioSegment = getAudioSegment(track);
|
|
327
316
|
if (!audioSegment) {
|
|
328
317
|
throw new Error('Could not find audio segment');
|
|
329
318
|
}
|
|
330
319
|
|
|
331
|
-
const channels = audioSegment.
|
|
332
|
-
(b) => b.type === 'channels-segment',
|
|
333
|
-
);
|
|
320
|
+
const channels = audioSegment.value.find((b) => b.type === 'Channels');
|
|
334
321
|
|
|
335
|
-
if (!channels || channels.type !== '
|
|
322
|
+
if (!channels || channels.type !== 'Channels') {
|
|
336
323
|
return 1;
|
|
337
324
|
}
|
|
338
325
|
|
|
339
|
-
return channels.
|
|
326
|
+
return channels.value.value;
|
|
340
327
|
};
|
|
341
328
|
|
|
342
|
-
export const getBitDepth = (track:
|
|
329
|
+
export const getBitDepth = (track: TrackEntry): number | null => {
|
|
343
330
|
const audioSegment = getAudioSegment(track);
|
|
344
331
|
if (!audioSegment) {
|
|
345
332
|
return null;
|
|
346
333
|
}
|
|
347
334
|
|
|
348
|
-
const bitDepth = audioSegment.
|
|
349
|
-
(b) => b.type === 'bit-depth-segment',
|
|
350
|
-
);
|
|
335
|
+
const bitDepth = audioSegment.value.find((b) => b.type === 'BitDepth');
|
|
351
336
|
|
|
352
|
-
if (!bitDepth || bitDepth.type !== '
|
|
337
|
+
if (!bitDepth || bitDepth.type !== 'BitDepth') {
|
|
353
338
|
return null;
|
|
354
339
|
}
|
|
355
340
|
|
|
356
|
-
return bitDepth.
|
|
341
|
+
return bitDepth.value.value;
|
|
357
342
|
};
|
|
358
343
|
|
|
359
|
-
export const getPrivateData = (track:
|
|
360
|
-
const privateData = track.
|
|
361
|
-
(b) => b.type === 'codec-private-segment',
|
|
362
|
-
);
|
|
344
|
+
export const getPrivateData = (track: TrackEntry): Uint8Array | null => {
|
|
345
|
+
const privateData = track.value.find((b) => b.type === 'CodecPrivate');
|
|
363
346
|
|
|
364
|
-
if (!privateData || privateData.type !== '
|
|
347
|
+
if (!privateData || privateData.type !== 'CodecPrivate') {
|
|
365
348
|
return null;
|
|
366
349
|
}
|
|
367
350
|
|
|
368
|
-
return privateData.
|
|
351
|
+
return privateData.value;
|
|
369
352
|
};
|
|
370
353
|
|
|
371
|
-
export const getWidthSegment = (
|
|
372
|
-
track: TrackEntrySegment,
|
|
373
|
-
): WidthSegment | null => {
|
|
354
|
+
export const getWidthSegment = (track: TrackEntry): WidthSegment | null => {
|
|
374
355
|
const videoSegment = getVideoSegment(track);
|
|
375
356
|
if (!videoSegment) {
|
|
376
357
|
return null;
|
|
377
358
|
}
|
|
378
359
|
|
|
379
|
-
const width = videoSegment.
|
|
360
|
+
const width = videoSegment.value.find((b) => b.type === 'PixelWidth');
|
|
380
361
|
|
|
381
|
-
if (!width || width.type !== '
|
|
362
|
+
if (!width || width.type !== 'PixelWidth') {
|
|
382
363
|
return null;
|
|
383
364
|
}
|
|
384
365
|
|
|
385
366
|
return width;
|
|
386
367
|
};
|
|
387
368
|
|
|
388
|
-
export const getHeightSegment = (
|
|
389
|
-
track: TrackEntrySegment,
|
|
390
|
-
): HeightSegment | null => {
|
|
369
|
+
export const getHeightSegment = (track: TrackEntry): HeightSegment | null => {
|
|
391
370
|
const videoSegment = getVideoSegment(track);
|
|
392
371
|
if (!videoSegment) {
|
|
393
372
|
return null;
|
|
394
373
|
}
|
|
395
374
|
|
|
396
|
-
const height = videoSegment.
|
|
375
|
+
const height = videoSegment.value.find((b) => b.type === 'PixelHeight');
|
|
397
376
|
|
|
398
|
-
if (!height || height.type !== '
|
|
377
|
+
if (!height || height.type !== 'PixelHeight') {
|
|
399
378
|
return null;
|
|
400
379
|
}
|
|
401
380
|
|
|
@@ -403,18 +382,18 @@ export const getHeightSegment = (
|
|
|
403
382
|
};
|
|
404
383
|
|
|
405
384
|
export const getDisplayWidthSegment = (
|
|
406
|
-
track:
|
|
385
|
+
track: TrackEntry,
|
|
407
386
|
): DisplayWidthSegment | null => {
|
|
408
387
|
const videoSegment = getVideoSegment(track);
|
|
409
388
|
if (!videoSegment) {
|
|
410
389
|
return null;
|
|
411
390
|
}
|
|
412
391
|
|
|
413
|
-
const displayWidth = videoSegment.
|
|
414
|
-
(b) => b.type === '
|
|
392
|
+
const displayWidth = videoSegment.value.find(
|
|
393
|
+
(b) => b.type === 'DisplayWidth',
|
|
415
394
|
);
|
|
416
395
|
|
|
417
|
-
if (!displayWidth || displayWidth.type !== '
|
|
396
|
+
if (!displayWidth || displayWidth.type !== 'DisplayWidth') {
|
|
418
397
|
return null;
|
|
419
398
|
}
|
|
420
399
|
|
|
@@ -422,18 +401,18 @@ export const getDisplayWidthSegment = (
|
|
|
422
401
|
};
|
|
423
402
|
|
|
424
403
|
export const getDisplayHeightSegment = (
|
|
425
|
-
track:
|
|
404
|
+
track: TrackEntry,
|
|
426
405
|
): DisplayHeightSegment | null => {
|
|
427
406
|
const videoSegment = getVideoSegment(track);
|
|
428
407
|
if (!videoSegment) {
|
|
429
408
|
return null;
|
|
430
409
|
}
|
|
431
410
|
|
|
432
|
-
const displayHeight = videoSegment.
|
|
433
|
-
(b) => b.type === '
|
|
411
|
+
const displayHeight = videoSegment.value.find(
|
|
412
|
+
(b) => b.type === 'DisplayHeight',
|
|
434
413
|
);
|
|
435
414
|
|
|
436
|
-
if (!displayHeight || displayHeight.type !== '
|
|
415
|
+
if (!displayHeight || displayHeight.type !== 'DisplayHeight') {
|
|
437
416
|
return null;
|
|
438
417
|
}
|
|
439
418
|
|
|
@@ -441,30 +420,28 @@ export const getDisplayHeightSegment = (
|
|
|
441
420
|
};
|
|
442
421
|
|
|
443
422
|
export const getTrackTypeSegment = (
|
|
444
|
-
track:
|
|
423
|
+
track: TrackEntry,
|
|
445
424
|
): TrackTypeSegment | null => {
|
|
446
|
-
const trackType = track.
|
|
447
|
-
if (!trackType || trackType.type !== '
|
|
425
|
+
const trackType = track.value.find((b) => b.type === 'TrackType');
|
|
426
|
+
if (!trackType || trackType.type !== 'TrackType') {
|
|
448
427
|
return null;
|
|
449
428
|
}
|
|
450
429
|
|
|
451
430
|
return trackType;
|
|
452
431
|
};
|
|
453
432
|
|
|
454
|
-
export const getTrackId = (track:
|
|
455
|
-
const trackId = track.
|
|
456
|
-
if (!trackId || trackId.type !== '
|
|
433
|
+
export const getTrackId = (track: TrackEntry): number => {
|
|
434
|
+
const trackId = track.value.find((b) => b.type === 'TrackNumber');
|
|
435
|
+
if (!trackId || trackId.type !== 'TrackNumber') {
|
|
457
436
|
throw new Error('Expected track number segment');
|
|
458
437
|
}
|
|
459
438
|
|
|
460
|
-
return trackId.
|
|
439
|
+
return trackId.value.value;
|
|
461
440
|
};
|
|
462
441
|
|
|
463
|
-
export const getCodecSegment = (
|
|
464
|
-
track
|
|
465
|
-
|
|
466
|
-
const codec = track.children.find((b) => b.type === 'codec-segment');
|
|
467
|
-
if (!codec || codec.type !== 'codec-segment') {
|
|
442
|
+
export const getCodecSegment = (track: TrackEntry): CodecIdSegment | null => {
|
|
443
|
+
const codec = track.value.find((b) => b.type === 'CodecID');
|
|
444
|
+
if (!codec || codec.type !== 'CodecID') {
|
|
468
445
|
return null;
|
|
469
446
|
}
|
|
470
447
|
|