@remotion/media-parser 4.0.209 → 4.0.211

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 (290) 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 +13 -4
  5. package/dist/boxes/iso-base-media/mdat/mdat.js +20 -5
  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 +66 -12
  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 +39 -0
  24. package/dist/boxes/iso-base-media/traversal.js +201 -0
  25. package/dist/boxes/webm/color.d.ts +4 -0
  26. package/dist/boxes/webm/color.js +127 -0
  27. package/dist/boxes/webm/description.js +1 -1
  28. package/dist/boxes/webm/ebml.d.ts +1 -1
  29. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  30. package/dist/boxes/webm/get-sample-from-block.js +1 -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/segments/parse-children.js +6 -0
  37. package/dist/boxes/webm/traversal.d.ts +26 -1
  38. package/dist/boxes/webm/traversal.js +214 -1
  39. package/dist/buffer-iterator.d.ts +4 -1
  40. package/dist/buffer-iterator.js +31 -5
  41. package/dist/create/cluster-segment.js +0 -2
  42. package/dist/create/cluster.d.ts +16 -2
  43. package/dist/create/cluster.js +17 -10
  44. package/dist/create/create-media.d.ts +4 -2
  45. package/dist/create/create-media.js +101 -22
  46. package/dist/create/make-duration-with-padding.d.ts +1 -1
  47. package/dist/create/make-duration-with-padding.js +3 -3
  48. package/dist/create/matroska-cues.d.ts +6 -0
  49. package/dist/create/matroska-cues.js +49 -0
  50. package/dist/create/matroska-info.js +1 -1
  51. package/dist/create/matroska-seek.d.ts +6 -0
  52. package/dist/create/matroska-seek.js +32 -0
  53. package/dist/create/matroska-segment.d.ts +1 -0
  54. package/dist/create/matroska-segment.js +3 -2
  55. package/dist/create/matroska-trackentry.d.ts +9 -14
  56. package/dist/create/matroska-trackentry.js +79 -102
  57. package/dist/emit-available-info.d.ts +12 -0
  58. package/dist/emit-available-info.js +133 -0
  59. package/dist/esm/buffer.mjs +57 -0
  60. package/dist/esm/from-fetch.mjs +107 -0
  61. package/dist/esm/from-node.mjs +49 -0
  62. package/dist/esm/from-web-file.mjs +49 -0
  63. package/dist/esm/index.mjs +6822 -0
  64. package/dist/esm/web-fs.mjs +67 -0
  65. package/dist/get-audio-codec.d.ts +5 -5
  66. package/dist/get-audio-codec.js +44 -57
  67. package/dist/get-container.d.ts +4 -0
  68. package/dist/get-container.js +26 -0
  69. package/dist/get-duration.js +1 -1
  70. package/dist/get-fps.js +1 -1
  71. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  72. package/dist/get-sample-aspect-ratio.js +19 -19
  73. package/dist/get-tracks.d.ts +13 -0
  74. package/dist/get-tracks.js +8 -8
  75. package/dist/get-video-codec.d.ts +5 -2
  76. package/dist/get-video-codec.js +111 -21
  77. package/dist/has-all-info.d.ts +2 -2
  78. package/dist/has-all-info.js +23 -9
  79. package/dist/index.d.ts +4 -1
  80. package/dist/options.d.ts +97 -30
  81. package/dist/parse-media.js +59 -69
  82. package/dist/parse-video.d.ts +2 -1
  83. package/dist/parse-video.js +3 -1
  84. package/dist/parser-context.d.ts +1 -0
  85. package/dist/parser-state.js +1 -2
  86. package/dist/readers/from-fetch.d.ts +12 -0
  87. package/dist/readers/from-fetch.js +83 -17
  88. package/dist/readers/from-node.js +14 -3
  89. package/dist/readers/from-web-file.js +15 -2
  90. package/dist/readers/reader.d.ts +7 -1
  91. package/dist/samples-from-moof.js +1 -1
  92. package/dist/truthy.d.ts +3 -0
  93. package/dist/truthy.js +7 -0
  94. package/dist/writers/buffer.d.ts +2 -0
  95. package/dist/writers/buffer.js +58 -0
  96. package/dist/writers/web-fs.d.ts +1 -0
  97. package/dist/writers/web-fs.js +42 -18
  98. package/dist/writers/writer.d.ts +4 -2
  99. package/fetch.js +2 -0
  100. package/node.js +2 -0
  101. package/package.json +43 -8
  102. package/web-file.js +2 -0
  103. package/web-fs.js +2 -0
  104. package/.eslintrc +0 -8
  105. package/dist/av1-codec-string.d.ts +0 -3
  106. package/dist/av1-codec-string.js +0 -91
  107. package/dist/boxes/iso-base-media/ftype.d.ts +0 -9
  108. package/dist/boxes/iso-base-media/ftype.js +0 -31
  109. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.d.ts +0 -20
  110. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.js +0 -73
  111. package/dist/boxes/iso-base-media/stts/stts.d.ts +0 -15
  112. package/dist/boxes/iso-base-media/stts/stts.js +0 -35
  113. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.d.ts +0 -14
  114. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.js +0 -67
  115. package/dist/boxes/webm/bitstream/av1/bitstream-frame.d.ts +0 -11
  116. package/dist/boxes/webm/bitstream/av1/bitstream-frame.js +0 -14
  117. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.d.ts +0 -6
  118. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.js +0 -9
  119. package/dist/boxes/webm/bitstream/av1/color-config.d.ts +0 -16
  120. package/dist/boxes/webm/bitstream/av1/color-config.js +0 -103
  121. package/dist/boxes/webm/bitstream/av1/color-primaries.d.ts +0 -14
  122. package/dist/boxes/webm/bitstream/av1/color-primaries.js +0 -17
  123. package/dist/boxes/webm/bitstream/av1/decoder-model-info.d.ts +0 -9
  124. package/dist/boxes/webm/bitstream/av1/decoder-model-info.js +0 -17
  125. package/dist/boxes/webm/bitstream/av1/frame.d.ts +0 -0
  126. package/dist/boxes/webm/bitstream/av1/frame.js +0 -1
  127. package/dist/boxes/webm/bitstream/av1/header-segment.d.ts +0 -51
  128. package/dist/boxes/webm/bitstream/av1/header-segment.js +0 -183
  129. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.d.ts +0 -17
  130. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.js +0 -20
  131. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.d.ts +0 -10
  132. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.js +0 -15
  133. package/dist/boxes/webm/bitstream/av1/temporal-point-info.d.ts +0 -5
  134. package/dist/boxes/webm/bitstream/av1/temporal-point-info.js +0 -8
  135. package/dist/boxes/webm/bitstream/av1/timing-info.d.ts +0 -8
  136. package/dist/boxes/webm/bitstream/av1/timing-info.js +0 -20
  137. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.d.ts +0 -21
  138. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.js +0 -24
  139. package/dist/boxes/webm/bitstream/av1/uvlc.d.ts +0 -2
  140. package/dist/boxes/webm/bitstream/av1/uvlc.js +0 -20
  141. package/dist/boxes/webm/bitstream/av1.d.ts +0 -20
  142. package/dist/boxes/webm/bitstream/av1.js +0 -118
  143. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.d.ts +0 -0
  144. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.js +0 -1
  145. package/dist/boxes/webm/segments/duration.d.ts +0 -6
  146. package/dist/boxes/webm/segments/duration.js +0 -19
  147. package/dist/boxes/webm/segments/info.d.ts +0 -9
  148. package/dist/boxes/webm/segments/info.js +0 -22
  149. package/dist/boxes/webm/segments/main.d.ts +0 -5
  150. package/dist/boxes/webm/segments/main.js +0 -2
  151. package/dist/boxes/webm/segments/muxing.d.ts +0 -6
  152. package/dist/boxes/webm/segments/muxing.js +0 -11
  153. package/dist/boxes/webm/segments/seek-head.d.ts +0 -9
  154. package/dist/boxes/webm/segments/seek-head.js +0 -22
  155. package/dist/boxes/webm/segments/seek-position.d.ts +0 -6
  156. package/dist/boxes/webm/segments/seek-position.js +0 -11
  157. package/dist/boxes/webm/segments/seek.d.ts +0 -13
  158. package/dist/boxes/webm/segments/seek.js +0 -35
  159. package/dist/boxes/webm/segments/timestamp-scale.d.ts +0 -6
  160. package/dist/boxes/webm/segments/timestamp-scale.js +0 -11
  161. package/dist/boxes/webm/segments/tracks.d.ts +0 -8
  162. package/dist/boxes/webm/segments/tracks.js +0 -21
  163. package/dist/boxes/webm/segments/unknown.d.ts +0 -6
  164. package/dist/boxes/webm/segments/unknown.js +0 -11
  165. package/dist/boxes/webm/segments/void.d.ts +0 -6
  166. package/dist/boxes/webm/segments/void.js +0 -11
  167. package/dist/boxes/webm/segments/writing.d.ts +0 -6
  168. package/dist/boxes/webm/segments/writing.js +0 -11
  169. package/dist/boxes/webm/tracks.d.ts +0 -8
  170. package/dist/boxes/webm/tracks.js +0 -21
  171. package/dist/combine-uint8array.d.ts +0 -1
  172. package/dist/combine-uint8array.js +0 -13
  173. package/dist/from-web.d.ts +0 -2
  174. package/dist/from-web.js +0 -45
  175. package/dist/get-video-metadata.d.ts +0 -2
  176. package/dist/get-video-metadata.js +0 -44
  177. package/dist/read-and-increment-offset.d.ts +0 -28
  178. package/dist/read-and-increment-offset.js +0 -177
  179. package/dist/understand-vorbis.d.ts +0 -1
  180. package/dist/understand-vorbis.js +0 -12
  181. package/input.webm +0 -0
  182. package/src/add-new-matroska-tracks.ts +0 -23
  183. package/src/boxes/iso-base-media/base-type.ts +0 -4
  184. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  185. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  186. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  187. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  188. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  189. package/src/boxes/iso-base-media/make-track.ts +0 -116
  190. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  191. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  192. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  193. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  194. package/src/boxes/iso-base-media/process-box.ts +0 -748
  195. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  196. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  197. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  198. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  199. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  200. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  201. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  202. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  203. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  204. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  205. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  206. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  207. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  208. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  209. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  210. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  211. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  212. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  213. package/src/boxes/iso-base-media/to-date.ts +0 -9
  214. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  215. package/src/boxes/iso-base-media/trun.ts +0 -74
  216. package/src/boxes/iso-base-media/void-box.ts +0 -4
  217. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  218. package/src/boxes/webm/av1-codec-private.ts +0 -113
  219. package/src/boxes/webm/description.ts +0 -104
  220. package/src/boxes/webm/ebml.ts +0 -98
  221. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  222. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  223. package/src/boxes/webm/get-track.ts +0 -257
  224. package/src/boxes/webm/make-header.ts +0 -253
  225. package/src/boxes/webm/parse-ebml.ts +0 -259
  226. package/src/boxes/webm/parse-webm-header.ts +0 -18
  227. package/src/boxes/webm/segments/all-segments.ts +0 -888
  228. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  229. package/src/boxes/webm/segments/parse-children.ts +0 -144
  230. package/src/boxes/webm/segments/track-entry.ts +0 -38
  231. package/src/boxes/webm/segments.ts +0 -147
  232. package/src/boxes/webm/traversal.ts +0 -45
  233. package/src/buffer-iterator.ts +0 -555
  234. package/src/create/cluster-segment.ts +0 -62
  235. package/src/create/cluster.ts +0 -64
  236. package/src/create/create-media.ts +0 -136
  237. package/src/create/make-duration-with-padding.ts +0 -15
  238. package/src/create/matroska-header.ts +0 -63
  239. package/src/create/matroska-info.ts +0 -30
  240. package/src/create/matroska-segment.ts +0 -10
  241. package/src/create/matroska-trackentry.ts +0 -325
  242. package/src/create/timescale.ts +0 -1
  243. package/src/get-audio-codec.ts +0 -270
  244. package/src/get-dimensions.ts +0 -47
  245. package/src/get-duration.ts +0 -103
  246. package/src/get-fps.ts +0 -113
  247. package/src/get-sample-aspect-ratio.ts +0 -204
  248. package/src/get-sample-positions.ts +0 -93
  249. package/src/get-tracks.ts +0 -147
  250. package/src/get-video-codec.ts +0 -117
  251. package/src/has-all-info.ts +0 -81
  252. package/src/index.ts +0 -18
  253. package/src/make-hvc1-codec-strings.ts +0 -55
  254. package/src/options.ts +0 -118
  255. package/src/parse-media.ts +0 -183
  256. package/src/parse-result.ts +0 -79
  257. package/src/parse-video.ts +0 -83
  258. package/src/parser-context.ts +0 -10
  259. package/src/parser-state.ts +0 -178
  260. package/src/readers/from-fetch.ts +0 -90
  261. package/src/readers/from-node.ts +0 -51
  262. package/src/readers/from-web-file.ts +0 -49
  263. package/src/readers/reader.ts +0 -15
  264. package/src/samples-from-moof.ts +0 -102
  265. package/src/test/aspect-ratio.test.ts +0 -42
  266. package/src/test/av1.test.ts +0 -108
  267. package/src/test/create-matroska.test.ts +0 -287
  268. package/src/test/duration.test.ts +0 -18
  269. package/src/test/keys.test.ts +0 -47
  270. package/src/test/matroska.test.ts +0 -463
  271. package/src/test/mvhd.test.ts +0 -94
  272. package/src/test/parse-esds.test.ts +0 -98
  273. package/src/test/parse-stco.test.ts +0 -61
  274. package/src/test/parse-stsc.test.ts +0 -104
  275. package/src/test/parse-stsz.test.ts +0 -57
  276. package/src/test/parse-stts.test.ts +0 -38
  277. package/src/test/parse-video.test.ts +0 -101
  278. package/src/test/parse-webm.test.ts +0 -17
  279. package/src/test/samples-from-moof.test.ts +0 -2496
  280. package/src/test/stream-local.test.ts +0 -743
  281. package/src/test/stream-remote.test.ts +0 -59
  282. package/src/test/stream-samples.test.ts +0 -181
  283. package/src/test/stsd.test.ts +0 -265
  284. package/src/test/tkhd.test.ts +0 -87
  285. package/src/traversal.ts +0 -528
  286. package/src/webcodec-sample-types.ts +0 -29
  287. package/src/writers/web-fs.ts +0 -50
  288. package/src/writers/writer.ts +0 -12
  289. package/tsconfig.json +0 -14
  290. package/tsconfig.tsbuildinfo +0 -1
