@remotion/media-parser 4.0.209 → 4.0.210
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/buffer.js +2 -0
- package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +1 -1
- package/dist/boxes/iso-base-media/make-track.js +14 -2
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -1
- package/dist/boxes/iso-base-media/mdat/mdat.js +8 -3
- package/dist/boxes/iso-base-media/moov/moov.d.ts +2 -1
- package/dist/boxes/iso-base-media/moov/moov.js +2 -1
- package/dist/boxes/iso-base-media/process-box.d.ts +6 -3
- package/dist/boxes/iso-base-media/process-box.js +20 -5
- package/dist/boxes/iso-base-media/stsd/avcc.d.ts +1 -1
- package/dist/boxes/iso-base-media/stsd/avcc.js +2 -2
- package/dist/boxes/iso-base-media/stsd/ctts.js +2 -5
- package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +1 -1
- package/dist/boxes/iso-base-media/stsd/hvcc.js +2 -2
- 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.d.ts +4 -2
- package/dist/boxes/iso-base-media/stsd/samples.js +69 -11
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +2 -1
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -1
- package/dist/boxes/iso-base-media/trak/trak.d.ts +2 -1
- package/dist/boxes/iso-base-media/trak/trak.js +2 -1
- package/dist/boxes/iso-base-media/traversal.d.ts +44 -0
- package/dist/boxes/iso-base-media/traversal.js +211 -0
- package/dist/boxes/webm/color.d.ts +4 -0
- package/dist/boxes/webm/color.js +120 -0
- package/dist/boxes/webm/description.js +1 -1
- package/dist/boxes/webm/get-ready-tracks.js +3 -3
- package/dist/boxes/webm/get-sample-from-block.js +1 -1
- package/dist/boxes/webm/get-track.js +16 -1
- package/dist/boxes/webm/make-track.d.ts +9 -0
- package/dist/boxes/webm/make-track.js +260 -0
- package/dist/boxes/webm/parse-ebml.js +2 -2
- package/dist/boxes/webm/segments/all-segments.d.ts +36 -3
- package/dist/boxes/webm/segments/all-segments.js +34 -6
- package/dist/boxes/webm/traversal.d.ts +26 -1
- package/dist/boxes/webm/traversal.js +214 -1
- package/dist/create/cluster-segment.js +0 -2
- package/dist/create/cluster.d.ts +10 -2
- package/dist/create/cluster.js +16 -10
- package/dist/create/create-media.d.ts +4 -2
- package/dist/create/create-media.js +76 -14
- package/dist/create/cues.d.ts +0 -0
- package/dist/create/cues.js +1 -0
- package/dist/create/make-duration-with-padding.d.ts +1 -1
- package/dist/create/make-duration-with-padding.js +3 -3
- package/dist/create/matroska-cues.d.ts +6 -0
- package/dist/create/matroska-cues.js +50 -0
- package/dist/create/matroska-info.js +1 -1
- package/dist/create/matroska-seek.d.ts +6 -0
- package/dist/create/matroska-seek.js +32 -0
- package/dist/create/matroska-segment.d.ts +1 -0
- package/dist/create/matroska-segment.js +3 -2
- package/dist/create/matroska-trackentry.d.ts +9 -14
- package/dist/create/matroska-trackentry.js +79 -94
- package/dist/emit-available-info.d.ts +12 -0
- package/dist/emit-available-info.js +133 -0
- package/dist/esm/buffer.mjs +57 -0
- package/dist/esm/from-fetch.mjs +72 -0
- package/dist/esm/from-node.mjs +48 -0
- package/dist/esm/from-web-file.mjs +48 -0
- package/dist/esm/index.mjs +6689 -0
- package/dist/esm/web-fs.mjs +67 -0
- package/dist/get-audio-codec.d.ts +5 -5
- package/dist/get-audio-codec.js +41 -57
- package/dist/get-container.d.ts +4 -0
- package/dist/get-container.js +26 -0
- package/dist/get-duration.js +1 -1
- package/dist/get-fps.js +1 -1
- package/dist/get-sample-aspect-ratio.d.ts +1 -1
- package/dist/get-sample-aspect-ratio.js +19 -19
- package/dist/get-tracks.d.ts +13 -0
- package/dist/get-tracks.js +8 -8
- package/dist/get-video-codec.d.ts +5 -2
- package/dist/get-video-codec.js +111 -21
- package/dist/has-all-info.d.ts +2 -2
- package/dist/has-all-info.js +23 -9
- package/dist/index.d.ts +3 -1
- package/dist/options.d.ts +97 -30
- package/dist/parse-media.js +43 -62
- package/dist/parse-video.d.ts +2 -1
- package/dist/parse-video.js +3 -1
- package/dist/parser-state.js +1 -2
- package/dist/readers/from-fetch.js +24 -4
- package/dist/readers/from-node.js +13 -3
- package/dist/readers/from-web-file.js +14 -2
- package/dist/readers/reader.d.ts +6 -1
- package/dist/samples-from-moof.js +1 -1
- package/dist/traversal.d.ts +0 -21
- package/dist/traversal.js +1 -158
- package/dist/truthy.d.ts +3 -0
- package/dist/truthy.js +7 -0
- package/dist/writers/buffer.d.ts +2 -0
- package/dist/writers/buffer.js +58 -0
- package/dist/writers/web-fs.d.ts +1 -0
- package/dist/writers/web-fs.js +42 -18
- package/dist/writers/writer.d.ts +4 -2
- package/fetch.js +2 -0
- package/node.js +2 -0
- package/package.json +43 -8
- package/web-file.js +2 -0
- package/web-fs.js +2 -0
- package/.eslintrc +0 -8
- package/input.webm +0 -0
- package/src/add-new-matroska-tracks.ts +0 -23
- package/src/boxes/iso-base-media/base-type.ts +0 -4
- package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
- package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
- package/src/boxes/iso-base-media/esds/esds.ts +0 -49
- package/src/boxes/iso-base-media/ftyp.ts +0 -39
- package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
- package/src/boxes/iso-base-media/make-track.ts +0 -116
- package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
- package/src/boxes/iso-base-media/mdhd.ts +0 -59
- package/src/boxes/iso-base-media/moov/moov.ts +0 -43
- package/src/boxes/iso-base-media/mvhd.ts +0 -114
- package/src/boxes/iso-base-media/process-box.ts +0 -748
- package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
- package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
- package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
- package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
- package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
- package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
- package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
- package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
- package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
- package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
- package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
- package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
- package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
- package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
- package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
- package/src/boxes/iso-base-media/tfdt.ts +0 -37
- package/src/boxes/iso-base-media/tfhd.ts +0 -66
- package/src/boxes/iso-base-media/tkhd.ts +0 -150
- package/src/boxes/iso-base-media/to-date.ts +0 -9
- package/src/boxes/iso-base-media/trak/trak.ts +0 -43
- package/src/boxes/iso-base-media/trun.ts +0 -74
- package/src/boxes/iso-base-media/void-box.ts +0 -4
- package/src/boxes/webm/allowed-partial-segments.ts +0 -1
- package/src/boxes/webm/av1-codec-private.ts +0 -113
- package/src/boxes/webm/description.ts +0 -104
- package/src/boxes/webm/ebml.ts +0 -98
- package/src/boxes/webm/get-ready-tracks.ts +0 -36
- package/src/boxes/webm/get-sample-from-block.ts +0 -125
- package/src/boxes/webm/get-track.ts +0 -257
- package/src/boxes/webm/make-header.ts +0 -253
- package/src/boxes/webm/parse-ebml.ts +0 -259
- package/src/boxes/webm/parse-webm-header.ts +0 -18
- package/src/boxes/webm/segments/all-segments.ts +0 -888
- package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
- package/src/boxes/webm/segments/parse-children.ts +0 -144
- package/src/boxes/webm/segments/track-entry.ts +0 -38
- package/src/boxes/webm/segments.ts +0 -147
- package/src/boxes/webm/traversal.ts +0 -45
- package/src/buffer-iterator.ts +0 -555
- package/src/create/cluster-segment.ts +0 -62
- package/src/create/cluster.ts +0 -64
- package/src/create/create-media.ts +0 -136
- package/src/create/make-duration-with-padding.ts +0 -15
- package/src/create/matroska-header.ts +0 -63
- package/src/create/matroska-info.ts +0 -30
- package/src/create/matroska-segment.ts +0 -10
- package/src/create/matroska-trackentry.ts +0 -325
- package/src/create/timescale.ts +0 -1
- package/src/get-audio-codec.ts +0 -270
- package/src/get-dimensions.ts +0 -47
- package/src/get-duration.ts +0 -103
- package/src/get-fps.ts +0 -113
- package/src/get-sample-aspect-ratio.ts +0 -204
- package/src/get-sample-positions.ts +0 -93
- package/src/get-tracks.ts +0 -147
- package/src/get-video-codec.ts +0 -117
- package/src/has-all-info.ts +0 -81
- package/src/index.ts +0 -18
- package/src/make-hvc1-codec-strings.ts +0 -55
- package/src/options.ts +0 -118
- package/src/parse-media.ts +0 -183
- package/src/parse-result.ts +0 -79
- package/src/parse-video.ts +0 -83
- package/src/parser-context.ts +0 -10
- package/src/parser-state.ts +0 -178
- package/src/readers/from-fetch.ts +0 -90
- package/src/readers/from-node.ts +0 -51
- package/src/readers/from-web-file.ts +0 -49
- package/src/readers/reader.ts +0 -15
- package/src/samples-from-moof.ts +0 -102
- package/src/test/aspect-ratio.test.ts +0 -42
- package/src/test/av1.test.ts +0 -108
- package/src/test/create-matroska.test.ts +0 -287
- package/src/test/duration.test.ts +0 -18
- package/src/test/keys.test.ts +0 -47
- package/src/test/matroska.test.ts +0 -463
- package/src/test/mvhd.test.ts +0 -94
- package/src/test/parse-esds.test.ts +0 -98
- package/src/test/parse-stco.test.ts +0 -61
- package/src/test/parse-stsc.test.ts +0 -104
- package/src/test/parse-stsz.test.ts +0 -57
- package/src/test/parse-stts.test.ts +0 -38
- package/src/test/parse-video.test.ts +0 -101
- package/src/test/parse-webm.test.ts +0 -17
- package/src/test/samples-from-moof.test.ts +0 -2496
- package/src/test/stream-local.test.ts +0 -743
- package/src/test/stream-remote.test.ts +0 -59
- package/src/test/stream-samples.test.ts +0 -181
- package/src/test/stsd.test.ts +0 -265
- package/src/test/tkhd.test.ts +0 -87
- package/src/traversal.ts +0 -528
- package/src/webcodec-sample-types.ts +0 -29
- package/src/writers/web-fs.ts +0 -50
- package/src/writers/writer.ts +0 -12
- package/tsconfig.json +0 -14
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
import type {BaseBox} from '../base-type';
|
|
3
|
-
|
|
4
|
-
export interface StcoBox extends BaseBox {
|
|
5
|
-
type: 'stco-box';
|
|
6
|
-
version: number;
|
|
7
|
-
flags: number[];
|
|
8
|
-
entryCount: number;
|
|
9
|
-
entries: (number | bigint)[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const parseStco = ({
|
|
13
|
-
iterator,
|
|
14
|
-
offset,
|
|
15
|
-
size,
|
|
16
|
-
mode64Bit,
|
|
17
|
-
}: {
|
|
18
|
-
iterator: BufferIterator;
|
|
19
|
-
offset: number;
|
|
20
|
-
size: number;
|
|
21
|
-
mode64Bit: boolean;
|
|
22
|
-
}): StcoBox => {
|
|
23
|
-
const version = iterator.getUint8();
|
|
24
|
-
if (version !== 0) {
|
|
25
|
-
throw new Error(`Unsupported STSD version ${version}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const flags = iterator.getSlice(3);
|
|
29
|
-
const entryCount = iterator.getUint32();
|
|
30
|
-
|
|
31
|
-
const entries: (number | bigint)[] = [];
|
|
32
|
-
for (let i = 0; i < entryCount; i++) {
|
|
33
|
-
const bytesRemaining = size - (iterator.counter.getOffset() - offset);
|
|
34
|
-
if (bytesRemaining < 4) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
entries.push(mode64Bit ? iterator.getUint64() : iterator.getUint32());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
iterator.discard(size - (iterator.counter.getOffset() - offset));
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
type: 'stco-box',
|
|
45
|
-
boxSize: size,
|
|
46
|
-
offset,
|
|
47
|
-
version,
|
|
48
|
-
flags: [...flags],
|
|
49
|
-
entries,
|
|
50
|
-
entryCount,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
import type {BaseBox} from '../base-type';
|
|
3
|
-
|
|
4
|
-
type StscEntry = {
|
|
5
|
-
firstChunk: number;
|
|
6
|
-
samplesPerChunk: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export interface StscBox extends BaseBox {
|
|
10
|
-
type: 'stsc-box';
|
|
11
|
-
version: number;
|
|
12
|
-
flags: number[];
|
|
13
|
-
entryCount: number;
|
|
14
|
-
entries: StscEntry[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const parseStsc = ({
|
|
18
|
-
iterator,
|
|
19
|
-
offset,
|
|
20
|
-
size,
|
|
21
|
-
}: {
|
|
22
|
-
iterator: BufferIterator;
|
|
23
|
-
offset: number;
|
|
24
|
-
size: number;
|
|
25
|
-
}): StscBox => {
|
|
26
|
-
const version = iterator.getUint8();
|
|
27
|
-
if (version !== 0) {
|
|
28
|
-
throw new Error(`Unsupported STSD version ${version}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const flags = iterator.getSlice(3);
|
|
32
|
-
const entryCount = iterator.getUint32();
|
|
33
|
-
|
|
34
|
-
const entries: StscEntry[] = [];
|
|
35
|
-
|
|
36
|
-
for (let i = 0; i < entryCount; i++) {
|
|
37
|
-
const firstChunk = iterator.getUint32();
|
|
38
|
-
const samplesPerChunk = iterator.getUint32();
|
|
39
|
-
const sampleDescriptionIndex = iterator.getUint32();
|
|
40
|
-
if (sampleDescriptionIndex !== 1) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Expected sampleDescriptionIndex to be 1, but got ${sampleDescriptionIndex}`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
entries.push({
|
|
47
|
-
firstChunk,
|
|
48
|
-
samplesPerChunk,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
type: 'stsc-box',
|
|
54
|
-
boxSize: size,
|
|
55
|
-
offset,
|
|
56
|
-
version,
|
|
57
|
-
flags: [...flags],
|
|
58
|
-
entryCount,
|
|
59
|
-
entries,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
import type {ParserContext} from '../../../parser-context';
|
|
3
|
-
import type {BaseBox} from '../base-type';
|
|
4
|
-
import type {Sample} from './samples';
|
|
5
|
-
import {parseSamples} from './samples';
|
|
6
|
-
|
|
7
|
-
export interface StsdBox extends BaseBox {
|
|
8
|
-
type: 'stsd-box';
|
|
9
|
-
numberOfEntries: number;
|
|
10
|
-
samples: Sample[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const parseStsd = async ({
|
|
14
|
-
iterator,
|
|
15
|
-
offset,
|
|
16
|
-
size,
|
|
17
|
-
options,
|
|
18
|
-
}: {
|
|
19
|
-
iterator: BufferIterator;
|
|
20
|
-
offset: number;
|
|
21
|
-
size: number;
|
|
22
|
-
options: ParserContext;
|
|
23
|
-
}): Promise<StsdBox> => {
|
|
24
|
-
const version = iterator.getUint8();
|
|
25
|
-
if (version !== 0) {
|
|
26
|
-
throw new Error(`Unsupported STSD version ${version}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// flags, we discard them
|
|
30
|
-
iterator.discard(3);
|
|
31
|
-
|
|
32
|
-
const numberOfEntries = iterator.getUint32();
|
|
33
|
-
|
|
34
|
-
const bytesRemainingInBox = size - (iterator.counter.getOffset() - offset);
|
|
35
|
-
|
|
36
|
-
const boxes = await parseSamples({
|
|
37
|
-
iterator,
|
|
38
|
-
maxBytes: bytesRemainingInBox,
|
|
39
|
-
options,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (boxes.length !== numberOfEntries) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Expected ${numberOfEntries} sample descriptions, got ${boxes.length}`,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
type: 'stsd-box',
|
|
50
|
-
boxSize: size,
|
|
51
|
-
offset,
|
|
52
|
-
numberOfEntries,
|
|
53
|
-
samples: boxes,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
import type {BaseBox} from '../base-type';
|
|
3
|
-
|
|
4
|
-
export interface StssBox extends BaseBox {
|
|
5
|
-
type: 'stss-box';
|
|
6
|
-
version: number;
|
|
7
|
-
flags: number[];
|
|
8
|
-
sampleNumber: number[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const parseStss = ({
|
|
12
|
-
iterator,
|
|
13
|
-
offset,
|
|
14
|
-
boxSize,
|
|
15
|
-
}: {
|
|
16
|
-
iterator: BufferIterator;
|
|
17
|
-
offset: number;
|
|
18
|
-
boxSize: number;
|
|
19
|
-
}): StssBox => {
|
|
20
|
-
const version = iterator.getUint8();
|
|
21
|
-
if (version !== 0) {
|
|
22
|
-
throw new Error(`Unsupported STSS version ${version}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const flags = iterator.getSlice(3);
|
|
26
|
-
const sampleCount = iterator.getUint32();
|
|
27
|
-
|
|
28
|
-
const sampleNumber: number[] = [];
|
|
29
|
-
for (let i = 0; i < sampleCount; i++) {
|
|
30
|
-
sampleNumber.push(iterator.getUint32());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - offset);
|
|
34
|
-
|
|
35
|
-
if (bytesRemainingInBox > 0) {
|
|
36
|
-
throw new Error(`Unexpected bytes remaining in box stss`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
type: 'stss-box',
|
|
41
|
-
version,
|
|
42
|
-
flags: [...flags],
|
|
43
|
-
sampleNumber,
|
|
44
|
-
boxSize,
|
|
45
|
-
offset,
|
|
46
|
-
};
|
|
47
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
import type {BaseBox} from '../base-type';
|
|
3
|
-
|
|
4
|
-
type Discriminated =
|
|
5
|
-
| {
|
|
6
|
-
countType: 'fixed';
|
|
7
|
-
sampleSize: number;
|
|
8
|
-
}
|
|
9
|
-
| {
|
|
10
|
-
countType: 'variable';
|
|
11
|
-
entries: number[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type StszBox = BaseBox & {
|
|
15
|
-
type: 'stsz-box';
|
|
16
|
-
version: number;
|
|
17
|
-
flags: number[];
|
|
18
|
-
sampleCount: number;
|
|
19
|
-
} & Discriminated;
|
|
20
|
-
|
|
21
|
-
export const parseStsz = ({
|
|
22
|
-
iterator,
|
|
23
|
-
offset,
|
|
24
|
-
size,
|
|
25
|
-
}: {
|
|
26
|
-
iterator: BufferIterator;
|
|
27
|
-
offset: number;
|
|
28
|
-
size: number;
|
|
29
|
-
}): StszBox => {
|
|
30
|
-
const version = iterator.getUint8();
|
|
31
|
-
if (version !== 0) {
|
|
32
|
-
throw new Error(`Unsupported STSD version ${version}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const flags = iterator.getSlice(3);
|
|
36
|
-
|
|
37
|
-
const sampleSize = iterator.getUint32();
|
|
38
|
-
const sampleCount = iterator.getUint32();
|
|
39
|
-
|
|
40
|
-
if (sampleSize !== 0) {
|
|
41
|
-
return {
|
|
42
|
-
type: 'stsz-box',
|
|
43
|
-
boxSize: size,
|
|
44
|
-
offset,
|
|
45
|
-
version,
|
|
46
|
-
flags: [...flags],
|
|
47
|
-
sampleCount,
|
|
48
|
-
countType: 'fixed',
|
|
49
|
-
sampleSize,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const samples: number[] = [];
|
|
54
|
-
for (let i = 0; i < sampleCount; i++) {
|
|
55
|
-
const bytesRemaining = size - (iterator.counter.getOffset() - offset);
|
|
56
|
-
if (bytesRemaining < 4) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
samples.push(iterator.getUint32());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
iterator.discard(size - (iterator.counter.getOffset() - offset));
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
type: 'stsz-box',
|
|
67
|
-
boxSize: size,
|
|
68
|
-
offset,
|
|
69
|
-
version,
|
|
70
|
-
flags: [...flags],
|
|
71
|
-
sampleCount,
|
|
72
|
-
countType: 'variable',
|
|
73
|
-
entries: samples,
|
|
74
|
-
};
|
|
75
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
|
|
3
|
-
export interface SttsBox {
|
|
4
|
-
type: 'stts-box';
|
|
5
|
-
sampleDistribution: SampleDistribution[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
type SampleDistribution = {
|
|
9
|
-
sampleCount: number;
|
|
10
|
-
sampleDelta: number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const parseStts = ({
|
|
14
|
-
data,
|
|
15
|
-
size,
|
|
16
|
-
fileOffset,
|
|
17
|
-
}: {
|
|
18
|
-
data: BufferIterator;
|
|
19
|
-
size: number;
|
|
20
|
-
fileOffset: number;
|
|
21
|
-
}): SttsBox => {
|
|
22
|
-
const initialOffset = data.counter.getOffset();
|
|
23
|
-
const initialCounter = initialOffset - fileOffset;
|
|
24
|
-
|
|
25
|
-
const version = data.getUint8();
|
|
26
|
-
if (version !== 0) {
|
|
27
|
-
throw new Error(`Unsupported STTS version ${version}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// flags, we discard them
|
|
31
|
-
data.discard(3);
|
|
32
|
-
|
|
33
|
-
// entry count
|
|
34
|
-
const entryCount = data.getUint32();
|
|
35
|
-
|
|
36
|
-
const sampleDistributions: SampleDistribution[] = [];
|
|
37
|
-
|
|
38
|
-
// entries
|
|
39
|
-
for (let i = 0; i < entryCount; i++) {
|
|
40
|
-
const sampleCount = data.getUint32();
|
|
41
|
-
const sampleDelta = data.getUint32();
|
|
42
|
-
|
|
43
|
-
const sampleDistribution: SampleDistribution = {
|
|
44
|
-
sampleCount,
|
|
45
|
-
sampleDelta,
|
|
46
|
-
};
|
|
47
|
-
sampleDistributions.push(sampleDistribution);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const bytesUsed = data.counter.getOffset() - initialOffset + initialCounter;
|
|
51
|
-
|
|
52
|
-
if (bytesUsed !== size) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Expected stts box to be ${size} bytes, but was ${bytesUsed} bytes`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
type: 'stts-box',
|
|
60
|
-
sampleDistribution: sampleDistributions,
|
|
61
|
-
};
|
|
62
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../buffer-iterator';
|
|
2
|
-
|
|
3
|
-
export interface TfdtBox {
|
|
4
|
-
type: 'tfdt-box';
|
|
5
|
-
version: number;
|
|
6
|
-
baseMediaDecodeTime: number;
|
|
7
|
-
offset: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const parseTfdt = ({
|
|
11
|
-
iterator,
|
|
12
|
-
size,
|
|
13
|
-
offset,
|
|
14
|
-
}: {
|
|
15
|
-
iterator: BufferIterator;
|
|
16
|
-
size: number;
|
|
17
|
-
offset: number;
|
|
18
|
-
}): TfdtBox => {
|
|
19
|
-
const version = iterator.getUint8();
|
|
20
|
-
iterator.discard(3);
|
|
21
|
-
// Flags, discard them
|
|
22
|
-
const num =
|
|
23
|
-
version === 0 ? iterator.getUint32() : Number(iterator.getUint64());
|
|
24
|
-
|
|
25
|
-
const bytesRemaining = size - (iterator.counter.getOffset() - offset);
|
|
26
|
-
|
|
27
|
-
if (bytesRemaining !== 0) {
|
|
28
|
-
throw new Error('expected 0 bytes ' + bytesRemaining);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
type: 'tfdt-box',
|
|
33
|
-
version,
|
|
34
|
-
baseMediaDecodeTime: num,
|
|
35
|
-
offset,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../buffer-iterator';
|
|
2
|
-
|
|
3
|
-
export interface TfhdBox {
|
|
4
|
-
type: 'tfhd-box';
|
|
5
|
-
version: number;
|
|
6
|
-
trackId: number;
|
|
7
|
-
baseDataOffset: number;
|
|
8
|
-
baseSampleDescriptionIndex: number;
|
|
9
|
-
defaultSampleDuration: number;
|
|
10
|
-
defaultSampleSize: number;
|
|
11
|
-
defaultSampleFlags: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const getTfhd = ({
|
|
15
|
-
iterator,
|
|
16
|
-
offset,
|
|
17
|
-
size,
|
|
18
|
-
}: {
|
|
19
|
-
iterator: BufferIterator;
|
|
20
|
-
size: number;
|
|
21
|
-
offset: number;
|
|
22
|
-
}): TfhdBox => {
|
|
23
|
-
const version = iterator.getUint8();
|
|
24
|
-
const flags = iterator.getUint24();
|
|
25
|
-
|
|
26
|
-
const trackId = iterator.getUint32();
|
|
27
|
-
|
|
28
|
-
const baseDataOffsetPresent = flags & 0x01;
|
|
29
|
-
const baseDataOffset = baseDataOffsetPresent
|
|
30
|
-
? Number(iterator.getUint64())
|
|
31
|
-
: 0;
|
|
32
|
-
|
|
33
|
-
const baseSampleDescriptionIndexPresent = flags & 0x02;
|
|
34
|
-
const baseSampleDescriptionIndex = baseSampleDescriptionIndexPresent
|
|
35
|
-
? iterator.getUint32()
|
|
36
|
-
: 0;
|
|
37
|
-
|
|
38
|
-
const defaultSampleDurationPresent = flags & 0x08;
|
|
39
|
-
const defaultSampleDuration = defaultSampleDurationPresent
|
|
40
|
-
? iterator.getUint32()
|
|
41
|
-
: 0;
|
|
42
|
-
|
|
43
|
-
const defaultSampleSizePresent = flags & 0x10;
|
|
44
|
-
const defaultSampleSize = defaultSampleSizePresent ? iterator.getUint32() : 0;
|
|
45
|
-
|
|
46
|
-
const defaultSampleFlagsPresent = flags & 0x20;
|
|
47
|
-
const defaultSampleFlags = defaultSampleFlagsPresent
|
|
48
|
-
? iterator.getUint32()
|
|
49
|
-
: 0;
|
|
50
|
-
|
|
51
|
-
const bytesRemaining = size - (iterator.counter.getOffset() - offset);
|
|
52
|
-
if (bytesRemaining !== 0) {
|
|
53
|
-
throw new Error('expected 0 bytes ' + bytesRemaining);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
type: 'tfhd-box',
|
|
58
|
-
version,
|
|
59
|
-
trackId,
|
|
60
|
-
baseDataOffset,
|
|
61
|
-
baseSampleDescriptionIndex,
|
|
62
|
-
defaultSampleDuration,
|
|
63
|
-
defaultSampleSize,
|
|
64
|
-
defaultSampleFlags,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../buffer-iterator';
|
|
2
|
-
import type {BaseBox} from './base-type';
|
|
3
|
-
import type {ThreeDMatrix} from './mvhd';
|
|
4
|
-
import {toUnixTimestamp} from './to-date';
|
|
5
|
-
|
|
6
|
-
export interface TkhdBox extends BaseBox {
|
|
7
|
-
type: 'tkhd-box';
|
|
8
|
-
alternateGroup: number;
|
|
9
|
-
creationTime: number | null;
|
|
10
|
-
duration: number;
|
|
11
|
-
modificationTime: number | null;
|
|
12
|
-
trackId: number;
|
|
13
|
-
version: number;
|
|
14
|
-
layer: number;
|
|
15
|
-
volume: number;
|
|
16
|
-
matrix: ThreeDMatrix;
|
|
17
|
-
width: number;
|
|
18
|
-
height: number;
|
|
19
|
-
unrotatedWidth: number;
|
|
20
|
-
unrotatedHeight: number;
|
|
21
|
-
rotation: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type Matrix2x2 = readonly [number, number, number, number];
|
|
25
|
-
|
|
26
|
-
function getRotationAngleFromMatrix(matrix: Matrix2x2): number {
|
|
27
|
-
// Extract elements from the matrix
|
|
28
|
-
const [a, b, c, d] = matrix;
|
|
29
|
-
if (a === 0 && b === 0 && c === 0 && d === 0) {
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Check if the matrix is a valid rotation matrix
|
|
34
|
-
if (Math.round(a * a + b * b) !== 1 || Math.round(c * c + d * d) !== 1) {
|
|
35
|
-
throw new Error('The provided matrix is not a valid rotation matrix.');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Calculate the angle using the atan2 function
|
|
39
|
-
const angleRadians = Math.atan2(c, a); // atan2(sin(θ), cos(θ))
|
|
40
|
-
const angleDegrees = angleRadians * (180 / Math.PI); // Convert radians to degrees
|
|
41
|
-
|
|
42
|
-
return angleDegrees;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const applyRotation = ({
|
|
46
|
-
matrix,
|
|
47
|
-
width,
|
|
48
|
-
height,
|
|
49
|
-
}: {
|
|
50
|
-
matrix: Matrix2x2;
|
|
51
|
-
width: number;
|
|
52
|
-
height: number;
|
|
53
|
-
}) => {
|
|
54
|
-
const newWidth = matrix[0] * width + matrix[1] * height; // 0*3840 + 1*2160
|
|
55
|
-
const newHeight = matrix[2] * width + matrix[3] * height; // -1*3840 + 0*2160
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
width: Math.abs(newWidth),
|
|
59
|
-
height: Math.abs(newHeight),
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const parseTkhd = ({
|
|
64
|
-
iterator,
|
|
65
|
-
offset,
|
|
66
|
-
size,
|
|
67
|
-
}: {
|
|
68
|
-
iterator: BufferIterator;
|
|
69
|
-
offset: number;
|
|
70
|
-
size: number;
|
|
71
|
-
}): TkhdBox => {
|
|
72
|
-
const version = iterator.getUint8();
|
|
73
|
-
|
|
74
|
-
// Flags, we discard them
|
|
75
|
-
iterator.discard(3);
|
|
76
|
-
|
|
77
|
-
const creationTime =
|
|
78
|
-
version === 1 ? iterator.getUint64() : iterator.getUint32();
|
|
79
|
-
|
|
80
|
-
const modificationTime =
|
|
81
|
-
version === 1 ? iterator.getUint64() : iterator.getUint32();
|
|
82
|
-
|
|
83
|
-
const trackId = iterator.getUint32();
|
|
84
|
-
|
|
85
|
-
// reserved
|
|
86
|
-
iterator.discard(4);
|
|
87
|
-
|
|
88
|
-
const duration = version === 1 ? iterator.getUint64() : iterator.getUint32();
|
|
89
|
-
|
|
90
|
-
// reserved 2
|
|
91
|
-
iterator.discard(4);
|
|
92
|
-
|
|
93
|
-
// reserved 3
|
|
94
|
-
iterator.discard(4);
|
|
95
|
-
|
|
96
|
-
const layer = iterator.getUint16();
|
|
97
|
-
|
|
98
|
-
const alternateGroup = iterator.getUint16();
|
|
99
|
-
|
|
100
|
-
const volume = iterator.getUint16();
|
|
101
|
-
|
|
102
|
-
// reserved 4
|
|
103
|
-
iterator.discard(2);
|
|
104
|
-
|
|
105
|
-
const matrix = [
|
|
106
|
-
iterator.getFixedPointSigned1616Number(),
|
|
107
|
-
iterator.getFixedPointSigned1616Number(),
|
|
108
|
-
iterator.getFixedPointSigned230Number(),
|
|
109
|
-
iterator.getFixedPointSigned1616Number(),
|
|
110
|
-
iterator.getFixedPointSigned1616Number(),
|
|
111
|
-
iterator.getFixedPointSigned230Number(),
|
|
112
|
-
iterator.getFixedPointSigned1616Number(),
|
|
113
|
-
iterator.getFixedPointSigned1616Number(),
|
|
114
|
-
iterator.getFixedPointSigned230Number(),
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
const rotationMatrix = [matrix[0], matrix[1], matrix[3], matrix[4]] as const;
|
|
118
|
-
|
|
119
|
-
const widthWithoutRotationApplied =
|
|
120
|
-
iterator.getFixedPointUnsigned1616Number();
|
|
121
|
-
const heightWithoutRotationApplied = iterator.getFixedPointSigned1616Number();
|
|
122
|
-
|
|
123
|
-
const {width, height} = applyRotation({
|
|
124
|
-
matrix: rotationMatrix,
|
|
125
|
-
width: widthWithoutRotationApplied,
|
|
126
|
-
height: heightWithoutRotationApplied,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const rotation = getRotationAngleFromMatrix(rotationMatrix);
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
offset,
|
|
133
|
-
boxSize: size,
|
|
134
|
-
type: 'tkhd-box',
|
|
135
|
-
creationTime: toUnixTimestamp(Number(creationTime)),
|
|
136
|
-
modificationTime: toUnixTimestamp(Number(modificationTime)),
|
|
137
|
-
trackId,
|
|
138
|
-
duration: Number(duration),
|
|
139
|
-
layer,
|
|
140
|
-
alternateGroup,
|
|
141
|
-
volume,
|
|
142
|
-
matrix: matrix as ThreeDMatrix,
|
|
143
|
-
width,
|
|
144
|
-
height,
|
|
145
|
-
version,
|
|
146
|
-
rotation,
|
|
147
|
-
unrotatedWidth: widthWithoutRotationApplied,
|
|
148
|
-
unrotatedHeight: heightWithoutRotationApplied,
|
|
149
|
-
};
|
|
150
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from '../../../buffer-iterator';
|
|
2
|
-
import type {AnySegment} from '../../../parse-result';
|
|
3
|
-
import type {ParserContext} from '../../../parser-context';
|
|
4
|
-
import type {BaseBox} from '../base-type';
|
|
5
|
-
import {parseBoxes} from '../process-box';
|
|
6
|
-
|
|
7
|
-
export interface TrakBox extends BaseBox {
|
|
8
|
-
type: 'trak-box';
|
|
9
|
-
children: AnySegment[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const parseTrak = async ({
|
|
13
|
-
data,
|
|
14
|
-
size,
|
|
15
|
-
offsetAtStart,
|
|
16
|
-
options,
|
|
17
|
-
}: {
|
|
18
|
-
data: BufferIterator;
|
|
19
|
-
size: number;
|
|
20
|
-
offsetAtStart: number;
|
|
21
|
-
options: ParserContext;
|
|
22
|
-
}): Promise<TrakBox> => {
|
|
23
|
-
const children = await parseBoxes({
|
|
24
|
-
iterator: data,
|
|
25
|
-
maxBytes: size - (data.counter.getOffset() - offsetAtStart),
|
|
26
|
-
allowIncompleteBoxes: false,
|
|
27
|
-
initialBoxes: [],
|
|
28
|
-
options,
|
|
29
|
-
continueMdat: false,
|
|
30
|
-
littleEndian: false,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (children.status === 'incomplete') {
|
|
34
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
offset: offsetAtStart,
|
|
39
|
-
boxSize: size,
|
|
40
|
-
type: 'trak-box',
|
|
41
|
-
children: children.segments,
|
|
42
|
-
};
|
|
43
|
-
};
|