@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.
Files changed (213) hide show
  1. package/buffer.js +2 -0
  2. package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +1 -1
  3. package/dist/boxes/iso-base-media/make-track.js +14 -2
  4. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -1
  5. package/dist/boxes/iso-base-media/mdat/mdat.js +8 -3
  6. package/dist/boxes/iso-base-media/moov/moov.d.ts +2 -1
  7. package/dist/boxes/iso-base-media/moov/moov.js +2 -1
  8. package/dist/boxes/iso-base-media/process-box.d.ts +6 -3
  9. package/dist/boxes/iso-base-media/process-box.js +20 -5
  10. package/dist/boxes/iso-base-media/stsd/avcc.d.ts +1 -1
  11. package/dist/boxes/iso-base-media/stsd/avcc.js +2 -2
  12. package/dist/boxes/iso-base-media/stsd/ctts.js +2 -5
  13. package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +1 -1
  14. package/dist/boxes/iso-base-media/stsd/hvcc.js +2 -2
  15. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +2 -1
  16. package/dist/boxes/iso-base-media/stsd/mebx.js +2 -1
  17. package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -2
  18. package/dist/boxes/iso-base-media/stsd/samples.js +69 -11
  19. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +2 -1
  20. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -1
  21. package/dist/boxes/iso-base-media/trak/trak.d.ts +2 -1
  22. package/dist/boxes/iso-base-media/trak/trak.js +2 -1
  23. package/dist/boxes/iso-base-media/traversal.d.ts +44 -0
  24. package/dist/boxes/iso-base-media/traversal.js +211 -0
  25. package/dist/boxes/webm/color.d.ts +4 -0
  26. package/dist/boxes/webm/color.js +120 -0
  27. package/dist/boxes/webm/description.js +1 -1
  28. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  29. package/dist/boxes/webm/get-sample-from-block.js +1 -1
  30. package/dist/boxes/webm/get-track.js +16 -1
  31. package/dist/boxes/webm/make-track.d.ts +9 -0
  32. package/dist/boxes/webm/make-track.js +260 -0
  33. package/dist/boxes/webm/parse-ebml.js +2 -2
  34. package/dist/boxes/webm/segments/all-segments.d.ts +36 -3
  35. package/dist/boxes/webm/segments/all-segments.js +34 -6
  36. package/dist/boxes/webm/traversal.d.ts +26 -1
  37. package/dist/boxes/webm/traversal.js +214 -1
  38. package/dist/create/cluster-segment.js +0 -2
  39. package/dist/create/cluster.d.ts +10 -2
  40. package/dist/create/cluster.js +16 -10
  41. package/dist/create/create-media.d.ts +4 -2
  42. package/dist/create/create-media.js +76 -14
  43. package/dist/create/cues.d.ts +0 -0
  44. package/dist/create/cues.js +1 -0
  45. package/dist/create/make-duration-with-padding.d.ts +1 -1
  46. package/dist/create/make-duration-with-padding.js +3 -3
  47. package/dist/create/matroska-cues.d.ts +6 -0
  48. package/dist/create/matroska-cues.js +50 -0
  49. package/dist/create/matroska-info.js +1 -1
  50. package/dist/create/matroska-seek.d.ts +6 -0
  51. package/dist/create/matroska-seek.js +32 -0
  52. package/dist/create/matroska-segment.d.ts +1 -0
  53. package/dist/create/matroska-segment.js +3 -2
  54. package/dist/create/matroska-trackentry.d.ts +9 -14
  55. package/dist/create/matroska-trackentry.js +79 -94
  56. package/dist/emit-available-info.d.ts +12 -0
  57. package/dist/emit-available-info.js +133 -0
  58. package/dist/esm/buffer.mjs +57 -0
  59. package/dist/esm/from-fetch.mjs +72 -0
  60. package/dist/esm/from-node.mjs +48 -0
  61. package/dist/esm/from-web-file.mjs +48 -0
  62. package/dist/esm/index.mjs +6689 -0
  63. package/dist/esm/web-fs.mjs +67 -0
  64. package/dist/get-audio-codec.d.ts +5 -5
  65. package/dist/get-audio-codec.js +41 -57
  66. package/dist/get-container.d.ts +4 -0
  67. package/dist/get-container.js +26 -0
  68. package/dist/get-duration.js +1 -1
  69. package/dist/get-fps.js +1 -1
  70. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  71. package/dist/get-sample-aspect-ratio.js +19 -19
  72. package/dist/get-tracks.d.ts +13 -0
  73. package/dist/get-tracks.js +8 -8
  74. package/dist/get-video-codec.d.ts +5 -2
  75. package/dist/get-video-codec.js +111 -21
  76. package/dist/has-all-info.d.ts +2 -2
  77. package/dist/has-all-info.js +23 -9
  78. package/dist/index.d.ts +3 -1
  79. package/dist/options.d.ts +97 -30
  80. package/dist/parse-media.js +43 -62
  81. package/dist/parse-video.d.ts +2 -1
  82. package/dist/parse-video.js +3 -1
  83. package/dist/parser-state.js +1 -2
  84. package/dist/readers/from-fetch.js +24 -4
  85. package/dist/readers/from-node.js +13 -3
  86. package/dist/readers/from-web-file.js +14 -2
  87. package/dist/readers/reader.d.ts +6 -1
  88. package/dist/samples-from-moof.js +1 -1
  89. package/dist/traversal.d.ts +0 -21
  90. package/dist/traversal.js +1 -158
  91. package/dist/truthy.d.ts +3 -0
  92. package/dist/truthy.js +7 -0
  93. package/dist/writers/buffer.d.ts +2 -0
  94. package/dist/writers/buffer.js +58 -0
  95. package/dist/writers/web-fs.d.ts +1 -0
  96. package/dist/writers/web-fs.js +42 -18
  97. package/dist/writers/writer.d.ts +4 -2
  98. package/fetch.js +2 -0
  99. package/node.js +2 -0
  100. package/package.json +43 -8
  101. package/web-file.js +2 -0
  102. package/web-fs.js +2 -0
  103. package/.eslintrc +0 -8
  104. package/input.webm +0 -0
  105. package/src/add-new-matroska-tracks.ts +0 -23
  106. package/src/boxes/iso-base-media/base-type.ts +0 -4
  107. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  108. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  109. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  110. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  111. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  112. package/src/boxes/iso-base-media/make-track.ts +0 -116
  113. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  114. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  115. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  116. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  117. package/src/boxes/iso-base-media/process-box.ts +0 -748
  118. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  119. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  120. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  121. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  122. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  123. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  124. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  125. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  126. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  127. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  128. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  129. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  130. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  131. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  132. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  133. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  134. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  135. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  136. package/src/boxes/iso-base-media/to-date.ts +0 -9
  137. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  138. package/src/boxes/iso-base-media/trun.ts +0 -74
  139. package/src/boxes/iso-base-media/void-box.ts +0 -4
  140. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  141. package/src/boxes/webm/av1-codec-private.ts +0 -113
  142. package/src/boxes/webm/description.ts +0 -104
  143. package/src/boxes/webm/ebml.ts +0 -98
  144. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  145. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  146. package/src/boxes/webm/get-track.ts +0 -257
  147. package/src/boxes/webm/make-header.ts +0 -253
  148. package/src/boxes/webm/parse-ebml.ts +0 -259
  149. package/src/boxes/webm/parse-webm-header.ts +0 -18
  150. package/src/boxes/webm/segments/all-segments.ts +0 -888
  151. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  152. package/src/boxes/webm/segments/parse-children.ts +0 -144
  153. package/src/boxes/webm/segments/track-entry.ts +0 -38
  154. package/src/boxes/webm/segments.ts +0 -147
  155. package/src/boxes/webm/traversal.ts +0 -45
  156. package/src/buffer-iterator.ts +0 -555
  157. package/src/create/cluster-segment.ts +0 -62
  158. package/src/create/cluster.ts +0 -64
  159. package/src/create/create-media.ts +0 -136
  160. package/src/create/make-duration-with-padding.ts +0 -15
  161. package/src/create/matroska-header.ts +0 -63
  162. package/src/create/matroska-info.ts +0 -30
  163. package/src/create/matroska-segment.ts +0 -10
  164. package/src/create/matroska-trackentry.ts +0 -325
  165. package/src/create/timescale.ts +0 -1
  166. package/src/get-audio-codec.ts +0 -270
  167. package/src/get-dimensions.ts +0 -47
  168. package/src/get-duration.ts +0 -103
  169. package/src/get-fps.ts +0 -113
  170. package/src/get-sample-aspect-ratio.ts +0 -204
  171. package/src/get-sample-positions.ts +0 -93
  172. package/src/get-tracks.ts +0 -147
  173. package/src/get-video-codec.ts +0 -117
  174. package/src/has-all-info.ts +0 -81
  175. package/src/index.ts +0 -18
  176. package/src/make-hvc1-codec-strings.ts +0 -55
  177. package/src/options.ts +0 -118
  178. package/src/parse-media.ts +0 -183
  179. package/src/parse-result.ts +0 -79
  180. package/src/parse-video.ts +0 -83
  181. package/src/parser-context.ts +0 -10
  182. package/src/parser-state.ts +0 -178
  183. package/src/readers/from-fetch.ts +0 -90
  184. package/src/readers/from-node.ts +0 -51
  185. package/src/readers/from-web-file.ts +0 -49
  186. package/src/readers/reader.ts +0 -15
  187. package/src/samples-from-moof.ts +0 -102
  188. package/src/test/aspect-ratio.test.ts +0 -42
  189. package/src/test/av1.test.ts +0 -108
  190. package/src/test/create-matroska.test.ts +0 -287
  191. package/src/test/duration.test.ts +0 -18
  192. package/src/test/keys.test.ts +0 -47
  193. package/src/test/matroska.test.ts +0 -463
  194. package/src/test/mvhd.test.ts +0 -94
  195. package/src/test/parse-esds.test.ts +0 -98
  196. package/src/test/parse-stco.test.ts +0 -61
  197. package/src/test/parse-stsc.test.ts +0 -104
  198. package/src/test/parse-stsz.test.ts +0 -57
  199. package/src/test/parse-stts.test.ts +0 -38
  200. package/src/test/parse-video.test.ts +0 -101
  201. package/src/test/parse-webm.test.ts +0 -17
  202. package/src/test/samples-from-moof.test.ts +0 -2496
  203. package/src/test/stream-local.test.ts +0 -743
  204. package/src/test/stream-remote.test.ts +0 -59
  205. package/src/test/stream-samples.test.ts +0 -181
  206. package/src/test/stsd.test.ts +0 -265
  207. package/src/test/tkhd.test.ts +0 -87
  208. package/src/traversal.ts +0 -528
  209. package/src/webcodec-sample-types.ts +0 -29
  210. package/src/writers/web-fs.ts +0 -50
  211. package/src/writers/writer.ts +0 -12
  212. package/tsconfig.json +0 -14
  213. package/tsconfig.tsbuildinfo +0 -1