package/src/options.ts DELETED
@@ -1,118 +0,0 @@
1
- import type {} from './boxes/iso-base-media/mdat/mdat';
2
- import type {Dimensions} from './get-dimensions';
3
- import type {AudioTrack, VideoTrack} from './get-tracks';
4
- import type {AnySegment} from './parse-result';
5
- import type {InternalStats} from './parser-state';
6
- import type {ReaderInterface} from './readers/reader';
7
- import type {OnAudioTrack, OnVideoTrack} from './webcodec-sample-types';
8
-
9
- export type KnownVideoCodecs =
10
- | 'h264'
11
- | 'h265'
12
- | 'vp8'
13
- | 'vp9'
14
- | 'av1'
15
- | 'prores';
16
-
17
- export type KnownAudioCodecs =
18
- | 'aac'
19
- | 'mp3'
20
- | 'aiff'
21
- | 'opus'
22
- | 'pcm'
23
- | 'vorbis'
24
- | 'unknown';
25
-
26
- export type Options<
27
- EnableDimensions extends boolean,
28
- EnableDuration extends boolean,
29
- EnableBoxes extends boolean,
30
- EnableFps extends boolean,
31
- EnableVideoCodec extends boolean,
32
- EnableAudioCodec extends boolean,
33
- EnableTracks extends boolean,
34
- EnableRotation extends boolean,
35
- EnableUnrotatedDimensions extends boolean,
36
- EnableInternalStats extends boolean,
37
- > = {
38
- dimensions?: EnableDimensions;
39
- durationInSeconds?: EnableDuration;
40
- boxes?: EnableBoxes;
41
- fps?: EnableFps;
42
- videoCodec?: EnableVideoCodec;
43
- audioCodec?: EnableAudioCodec;
44
- tracks?: EnableTracks;
45
- rotation?: EnableRotation;
46
- unrotatedDimensions?: EnableUnrotatedDimensions;
47
- internalStats?: EnableInternalStats;
48
- };
49
-
50
- export type Metadata<
51
- EnableDimensions extends boolean,
52
- EnableDuration extends boolean,
53
- EnableBoxes extends boolean,
54
- EnableFps extends boolean,
55
- EnableVideoCodec extends boolean,
56
- EnableAudioCodec extends boolean,
57
- EnableTracks extends boolean,
58
- EnableRotation extends boolean,
59
- EnableUnrotatedDimensions extends boolean,
60
- EnableInternalStats extends boolean,
61
- > = (EnableDimensions extends true ? {dimensions: Dimensions} : {}) &
62
- (EnableDuration extends true ? {durationInSeconds: number | null} : {}) &
63
- (EnableBoxes extends true ? {boxes: AnySegment[]} : {}) &
64
- (EnableFps extends true ? {fps: number | null} : {}) &
65
- (EnableVideoCodec extends true ? {videoCodec: KnownVideoCodecs | null} : {}) &
66
- (EnableAudioCodec extends true ? {audioCodec: KnownAudioCodecs | null} : {}) &
67
- (EnableTracks extends true
68
- ? {videoTracks: VideoTrack[]; audioTracks: AudioTrack[]}
69
- : {}) &
70
- (EnableRotation extends true ? {rotation: number | null} : {}) &
71
- (EnableUnrotatedDimensions extends true
72
- ? {unrotatedDimensions: Dimensions}
73
- : {}) &
74
- (EnableInternalStats extends true ? {internalStats: InternalStats} : {});
75
-
76
- export type ParseMedia = <
77
- EnableDimensions extends boolean,
78
- EnableDuration extends boolean,
79
- EnableBoxes extends boolean,
80
- EnableFps extends boolean,
81
- EnableVideoCodec extends boolean,
82
- EnableAudioCodec extends boolean,
83
- EnableTracks extends boolean,
84
- EnableRotation extends boolean,
85
- EnableUnrotatedDimensions extends boolean,
86
- EnableInternalStats extends boolean,
87
- >(options: {
88
- src: string | File;
89
- fields?: Options<
90
- EnableDimensions,
91
- EnableDuration,
92
- EnableBoxes,
93
- EnableFps,
94
- EnableVideoCodec,
95
- EnableAudioCodec,
96
- EnableTracks,
97
- EnableRotation,
98
- EnableUnrotatedDimensions,
99
- EnableInternalStats
100
- >;
101
- reader?: ReaderInterface;
102
- onAudioTrack?: OnAudioTrack;
103
- onVideoTrack?: OnVideoTrack;
104
- signal?: AbortSignal;
105
- }) => Promise<
106
- Metadata<
107
- EnableDimensions,
108
- EnableDuration,
109
- EnableBoxes,
110
- EnableFps,
111
- EnableVideoCodec,
112
- EnableAudioCodec,
113
- EnableTracks,
114
- EnableRotation,
115
- EnableUnrotatedDimensions,
116
- EnableInternalStats
117
- >
118
- >;
@@ -1,183 +0,0 @@
1
- /* eslint-disable max-depth */
2
- import type {BufferIterator} from './buffer-iterator';
3
- import {getArrayBufferIterator} from './buffer-iterator';
4
- import {getAudioCodec} from './get-audio-codec';
5
- import {getDimensions} from './get-dimensions';
6
- import {getDuration} from './get-duration';
7
- import {getFps} from './get-fps';
8
- import {getTracks} from './get-tracks';
9
- import {getVideoCodec} from './get-video-codec';
10
- import {hasAllInfo} from './has-all-info';
11
- import type {Metadata, ParseMedia} from './options';
12
- import type {ParseResult} from './parse-result';
13
- import {parseVideo} from './parse-video';
14
- import type {ParserContext} from './parser-context';
15
- import {makeParserState} from './parser-state';
16
- import {fetchReader} from './readers/from-fetch';
17
-
18
- export const parseMedia: ParseMedia = async ({
19
- src,
20
- fields,
21
- reader: readerInterface = fetchReader,
22
- onAudioTrack,
23
- onVideoTrack,
24
- signal,
25
- }) => {
26
- const state = makeParserState({
27
- hasAudioCallbacks: onAudioTrack !== null,
28
- hasVideoCallbacks: onVideoTrack !== null,
29
- signal,
30
- });
31
- const {reader, contentLength} = await readerInterface.read(src, null, signal);
32
- let currentReader = reader;
33
-
34
- const returnValue = {} as Metadata<
35
- true,
36
- true,
37
- true,
38
- true,
39
- true,
40
- true,
41
- true,
42
- true,
43
- true,
44
- true
45
- >;
46
-
47
- let iterator: BufferIterator | null = null;
48
- let parseResult: ParseResult | null = null;
49
-
50
- const options: ParserContext = {
51
- canSkipVideoData: !(onAudioTrack || onVideoTrack),
52
- onAudioTrack: onAudioTrack ?? null,
53
- onVideoTrack: onVideoTrack ?? null,
54
- parserState: state,
55
- nullifySamples: !(
56
- typeof process !== 'undefined' &&
57
- typeof process.env !== 'undefined' &&
58
- process.env.KEEP_SAMPLES === 'true'
59
- ),
60
- };
61
-
62
- while (parseResult === null || parseResult.status === 'incomplete') {
63
- if (signal?.aborted) {
64
- throw new Error('Aborted');
65
- }
66
-
67
- const result = await currentReader.read();
68
-
69
- if (iterator) {
70
- if (!result.done) {
71
- iterator.addData(result.value);
72
- }
73
- } else {
74
- if (result.done) {
75
- throw new Error('Unexpectedly reached EOF');
76
- }
77
-
78
- iterator = getArrayBufferIterator(
79
- result.value,
80
- contentLength ?? 1_000_000_000,
81
- );
82
- }
83
-
84
- if (parseResult && parseResult.status === 'incomplete') {
85
- parseResult = await parseResult.continueParsing();
86
- } else {
87
- parseResult = await parseVideo({
88
- iterator,
89
- options,
90
- });
91
- }
92
-
93
- // TODO Better: Check if no active listeners are registered
94
- // Also maybe check for canSkipVideoData
95
- if (
96
- hasAllInfo(fields ?? {}, parseResult, state) &&
97
- !onVideoTrack &&
98
- !onAudioTrack
99
- ) {
100
- if (!currentReader.closed) {
101
- currentReader.cancel(new Error('has all information'));
102
- }
103
-
104
- break;
105
- }
106
-
107
- if (
108
- parseResult &&
109
- parseResult.status === 'incomplete' &&
110
- parseResult.skipTo !== null
111
- ) {
112
- if (!currentReader.closed) {
113
- currentReader.cancel(new Error('skipped ahead'));
114
- }
115
-
116
- const {reader: newReader} = await readerInterface.read(
117
- src,
118
- parseResult.skipTo,
119
- signal,
120
- );
121
- currentReader = newReader;
122
- iterator.skipTo(parseResult.skipTo);
123
- }
124
- }
125
-
126
- if (!parseResult) {
127
- throw new Error('Could not parse video');
128
- }
129
-
130
- if (fields?.dimensions) {
131
- const dimensions = getDimensions(parseResult.segments, state);
132
- returnValue.dimensions = {
133
- width: dimensions.width,
134
- height: dimensions.height,
135
- };
136
- }
137
-
138
- if (fields?.unrotatedDimensions) {
139
- const dimensions = getDimensions(parseResult.segments, state);
140
- returnValue.unrotatedDimensions = {
141
- width: dimensions.unrotatedWidth,
142
- height: dimensions.unrotatedHeight,
143
- };
144
- }
145
-
146
- if (fields?.rotation) {
147
- const dimensions = getDimensions(parseResult.segments, state);
148
- returnValue.rotation = dimensions.rotation;
149
- }
150
-
151
- if (fields?.durationInSeconds) {
152
- returnValue.durationInSeconds = getDuration(parseResult.segments, state);
153
- }
154
-
155
- if (fields?.fps) {
156
- returnValue.fps = getFps(parseResult.segments);
157
- }
158
-
159
- if (fields?.videoCodec) {
160
- returnValue.videoCodec = getVideoCodec(parseResult.segments);
161
- }
162
-
163
- if (fields?.audioCodec) {
164
- returnValue.audioCodec = getAudioCodec(parseResult.segments);
165
- }
166
-
167
- if (fields?.tracks) {
168
- const {audioTracks, videoTracks} = getTracks(parseResult.segments, state);
169
- returnValue.audioTracks = audioTracks;
170
- returnValue.videoTracks = videoTracks;
171
- }
172
-
173
- if (fields?.boxes) {
174
- returnValue.boxes = parseResult.segments;
175
- }
176
-
177
- if (fields?.internalStats) {
178
- returnValue.internalStats = state.getInternalStats();
179
- }
180
-
181
- iterator?.destroy();
182
- return returnValue;
183
- };
@@ -1,79 +0,0 @@
1
- import type {BaseBox} from './boxes/iso-base-media/base-type';
2
- import type {EsdsBox} from './boxes/iso-base-media/esds/esds';
3
- import type {FtypBox} from './boxes/iso-base-media/ftyp';
4
- import type {MdatBox} from './boxes/iso-base-media/mdat/mdat';
5
- import type {MdhdBox} from './boxes/iso-base-media/mdhd';
6
- import type {MoovBox} from './boxes/iso-base-media/moov/moov';
7
- import type {MvhdBox} from './boxes/iso-base-media/mvhd';
8
- import type {Av1CBox} from './boxes/iso-base-media/stsd/av1c';
9
- import type {AvccBox} from './boxes/iso-base-media/stsd/avcc';
10
- import type {ColorParameterBox} from './boxes/iso-base-media/stsd/colr';
11
- import type {CttsBox} from './boxes/iso-base-media/stsd/ctts';
12
- import type {HvccBox} from './boxes/iso-base-media/stsd/hvcc';
13
- import type {KeysBox} from './boxes/iso-base-media/stsd/keys';
14
- import type {MebxBox} from './boxes/iso-base-media/stsd/mebx';
15
- import type {PaspBox} from './boxes/iso-base-media/stsd/pasp';
16
- import type {StcoBox} from './boxes/iso-base-media/stsd/stco';
17
- import type {StscBox} from './boxes/iso-base-media/stsd/stsc';
18
- import type {StsdBox} from './boxes/iso-base-media/stsd/stsd';
19
- import type {StssBox} from './boxes/iso-base-media/stsd/stss';
20
- import type {StszBox} from './boxes/iso-base-media/stsd/stsz';
21
- import type {SttsBox} from './boxes/iso-base-media/stsd/stts';
22
- import type {TfdtBox} from './boxes/iso-base-media/tfdt';
23
- import type {TfhdBox} from './boxes/iso-base-media/tfhd';
24
- import type {TkhdBox} from './boxes/iso-base-media/tkhd';
25
- import type {TrakBox} from './boxes/iso-base-media/trak/trak';
26
- import type {TrunBox} from './boxes/iso-base-media/trun';
27
- import type {VoidBox} from './boxes/iso-base-media/void-box';
28
- import type {MatroskaSegment} from './boxes/webm/segments';
29
-
30
- export interface RegularBox extends BaseBox {
31
- boxType: string;
32
- boxSize: number;
33
- children: AnySegment[];
34
- offset: number;
35
- type: 'regular-box';
36
- }
37
-
38
- export type IsoBaseMediaBox =
39
- | RegularBox
40
- | FtypBox
41
- | MvhdBox
42
- | TkhdBox
43
- | StsdBox
44
- | MebxBox
45
- | KeysBox
46
- | MoovBox
47
- | TrakBox
48
- | SttsBox
49
- | MdhdBox
50
- | EsdsBox
51
- | MdatBox
52
- | StszBox
53
- | StcoBox
54
- | StscBox
55
- | AvccBox
56
- | HvccBox
57
- | VoidBox
58
- | StssBox
59
- | PaspBox
60
- | CttsBox
61
- | Av1CBox
62
- | TrunBox
63
- | ColorParameterBox
64
- | TfdtBox
65
- | TfhdBox;
66
-
67
- export type AnySegment = MatroskaSegment | IsoBaseMediaBox;
68
-
69
- export type ParseResult =
70
- | {
71
- status: 'done';
72
- segments: AnySegment[];
73
- }
74
- | {
75
- status: 'incomplete';
76
- segments: AnySegment[];
77
- skipTo: number | null;
78
- continueParsing: () => Promise<ParseResult>;
79
- };
@@ -1,83 +0,0 @@
1
- import {parseBoxes} from './boxes/iso-base-media/process-box';
2
- import {parseWebm} from './boxes/webm/parse-webm-header';
3
- import type {BufferIterator} from './buffer-iterator';
4
- import type {IsoBaseMediaBox, ParseResult} from './parse-result';
5
- import type {ParserContext} from './parser-context';
6
-
7
- export type PartialMdatBox = {
8
- type: 'partial-mdat-box';
9
- boxSize: number;
10
- fileOffset: number;
11
- };
12
-
13
- export type BoxAndNext =
14
- | {
15
- type: 'complete';
16
- box: IsoBaseMediaBox;
17
- size: number;
18
- skipTo: number | null;
19
- }
20
- | {
21
- type: 'incomplete';
22
- }
23
- | PartialMdatBox;
24
-
25
- export const parseVideo = ({
26
- iterator,
27
- options,
28
- }: {
29
- iterator: BufferIterator;
30
- options: ParserContext;
31
- }): Promise<ParseResult> => {
32
- if (iterator.bytesRemaining() === 0) {
33
- return Promise.resolve({
34
- status: 'incomplete',
35
- segments: [],
36
- continueParsing: () => {
37
- return parseVideo({
38
- iterator,
39
- options,
40
- });
41
- },
42
- skipTo: null,
43
- });
44
- }
45
-
46
- if (iterator.isRiff()) {
47
- throw new Error('AVI files are not yet supported');
48
- /*
49
- iterator.discard(4);
50
- return parseBoxes({
51
- iterator,
52
- maxBytes: Infinity,
53
- allowIncompleteBoxes: true,
54
- initialBoxes: [],
55
- options,
56
- continueMdat: false,
57
- littleEndian: true,
58
- });
59
- */
60
- }
61
-
62
- if (iterator.isIsoBaseMedia()) {
63
- return parseBoxes({
64
- iterator,
65
- maxBytes: Infinity,
66
- allowIncompleteBoxes: true,
67
- initialBoxes: [],
68
- options,
69
- continueMdat: false,
70
- littleEndian: false,
71
- });
72
- }
73
-
74
- if (iterator.isWebm()) {
75
- return Promise.resolve(parseWebm(iterator, options));
76
- }
77
-
78
- if (iterator.isMp3()) {
79
- return Promise.reject(new Error('MP3 files are not yet supported'));
80
- }
81
-
82
- return Promise.reject(new Error('Unknown video format'));
83
- };
@@ -1,10 +0,0 @@
1
- import type {ParserState} from './parser-state';
2
- import type {OnAudioTrack, OnVideoTrack} from './webcodec-sample-types';
3
-
4
- export type ParserContext = {
5
- onAudioTrack: OnAudioTrack | null;
6
- onVideoTrack: OnVideoTrack | null;
7
- canSkipVideoData: boolean;
8
- parserState: ParserState;
9
- nullifySamples: boolean;
10
- };
@@ -1,178 +0,0 @@
1
- import type {OnTrackEntrySegment} from './boxes/webm/segments';
2
- import type {TrackInfo} from './boxes/webm/segments/track-entry';
3
- import {getTrackCodec, getTrackTimestampScale} from './boxes/webm/traversal';
4
- import {getTrackId} from './traversal';
5
- import type {
6
- AudioSample,
7
- OnAudioSample,
8
- OnVideoSample,
9
- VideoSample,
10
- } from './webcodec-sample-types';
11
-
12
- export type InternalStats = {};
13
-
14
- export const makeParserState = ({
15
- hasAudioCallbacks,
16
- hasVideoCallbacks,
17
- signal,
18
- }: {
19
- hasAudioCallbacks: boolean;
20
- hasVideoCallbacks: boolean;
21
- signal: AbortSignal | undefined;
22
- }) => {
23
- const trackEntries: Record<number, TrackInfo> = {};
24
-
25
- const onTrackEntrySegment: OnTrackEntrySegment = (trackEntry) => {
26
- const trackId = getTrackId(trackEntry);
27
- if (!trackId) {
28
- throw new Error('Expected track id');
29
- }
30
-
31
- if (trackEntries[trackId]) {
32
- return;
33
- }
34
-
35
- const codec = getTrackCodec(trackEntry);
36
- if (!codec) {
37
- throw new Error('Expected codec');
38
- }
39
-
40
- const trackTimescale = getTrackTimestampScale(trackEntry);
41
-
42
- trackEntries[trackId] = {
43
- codec: codec.value,
44
- trackTimescale: trackTimescale?.value ?? null,
45
- };
46
- };
47
-
48
- const videoSampleCallbacks: Record<number, OnVideoSample> = {};
49
- const audioSampleCallbacks: Record<number, OnAudioSample> = {};
50
-
51
- const queuedAudioSamples: Record<number, AudioSample[]> = {};
52
- const queuedVideoSamples: Record<number, VideoSample[]> = {};
53
-
54
- const declinedTrackNumbers: number[] = [];
55
-
56
- let timescale: number | null = null;
57
-
58
- const getTimescale = () => {
59
- // https://www.matroska.org/technical/notes.html
60
- // When using the default value of TimestampScale of “1,000,000”, one Segment Tick represents one millisecond.
61
- if (timescale === null) {
62
- return 1_000_000;
63
- }
64
-
65
- return timescale;
66
- };
67
-
68
- const setTimescale = (newTimescale: number) => {
69
- timescale = newTimescale;
70
- };
71
-
72
- const timestampMap = new Map<number, number>();
73
-
74
- const setTimestampOffset = (byteOffset: number, timestamp: number) => {
75
- timestampMap.set(byteOffset, timestamp);
76
- };
77
-
78
- const getTimestampOffsetForByteOffset = (byteOffset: number) => {
79
- const entries = Array.from(timestampMap.entries());
80
- const sortedByByteOffset = entries
81
- .sort((a, b) => {
82
- return a[0] - b[0];
83
- })
84
- .reverse();
85
- for (const [offset, timestamp] of sortedByByteOffset) {
86
- if (offset >= byteOffset) {
87
- continue;
88
- }
89
-
90
- return timestamp;
91
- }
92
-
93
- return timestampMap.get(byteOffset);
94
- };
95
-
96
- return {
97
- onTrackEntrySegment,
98
- getTrackInfoByNumber: (id: number) => trackEntries[id],
99
- registerVideoSampleCallback: async (
100
- id: number,
101
- callback: OnVideoSample | null,
102
- ) => {
103
- if (callback === null) {
104
- delete videoSampleCallbacks[id];
105
- declinedTrackNumbers.push(id);
106
- return;
107
- }
108
-
109
- videoSampleCallbacks[id] = callback;
110
-
111
- for (const queued of queuedVideoSamples[id] ?? []) {
112
- await callback(queued);
113
- }
114
-
115
- queuedVideoSamples[id] = [];
116
- },
117
- setTimestampOffset,
118
- getTimestampOffsetForByteOffset,
119
- registerAudioSampleCallback: async (
120
- id: number,
121
- callback: OnAudioSample | null,
122
- ) => {
123
- if (callback === null) {
124
- delete audioSampleCallbacks[id];
125
- declinedTrackNumbers.push(id);
126
- return;
127
- }
128
-
129
- audioSampleCallbacks[id] = callback;
130
- for (const queued of queuedAudioSamples[id] ?? []) {
131
- await callback(queued);
132
- }
133
-
134
- queuedAudioSamples[id] = [];
135
- },
136
- onAudioSample: async (trackId: number, audioSample: AudioSample) => {
137
- if (signal?.aborted) {
138
- throw new Error('Aborted');
139
- }
140
-
141
- const callback = audioSampleCallbacks[trackId];
142
- if (callback) {
143
- await callback(audioSample);
144
- } else {
145
- if (declinedTrackNumbers.includes(trackId)) {
146
- return;
147
- }
148
-
149
- if (!hasAudioCallbacks) {
150
- throw new Error('No audio callbacks registered');
151
- }
152
- }
153
- },
154
- onVideoSample: async (trackId: number, videoSample: VideoSample) => {
155
- if (signal?.aborted) {
156
- throw new Error('Aborted');
157
- }
158
-
159
- const callback = videoSampleCallbacks[trackId];
160
- if (callback) {
161
- await callback(videoSample);
162
- } else {
163
- if (declinedTrackNumbers.includes(trackId)) {
164
- return;
165
- }
166
-
167
- if (!hasVideoCallbacks) {
168
- throw new Error('No video callbacks registered');
169
- }
170
- }
171
- },
172
- getInternalStats: () => ({}),
173
- getTimescale,
174
- setTimescale,
175
- };
176
- };
177
-
178
- export type ParserState = ReturnType<typeof makeParserState>;