@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,204 +0,0 @@
|
|
|
1
|
-
import type {Av1CBox} from './boxes/iso-base-media/stsd/av1c';
|
|
2
|
-
import type {AvccBox} from './boxes/iso-base-media/stsd/avcc';
|
|
3
|
-
import type {ColorParameterBox} from './boxes/iso-base-media/stsd/colr';
|
|
4
|
-
import type {HvccBox} from './boxes/iso-base-media/stsd/hvcc';
|
|
5
|
-
import type {PaspBox} from './boxes/iso-base-media/stsd/pasp';
|
|
6
|
-
import type {VideoSample} from './boxes/iso-base-media/stsd/samples';
|
|
7
|
-
import type {TkhdBox} from './boxes/iso-base-media/tkhd';
|
|
8
|
-
import type {TrakBox} from './boxes/iso-base-media/trak/trak';
|
|
9
|
-
import type {Dimensions} from './get-dimensions';
|
|
10
|
-
import {getStsdBox} from './traversal';
|
|
11
|
-
|
|
12
|
-
type AspectRatio = {
|
|
13
|
-
numerator: number;
|
|
14
|
-
denominator: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const getVideoSample = (trakBox: TrakBox): VideoSample | null => {
|
|
18
|
-
const stsdBox = getStsdBox(trakBox);
|
|
19
|
-
|
|
20
|
-
if (!stsdBox) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const videoSample = stsdBox.samples.find((s) => s.type === 'video');
|
|
25
|
-
if (!videoSample || videoSample.type !== 'video') {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return videoSample;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const getAvccBox = (trakBox: TrakBox): AvccBox | null => {
|
|
33
|
-
const videoSample = getVideoSample(trakBox);
|
|
34
|
-
if (!videoSample) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const avccBox = videoSample.descriptors.find((c) => c.type === 'avcc-box');
|
|
39
|
-
|
|
40
|
-
if (!avccBox || avccBox.type !== 'avcc-box') {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return avccBox;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const getAv1CBox = (trakBox: TrakBox): Av1CBox | null => {
|
|
48
|
-
const videoSample = getVideoSample(trakBox);
|
|
49
|
-
if (!videoSample) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const av1cBox = videoSample.descriptors.find((c) => c.type === 'av1C-box');
|
|
54
|
-
|
|
55
|
-
if (!av1cBox || av1cBox.type !== 'av1C-box') {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return av1cBox;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const getPaspBox = (trakBox: TrakBox): PaspBox | null => {
|
|
63
|
-
const videoSample = getVideoSample(trakBox);
|
|
64
|
-
if (!videoSample) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const paspBox = videoSample.descriptors.find((c) => c.type === 'pasp-box');
|
|
69
|
-
|
|
70
|
-
if (!paspBox || paspBox.type !== 'pasp-box') {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return paspBox;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const getHvccBox = (trakBox: TrakBox): HvccBox | null => {
|
|
78
|
-
const videoSample = getVideoSample(trakBox);
|
|
79
|
-
if (!videoSample) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const hvccBox = videoSample.descriptors.find((c) => c.type === 'hvcc-box');
|
|
84
|
-
|
|
85
|
-
if (!hvccBox || hvccBox.type !== 'hvcc-box') {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return hvccBox;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const getSampleAspectRatio = (trakBox: TrakBox): AspectRatio => {
|
|
93
|
-
const paspBox = getPaspBox(trakBox);
|
|
94
|
-
if (!paspBox) {
|
|
95
|
-
return {
|
|
96
|
-
numerator: 1,
|
|
97
|
-
denominator: 1,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
numerator: paspBox.hSpacing,
|
|
103
|
-
denominator: paspBox.vSpacing,
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const getColrBox = (
|
|
108
|
-
videoSample: VideoSample,
|
|
109
|
-
): ColorParameterBox | null => {
|
|
110
|
-
const colrBox = videoSample.descriptors.find((c) => c.type === 'colr-box');
|
|
111
|
-
|
|
112
|
-
if (!colrBox || colrBox.type !== 'colr-box') {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return colrBox;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const applyTkhdBox = (
|
|
120
|
-
aspectRatioApplied: Dimensions,
|
|
121
|
-
tkhdBox: TkhdBox,
|
|
122
|
-
): {
|
|
123
|
-
displayAspectWidth: number;
|
|
124
|
-
displayAspectHeight: number;
|
|
125
|
-
width: number;
|
|
126
|
-
height: number;
|
|
127
|
-
rotation: number;
|
|
128
|
-
} => {
|
|
129
|
-
if (tkhdBox === null || tkhdBox.rotation === 0) {
|
|
130
|
-
return {
|
|
131
|
-
displayAspectWidth: aspectRatioApplied.width,
|
|
132
|
-
displayAspectHeight: aspectRatioApplied.height,
|
|
133
|
-
width: aspectRatioApplied.width,
|
|
134
|
-
height: aspectRatioApplied.height,
|
|
135
|
-
rotation: 0,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
width: tkhdBox.width,
|
|
141
|
-
height: tkhdBox.height,
|
|
142
|
-
rotation: tkhdBox.rotation,
|
|
143
|
-
displayAspectWidth: aspectRatioApplied.width,
|
|
144
|
-
displayAspectHeight: aspectRatioApplied.height,
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export const applyAspectRatios = ({
|
|
149
|
-
dimensions,
|
|
150
|
-
sampleAspectRatio,
|
|
151
|
-
displayAspectRatio,
|
|
152
|
-
}: {
|
|
153
|
-
dimensions: Dimensions;
|
|
154
|
-
sampleAspectRatio: AspectRatio;
|
|
155
|
-
displayAspectRatio: AspectRatio;
|
|
156
|
-
}): Dimensions => {
|
|
157
|
-
if (displayAspectRatio.numerator === 0) {
|
|
158
|
-
return dimensions;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (displayAspectRatio.denominator === 0) {
|
|
162
|
-
return dimensions;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const newWidth = Math.round(
|
|
166
|
-
(dimensions.width * sampleAspectRatio.numerator) /
|
|
167
|
-
sampleAspectRatio.denominator,
|
|
168
|
-
);
|
|
169
|
-
const newHeight = Math.floor(
|
|
170
|
-
newWidth / (displayAspectRatio.numerator / displayAspectRatio.denominator),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
width: Math.floor(newWidth),
|
|
175
|
-
height: newHeight,
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
function gcd(a: number, b: number): number {
|
|
180
|
-
return b === 0 ? a : gcd(b, a % b);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function reduceFraction(numerator: number, denominator: number) {
|
|
184
|
-
const greatestCommonDivisor = gcd(Math.abs(numerator), Math.abs(denominator));
|
|
185
|
-
return {
|
|
186
|
-
numerator: numerator / greatestCommonDivisor,
|
|
187
|
-
denominator: denominator / greatestCommonDivisor,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export const getDisplayAspectRatio = ({
|
|
192
|
-
sampleAspectRatio,
|
|
193
|
-
nativeDimensions,
|
|
194
|
-
}: {
|
|
195
|
-
sampleAspectRatio: AspectRatio;
|
|
196
|
-
nativeDimensions: Dimensions;
|
|
197
|
-
}): AspectRatio => {
|
|
198
|
-
const num = Math.round(nativeDimensions.width * sampleAspectRatio.numerator);
|
|
199
|
-
const den = Math.round(
|
|
200
|
-
nativeDimensions.height * sampleAspectRatio.denominator,
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
return reduceFraction(num, den);
|
|
204
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type {CttsBox} from './boxes/iso-base-media/stsd/ctts';
|
|
2
|
-
import type {StcoBox} from './boxes/iso-base-media/stsd/stco';
|
|
3
|
-
import type {StscBox} from './boxes/iso-base-media/stsd/stsc';
|
|
4
|
-
import type {StssBox} from './boxes/iso-base-media/stsd/stss';
|
|
5
|
-
import type {StszBox} from './boxes/iso-base-media/stsd/stsz';
|
|
6
|
-
import type {SttsBox} from './boxes/iso-base-media/stsd/stts';
|
|
7
|
-
|
|
8
|
-
export type SamplePosition = {
|
|
9
|
-
offset: number;
|
|
10
|
-
size: number;
|
|
11
|
-
isKeyframe: boolean;
|
|
12
|
-
dts: number;
|
|
13
|
-
cts: number;
|
|
14
|
-
duration: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const getSamplePositions = ({
|
|
18
|
-
stcoBox,
|
|
19
|
-
stszBox,
|
|
20
|
-
stscBox,
|
|
21
|
-
stssBox,
|
|
22
|
-
sttsBox,
|
|
23
|
-
cttsBox,
|
|
24
|
-
}: {
|
|
25
|
-
stcoBox: StcoBox;
|
|
26
|
-
stszBox: StszBox;
|
|
27
|
-
stscBox: StscBox;
|
|
28
|
-
stssBox: StssBox | null;
|
|
29
|
-
sttsBox: SttsBox;
|
|
30
|
-
cttsBox: CttsBox | null;
|
|
31
|
-
}) => {
|
|
32
|
-
const sttsDeltas: number[] = [];
|
|
33
|
-
for (const distribution of sttsBox.sampleDistribution) {
|
|
34
|
-
for (let i = 0; i < distribution.sampleCount; i++) {
|
|
35
|
-
sttsDeltas.push(distribution.sampleDelta);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const cttsEntries: number[] = [];
|
|
40
|
-
for (const entry of cttsBox?.entries ?? [
|
|
41
|
-
{sampleCount: sttsDeltas.length, sampleOffset: 0},
|
|
42
|
-
]) {
|
|
43
|
-
for (let i = 0; i < entry.sampleCount; i++) {
|
|
44
|
-
cttsEntries.push(entry.sampleOffset);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let dts = 0;
|
|
49
|
-
|
|
50
|
-
const chunks = stcoBox.entries;
|
|
51
|
-
const samples: SamplePosition[] = [];
|
|
52
|
-
|
|
53
|
-
let samplesPerChunk = 1;
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
56
|
-
const hasEntry = stscBox.entries.find(
|
|
57
|
-
(entry) => entry.firstChunk === i + 1,
|
|
58
|
-
);
|
|
59
|
-
if (hasEntry) {
|
|
60
|
-
samplesPerChunk = hasEntry.samplesPerChunk;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let offsetInThisChunk = 0;
|
|
64
|
-
|
|
65
|
-
for (let j = 0; j < samplesPerChunk; j++) {
|
|
66
|
-
const size =
|
|
67
|
-
stszBox.countType === 'fixed'
|
|
68
|
-
? stszBox.sampleSize
|
|
69
|
-
: stszBox.entries[samples.length];
|
|
70
|
-
|
|
71
|
-
const isKeyframe = stssBox
|
|
72
|
-
? stssBox.sampleNumber.includes(samples.length + 1)
|
|
73
|
-
: true;
|
|
74
|
-
|
|
75
|
-
const delta = sttsDeltas[samples.length];
|
|
76
|
-
const ctsOffset = cttsEntries[samples.length];
|
|
77
|
-
const cts = dts + ctsOffset;
|
|
78
|
-
|
|
79
|
-
samples.push({
|
|
80
|
-
offset: Number(chunks[i]) + offsetInThisChunk,
|
|
81
|
-
size,
|
|
82
|
-
isKeyframe,
|
|
83
|
-
dts,
|
|
84
|
-
cts,
|
|
85
|
-
duration: delta,
|
|
86
|
-
});
|
|
87
|
-
dts += delta;
|
|
88
|
-
offsetInThisChunk += size;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return samples;
|
|
93
|
-
};
|
package/src/get-tracks.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import {makeBaseMediaTrack} from './boxes/iso-base-media/make-track';
|
|
2
|
-
import type {MoovBox} from './boxes/iso-base-media/moov/moov';
|
|
3
|
-
import type {TrakBox} from './boxes/iso-base-media/trak/trak';
|
|
4
|
-
import {getTracksFromMatroska} from './boxes/webm/get-ready-tracks';
|
|
5
|
-
import {getMainSegment} from './boxes/webm/traversal';
|
|
6
|
-
import type {AnySegment} from './parse-result';
|
|
7
|
-
import type {ParserState} from './parser-state';
|
|
8
|
-
import {getMoovBox, getMvhdBox, getTracksSegment, getTraks} from './traversal';
|
|
9
|
-
|
|
10
|
-
type SampleAspectRatio = {
|
|
11
|
-
numerator: number;
|
|
12
|
-
denominator: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type VideoTrack = {
|
|
16
|
-
type: 'video';
|
|
17
|
-
trackId: number;
|
|
18
|
-
description: Uint8Array | undefined;
|
|
19
|
-
timescale: number;
|
|
20
|
-
codec: string;
|
|
21
|
-
sampleAspectRatio: SampleAspectRatio;
|
|
22
|
-
width: number;
|
|
23
|
-
height: number;
|
|
24
|
-
displayAspectWidth: number;
|
|
25
|
-
displayAspectHeight: number;
|
|
26
|
-
codedWidth: number;
|
|
27
|
-
codedHeight: number;
|
|
28
|
-
rotation: number;
|
|
29
|
-
trakBox: TrakBox | null;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type AudioTrack = {
|
|
33
|
-
type: 'audio';
|
|
34
|
-
trackId: number;
|
|
35
|
-
timescale: number;
|
|
36
|
-
codec: string;
|
|
37
|
-
numberOfChannels: number;
|
|
38
|
-
sampleRate: number;
|
|
39
|
-
description: Uint8Array | undefined;
|
|
40
|
-
trakBox: TrakBox | null;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type OtherTrack = {
|
|
44
|
-
type: 'other';
|
|
45
|
-
trackId: number;
|
|
46
|
-
timescale: number;
|
|
47
|
-
trakBox: TrakBox | null;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type Track = VideoTrack | AudioTrack | OtherTrack;
|
|
51
|
-
|
|
52
|
-
export const getNumberOfTracks = (moovBox: MoovBox): number => {
|
|
53
|
-
const mvHdBox = getMvhdBox(moovBox);
|
|
54
|
-
if (!mvHdBox) {
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return mvHdBox.nextTrackId - 1;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const hasTracks = (segments: AnySegment[]): boolean => {
|
|
62
|
-
const mainSegment = getMainSegment(segments);
|
|
63
|
-
|
|
64
|
-
if (mainSegment) {
|
|
65
|
-
return getTracksSegment(mainSegment) !== null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const moovBox = getMoovBox(segments);
|
|
69
|
-
|
|
70
|
-
if (!moovBox) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const numberOfTracks = getNumberOfTracks(moovBox);
|
|
75
|
-
const tracks = getTraks(moovBox);
|
|
76
|
-
|
|
77
|
-
return tracks.length === numberOfTracks;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const getTracks = (
|
|
81
|
-
segments: AnySegment[],
|
|
82
|
-
state: ParserState,
|
|
83
|
-
): {
|
|
84
|
-
videoTracks: VideoTrack[];
|
|
85
|
-
audioTracks: AudioTrack[];
|
|
86
|
-
otherTracks: OtherTrack[];
|
|
87
|
-
} => {
|
|
88
|
-
const videoTracks: VideoTrack[] = [];
|
|
89
|
-
const audioTracks: AudioTrack[] = [];
|
|
90
|
-
const otherTracks: OtherTrack[] = [];
|
|
91
|
-
|
|
92
|
-
const mainSegment = segments.find((s) => s.type === 'Segment');
|
|
93
|
-
if (mainSegment && mainSegment.type === 'Segment') {
|
|
94
|
-
const matroskaTracks = getTracksFromMatroska(
|
|
95
|
-
mainSegment,
|
|
96
|
-
state.getTimescale(),
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
for (const track of matroskaTracks) {
|
|
100
|
-
if (track.type === 'video') {
|
|
101
|
-
videoTracks.push(track);
|
|
102
|
-
} else if (track.type === 'audio') {
|
|
103
|
-
audioTracks.push(track);
|
|
104
|
-
} else if (track.type === 'other') {
|
|
105
|
-
otherTracks.push(track);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
videoTracks,
|
|
111
|
-
audioTracks,
|
|
112
|
-
otherTracks,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const moovBox = getMoovBox(segments);
|
|
117
|
-
if (!moovBox) {
|
|
118
|
-
return {
|
|
119
|
-
videoTracks,
|
|
120
|
-
audioTracks,
|
|
121
|
-
otherTracks,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const tracks = getTraks(moovBox);
|
|
126
|
-
|
|
127
|
-
for (const trakBox of tracks) {
|
|
128
|
-
const track = makeBaseMediaTrack(trakBox);
|
|
129
|
-
if (!track) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (track.type === 'video') {
|
|
134
|
-
videoTracks.push(track);
|
|
135
|
-
} else if (track.type === 'audio') {
|
|
136
|
-
audioTracks.push(track);
|
|
137
|
-
} else if (track.type === 'other') {
|
|
138
|
-
otherTracks.push(track);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
videoTracks,
|
|
144
|
-
audioTracks,
|
|
145
|
-
otherTracks,
|
|
146
|
-
};
|
|
147
|
-
};
|
package/src/get-video-codec.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-depth */
|
|
2
|
-
import type {TrakBox} from './boxes/iso-base-media/trak/trak';
|
|
3
|
-
import {parseAv1PrivateData} from './boxes/webm/av1-codec-private';
|
|
4
|
-
import {trakBoxContainsVideo} from './get-fps';
|
|
5
|
-
import {
|
|
6
|
-
getAv1CBox,
|
|
7
|
-
getAvccBox,
|
|
8
|
-
getColrBox,
|
|
9
|
-
getHvccBox,
|
|
10
|
-
getVideoSample,
|
|
11
|
-
} from './get-sample-aspect-ratio';
|
|
12
|
-
import type {KnownVideoCodecs} from './options';
|
|
13
|
-
import type {AnySegment} from './parse-result';
|
|
14
|
-
import {getMoovBox, getStsdBox, getTraks} from './traversal';
|
|
15
|
-
|
|
16
|
-
export const hasVideoCodec = (boxes: AnySegment[]): boolean => {
|
|
17
|
-
try {
|
|
18
|
-
return getVideoCodec(boxes) !== null;
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const getVideoCodecString = (trakBox: TrakBox): string | null => {
|
|
25
|
-
const videoSample = getVideoSample(trakBox);
|
|
26
|
-
const avccBox = getAvccBox(trakBox);
|
|
27
|
-
const hvccBox = getHvccBox(trakBox);
|
|
28
|
-
const av1cBox = getAv1CBox(trakBox);
|
|
29
|
-
|
|
30
|
-
if (!videoSample) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (avccBox) {
|
|
35
|
-
return `${videoSample.format}.${avccBox.configurationString}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (hvccBox) {
|
|
39
|
-
return `${videoSample.format}.${hvccBox.configurationString}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (av1cBox) {
|
|
43
|
-
const colrAtom = getColrBox(videoSample);
|
|
44
|
-
return parseAv1PrivateData(av1cBox.privateData, colrAtom);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return videoSample.format;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const getVideoCodec = (boxes: AnySegment[]): KnownVideoCodecs | null => {
|
|
51
|
-
const moovBox = getMoovBox(boxes);
|
|
52
|
-
if (moovBox) {
|
|
53
|
-
const trakBox = getTraks(moovBox).filter((t) => trakBoxContainsVideo(t))[0];
|
|
54
|
-
if (trakBox) {
|
|
55
|
-
const stsdBox = getStsdBox(trakBox);
|
|
56
|
-
if (stsdBox && stsdBox.type === 'stsd-box') {
|
|
57
|
-
const videoSample = stsdBox.samples.find((s) => s.type === 'video');
|
|
58
|
-
if (videoSample && videoSample.type === 'video') {
|
|
59
|
-
if (videoSample.format === 'hvc1') {
|
|
60
|
-
return 'h265';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (videoSample.format === 'avc1') {
|
|
64
|
-
return 'h264';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (videoSample.format === 'av01') {
|
|
68
|
-
return 'av1';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (videoSample.format === 'ap4h') {
|
|
72
|
-
return 'prores';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const mainSegment = boxes.find((b) => b.type === 'Segment');
|
|
80
|
-
if (!mainSegment || mainSegment.type !== 'Segment') {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const tracksSegment = mainSegment.value.find((b) => b.type === 'Tracks');
|
|
85
|
-
if (!tracksSegment || tracksSegment.type !== 'Tracks') {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (const track of tracksSegment.value) {
|
|
90
|
-
if (track.type === 'TrackEntry') {
|
|
91
|
-
const trackType = track.value.find((b) => b.type === 'CodecID');
|
|
92
|
-
if (trackType && trackType.type === 'CodecID') {
|
|
93
|
-
if (trackType.value === 'V_VP8') {
|
|
94
|
-
return 'vp8';
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (trackType.value === 'V_VP9') {
|
|
98
|
-
return 'vp9';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (trackType.value === 'V_AV1') {
|
|
102
|
-
return 'av1';
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (trackType.value === 'V_MPEG4/ISO/AVC') {
|
|
106
|
-
return 'h264';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (trackType.value === 'V_MPEGH/ISO/HEVC') {
|
|
110
|
-
return 'h265';
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return null;
|
|
117
|
-
};
|
package/src/has-all-info.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {hasAudioCodec} from './get-audio-codec';
|
|
2
|
-
import {hasDimensions} from './get-dimensions';
|
|
3
|
-
import {hasDuration} from './get-duration';
|
|
4
|
-
import {hasFps} from './get-fps';
|
|
5
|
-
import {hasTracks} from './get-tracks';
|
|
6
|
-
import {hasVideoCodec} from './get-video-codec';
|
|
7
|
-
import type {Options} from './options';
|
|
8
|
-
import type {ParseResult} from './parse-result';
|
|
9
|
-
import type {ParserState} from './parser-state';
|
|
10
|
-
|
|
11
|
-
export const hasAllInfo = (
|
|
12
|
-
options: Options<
|
|
13
|
-
boolean,
|
|
14
|
-
boolean,
|
|
15
|
-
boolean,
|
|
16
|
-
boolean,
|
|
17
|
-
boolean,
|
|
18
|
-
boolean,
|
|
19
|
-
boolean,
|
|
20
|
-
boolean,
|
|
21
|
-
boolean,
|
|
22
|
-
boolean
|
|
23
|
-
>,
|
|
24
|
-
parseResult: ParseResult,
|
|
25
|
-
state: ParserState,
|
|
26
|
-
) => {
|
|
27
|
-
const keys = Object.entries(options)
|
|
28
|
-
.filter(([, value]) => value)
|
|
29
|
-
.map(([key]) => key) as (keyof Options<
|
|
30
|
-
true,
|
|
31
|
-
true,
|
|
32
|
-
true,
|
|
33
|
-
true,
|
|
34
|
-
true,
|
|
35
|
-
true,
|
|
36
|
-
true,
|
|
37
|
-
true,
|
|
38
|
-
true,
|
|
39
|
-
true
|
|
40
|
-
>)[];
|
|
41
|
-
|
|
42
|
-
return keys.every((key) => {
|
|
43
|
-
if (key === 'boxes') {
|
|
44
|
-
return parseResult.status === 'done';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (key === 'durationInSeconds') {
|
|
48
|
-
return hasDuration(parseResult.segments, state);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
key === 'dimensions' ||
|
|
53
|
-
key === 'rotation' ||
|
|
54
|
-
key === 'unrotatedDimensions'
|
|
55
|
-
) {
|
|
56
|
-
return hasDimensions(parseResult.segments, state);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (key === 'fps') {
|
|
60
|
-
return hasFps(parseResult.segments) !== null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (key === 'videoCodec') {
|
|
64
|
-
return hasVideoCodec(parseResult.segments);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (key === 'audioCodec') {
|
|
68
|
-
return hasAudioCodec(parseResult.segments);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (key === 'tracks') {
|
|
72
|
-
return hasTracks(parseResult.segments);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (key === 'internalStats') {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
throw new Error(`Unknown key: ${key satisfies never}`);
|
|
80
|
-
});
|
|
81
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {createMedia} from './create/create-media';
|
|
2
|
-
|
|
3
|
-
export {AudioTrack, OtherTrack, Track, VideoTrack} from './get-tracks';
|
|
4
|
-
export {parseMedia} from './parse-media';
|
|
5
|
-
export {
|
|
6
|
-
AudioSample,
|
|
7
|
-
OnAudioSample,
|
|
8
|
-
OnAudioTrack,
|
|
9
|
-
OnVideoSample,
|
|
10
|
-
OnVideoTrack,
|
|
11
|
-
VideoSample,
|
|
12
|
-
} from './webcodec-sample-types';
|
|
13
|
-
|
|
14
|
-
export type {MediaFn} from './create/create-media';
|
|
15
|
-
|
|
16
|
-
export const MediaParserInternals = {
|
|
17
|
-
createMedia,
|
|
18
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type {BufferIterator} from './buffer-iterator';
|
|
2
|
-
|
|
3
|
-
export const getHvc1CodecString = (data: BufferIterator) => {
|
|
4
|
-
const configurationVersion = data.getUint8();
|
|
5
|
-
if (configurationVersion !== 1) {
|
|
6
|
-
throw new Error(`Unsupported HVCC version ${configurationVersion}`);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const generalProfileSpaceTierFlagAndIdc = data.getUint8();
|
|
10
|
-
let generalProfileCompatibility = data.getUint32();
|
|
11
|
-
// unsigned int(2) general_profile_space;
|
|
12
|
-
// unsigned int(1) general_tier_flag;
|
|
13
|
-
// unsigned int(5) general_profile_idc;
|
|
14
|
-
|
|
15
|
-
const generalProfileSpace = generalProfileSpaceTierFlagAndIdc >> 6;
|
|
16
|
-
const generalTierFlag = generalProfileSpaceTierFlagAndIdc >> 5;
|
|
17
|
-
const generalProfileIdc = generalProfileSpaceTierFlagAndIdc >> 0;
|
|
18
|
-
|
|
19
|
-
// general_constraint_indicator_flags(48)
|
|
20
|
-
const generalConstraintIndicator = data.getSlice(6);
|
|
21
|
-
const generalLevelIdc = data.getUint8();
|
|
22
|
-
|
|
23
|
-
let reversedGeneralProfileSpace = 0;
|
|
24
|
-
for (let i = 0; i < 32; i++) {
|
|
25
|
-
reversedGeneralProfileSpace |= generalProfileCompatibility & 1;
|
|
26
|
-
if (i === 31) break;
|
|
27
|
-
|
|
28
|
-
reversedGeneralProfileSpace <<= 1;
|
|
29
|
-
generalProfileCompatibility >>= 1;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const profileSpaceChar =
|
|
33
|
-
generalProfileSpace === 0
|
|
34
|
-
? ''
|
|
35
|
-
: generalProfileSpace === 1
|
|
36
|
-
? 'A'
|
|
37
|
-
: generalProfileSpace === 2
|
|
38
|
-
? 'B'
|
|
39
|
-
: 'C';
|
|
40
|
-
|
|
41
|
-
const generalTierChar = generalTierFlag === 0 ? 'L' : 'H';
|
|
42
|
-
|
|
43
|
-
let hasByte = false;
|
|
44
|
-
|
|
45
|
-
let generalConstraintString = '';
|
|
46
|
-
for (let i = 5; i >= 0; i--) {
|
|
47
|
-
if (generalConstraintIndicator[i] || hasByte) {
|
|
48
|
-
generalConstraintString =
|
|
49
|
-
generalConstraintIndicator[i].toString(16) + generalConstraintString;
|
|
50
|
-
hasByte = true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return `${profileSpaceChar}${generalProfileIdc.toString(16)}.${reversedGeneralProfileSpace.toString(16)}.${generalTierChar}${generalLevelIdc}.${generalConstraintString}`;
|
|
55
|
-
};
|