@@ -1,259 +0,0 @@
1
- import {registerTrack} from '../../add-new-matroska-tracks';
2
- import {type BufferIterator} from '../../buffer-iterator';
3
- import type {ParserContext} from '../../parser-context';
4
- import type {VideoSample} from '../../webcodec-sample-types';
5
- import {getSampleFromBlock} from './get-sample-from-block';
6
- import {getTrack} from './get-track';
7
- import type {PossibleEbml} from './segments/all-segments';
8
- import {ebmlMap} from './segments/all-segments';
9
-
10
- export type Prettify<T> = {
11
- [K in keyof T]: T[K];
12
- } & {};
13
-
14
- export const parseEbml = async (
15
- iterator: BufferIterator,
16
- parserContext: ParserContext,
17
- ): Promise<Prettify<PossibleEbml>> => {
18
- const hex = iterator.getMatroskaSegmentId();
19
- if (hex === null) {
20
- throw new Error(
21
- 'Not enough bytes left to parse EBML - this should not happen',
22
- );
23
- }
24
-
25
- const hasInMap = ebmlMap[hex as keyof typeof ebmlMap];
26
- if (!hasInMap) {
27
- throw new Error(
28
- `Don't know how to parse EBML hex ID ${JSON.stringify(hex)}`,
29
- );
30
- }
31
-
32
- const off = iterator.counter.getOffset();
33
- const size = iterator.getVint();
34
- const minVintWidth = iterator.counter.getOffset() - off;
35
-
36
- if (size === null) {
37
- throw new Error(
38
- 'Not enough bytes left to parse EBML - this should not happen',
39
- );
40
- }
41
-
42
- if (hasInMap.type === 'uint') {
43
- const beforeUintOffset = iterator.counter.getOffset();
44
- const value = size === 0 ? 0 : iterator.getUint(size);
45
-
46
- const {name} = hasInMap;
47
-
48
- return {
49
- // To work around TS limit
50
- type: name as 'SeekPosition',
51
- value: {
52
- value,
53
- byteLength: iterator.counter.getOffset() - beforeUintOffset,
54
- },
55
- minVintWidth,
56
- };
57
- }
58
-
59
- if (hasInMap.type === 'string') {
60
- const value = iterator.getByteString(size);
61
-
62
- return {
63
- type: hasInMap.name,
64
- value,
65
- minVintWidth,
66
- };
67
- }
68
-
69
- if (hasInMap.type === 'float') {
70
- const value =
71
- size === 0
72
- ? 0.0
73
- : size === 4
74
- ? iterator.getFloat32()
75
- : iterator.getFloat64();
76
-
77
- return {
78
- type: hasInMap.name,
79
- value: {
80
- value,
81
- size: size === 4 ? '32' : '64',
82
- },
83
- minVintWidth,
84
- };
85
- }
86
-
87
- if (hasInMap.type === 'hex-string') {
88
- return {
89
- type: hasInMap.name,
90
- value:
91
- '0x' +
92
- [...iterator.getSlice(size)]
93
- .map((b) => b.toString(16).padStart(2, '0'))
94
- .join(''),
95
- minVintWidth,
96
- };
97
- }
98
-
99
- if (hasInMap.type === 'uint8array') {
100
- return {
101
- type: hasInMap.name,
102
- value: iterator.getSlice(size),
103
- minVintWidth,
104
- };
105
- }
106
-
107
- if (hasInMap.type === 'children') {
108
- const children: PossibleEbml[] = [];
109
- const startOffset = iterator.counter.getOffset();
110
-
111
- // eslint-disable-next-line no-constant-condition
112
- while (true) {
113
- if (size === 0) {
114
- break;
115
- }
116
-
117
- const offset = iterator.counter.getOffset();
118
- const value = await parseEbml(iterator, parserContext);
119
- const remapped = await postprocessEbml({
120
- offset,
121
- ebml: value,
122
- parserContext,
123
- });
124
- children.push(remapped);
125
-
126
- const offsetNow = iterator.counter.getOffset();
127
-
128
- if (offsetNow - startOffset > size) {
129
- throw new Error(
130
- `Offset ${offsetNow - startOffset} is larger than the length of the hex ${size}`,
131
- );
132
- }
133
-
134
- if (offsetNow - startOffset === size) {
135
- break;
136
- }
137
- }
138
-
139
- return {type: hasInMap.name, value: children, minVintWidth};
140
- }
141
-
142
- // @ts-expect-error
143
- throw new Error(`Unknown segment type ${hasInMap.type}`);
144
- };
145
-
146
- export const postprocessEbml = async ({
147
- offset,
148
- ebml,
149
- parserContext,
150
- }: {
151
- offset: number;
152
- ebml: Prettify<PossibleEbml>;
153
- parserContext: ParserContext;
154
- }): Promise<Prettify<PossibleEbml>> => {
155
- if (ebml.type === 'TimestampScale') {
156
- parserContext.parserState.setTimescale(ebml.value.value);
157
- }
158
-
159
- if (ebml.type === 'TrackEntry') {
160
- parserContext.parserState.onTrackEntrySegment(ebml);
161
-
162
- const track = getTrack({
163
- track: ebml,
164
- timescale: parserContext.parserState.getTimescale(),
165
- });
166
-
167
- if (track) {
168
- await registerTrack({
169
- state: parserContext.parserState,
170
- options: parserContext,
171
- track,
172
- });
173
- }
174
- }
175
-
176
- if (ebml.type === 'Timestamp') {
177
- parserContext.parserState.setTimestampOffset(offset, ebml.value.value);
178
- }
179
-
180
- if (ebml.type === 'Block' || ebml.type === 'SimpleBlock') {
181
- const sample = getSampleFromBlock(ebml, parserContext, offset);
182
-
183
- if (sample.type === 'video-sample' && parserContext.nullifySamples) {
184
- await parserContext.parserState.onVideoSample(
185
- sample.videoSample.trackId,
186
- sample.videoSample,
187
- );
188
- return {
189
- type: 'Block',
190
- value: new Uint8Array([]),
191
- minVintWidth: ebml.minVintWidth,
192
- };
193
- }
194
-
195
- if (sample.type === 'audio-sample' && parserContext.nullifySamples) {
196
- await parserContext.parserState.onAudioSample(
197
- sample.audioSample.trackId,
198
- sample.audioSample,
199
- );
200
- return {
201
- type: 'Block',
202
- value: new Uint8Array([]),
203
- minVintWidth: ebml.minVintWidth,
204
- };
205
- }
206
-
207
- if (sample.type === 'no-sample' && parserContext.nullifySamples) {
208
- return {
209
- type: 'Block',
210
- value: new Uint8Array([]),
211
- minVintWidth: ebml.minVintWidth,
212
- };
213
- }
214
- }
215
-
216
- if (ebml.type === 'BlockGroup') {
217
- // Blocks don't have information about keyframes.
218
- // https://ffmpeg.org/pipermail/ffmpeg-devel/2015-June/173825.html
219
- // "For Blocks, keyframes is
220
- // inferred by the absence of ReferenceBlock element (as done by matroskadec).""
221
-
222
- const block = ebml.value.find(
223
- (c) => c.type === 'SimpleBlock' || c.type === 'Block',
224
- );
225
- if (!block || (block.type !== 'SimpleBlock' && block.type !== 'Block')) {
226
- throw new Error('Expected block segment');
227
- }
228
-
229
- const hasReferenceBlock = ebml.value.find(
230
- (c) => c.type === 'ReferenceBlock',
231
- );
232
-
233
- const sample =
234
- block.value.length === 0
235
- ? null
236
- : getSampleFromBlock(block, parserContext, offset);
237
-
238
- if (sample && sample.type === 'partial-video-sample') {
239
- const completeFrame: VideoSample = {
240
- ...sample.partialVideoSample,
241
- type: hasReferenceBlock ? 'delta' : 'key',
242
- };
243
- await parserContext.parserState.onVideoSample(
244
- sample.partialVideoSample.trackId,
245
- completeFrame,
246
- );
247
- }
248
-
249
- if (parserContext.nullifySamples) {
250
- return {
251
- type: 'BlockGroup',
252
- value: [],
253
- minVintWidth: ebml.minVintWidth,
254
- };
255
- }
256
- }
257
-
258
- return ebml;
259
- };
@@ -1,18 +0,0 @@
1
- import type {BufferIterator} from '../../buffer-iterator';
2
- import type {ParseResult} from '../../parse-result';
3
- import type {ParserContext} from '../../parser-context';
4
- import {expectChildren} from './segments/parse-children';
5
-
6
- // Parsing according to https://darkcoding.net/software/reading-mediarecorders-webm-opus-output/
7
- export const parseWebm = (
8
- counter: BufferIterator,
9
- parserContext: ParserContext,
10
- ): Promise<ParseResult> => {
11
- return expectChildren({
12
- iterator: counter,
13
- length: Infinity,
14
- initialChildren: [],
15
- wrap: null,
16
- parserContext,
17
- });
18
- };