@remotion/media-parser 4.0.194 → 4.0.195

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 (275) hide show
  1. package/dist/add-new-matroska-tracks.d.ts +8 -0
  2. package/dist/add-new-matroska-tracks.js +14 -0
  3. package/dist/av1-codec-string.d.ts +3 -0
  4. package/dist/av1-codec-string.js +91 -0
  5. package/dist/boxes/iso-base-media/esds/decoder-specific-config.d.ts +14 -0
  6. package/dist/boxes/iso-base-media/esds/decoder-specific-config.js +38 -0
  7. package/dist/boxes/iso-base-media/esds/esds-descriptors.d.ts +8 -0
  8. package/dist/boxes/iso-base-media/esds/esds-descriptors.js +22 -2
  9. package/dist/boxes/iso-base-media/ftype.d.ts +9 -0
  10. package/dist/boxes/iso-base-media/ftype.js +31 -0
  11. package/dist/boxes/iso-base-media/make-track.d.ts +3 -0
  12. package/dist/boxes/iso-base-media/make-track.js +112 -0
  13. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +6 -2
  14. package/dist/boxes/iso-base-media/mdat/mdat.js +90 -6
  15. package/dist/boxes/iso-base-media/moov/moov.d.ts +4 -2
  16. package/dist/boxes/iso-base-media/moov/moov.js +4 -2
  17. package/dist/boxes/iso-base-media/mvhd.js +7 -1
  18. package/dist/boxes/iso-base-media/process-box.d.ts +20 -3
  19. package/dist/boxes/iso-base-media/process-box.js +322 -34
  20. package/dist/boxes/iso-base-media/stsd/av1c.d.ts +9 -0
  21. package/dist/boxes/iso-base-media/stsd/av1c.js +10 -0
  22. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.d.ts +20 -0
  23. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.js +73 -0
  24. package/dist/boxes/iso-base-media/stsd/avcc.d.ts +10 -0
  25. package/dist/boxes/iso-base-media/stsd/avcc.js +21 -0
  26. package/dist/boxes/iso-base-media/stsd/colr.d.ts +11 -0
  27. package/dist/boxes/iso-base-media/stsd/colr.js +35 -0
  28. package/dist/boxes/iso-base-media/stsd/ctts.d.ts +19 -0
  29. package/dist/boxes/iso-base-media/stsd/ctts.js +30 -0
  30. package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +11 -0
  31. package/dist/boxes/iso-base-media/stsd/hvcc.js +17 -0
  32. package/dist/boxes/iso-base-media/stsd/keys.js +1 -0
  33. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +4 -2
  34. package/dist/boxes/iso-base-media/stsd/mebx.js +4 -2
  35. package/dist/boxes/iso-base-media/stsd/pasp.d.ts +12 -0
  36. package/dist/boxes/iso-base-media/stsd/pasp.js +17 -0
  37. package/dist/boxes/iso-base-media/stsd/samples.d.ts +12 -5
  38. package/dist/boxes/iso-base-media/stsd/samples.js +27 -10
  39. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +4 -2
  40. package/dist/boxes/iso-base-media/stsd/stsd.js +6 -2
  41. package/dist/boxes/iso-base-media/stsd/stss.d.ts +13 -0
  42. package/dist/boxes/iso-base-media/stsd/stss.js +28 -0
  43. package/dist/boxes/iso-base-media/stsd/stsz.d.ts +9 -3
  44. package/dist/boxes/iso-base-media/stsd/stsz.js +14 -2
  45. package/dist/boxes/iso-base-media/stsd/stts.d.ts +15 -0
  46. package/dist/boxes/iso-base-media/stsd/stts.js +35 -0
  47. package/dist/boxes/iso-base-media/tkhd.d.ts +3 -0
  48. package/dist/boxes/iso-base-media/tkhd.js +41 -14
  49. package/dist/boxes/iso-base-media/trak/trak.d.ts +4 -2
  50. package/dist/boxes/iso-base-media/trak/trak.js +4 -2
  51. package/dist/boxes/iso-base-media/void-box.d.ts +4 -0
  52. package/dist/boxes/iso-base-media/void-box.js +2 -0
  53. package/dist/boxes/webm/allowed-partial-segments.d.ts +1 -0
  54. package/dist/boxes/webm/allowed-partial-segments.js +4 -0
  55. package/dist/boxes/webm/av1-codec-private.d.ts +2 -0
  56. package/dist/boxes/webm/av1-codec-private.js +95 -0
  57. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.d.ts +14 -0
  58. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.js +67 -0
  59. package/dist/boxes/webm/bitstream/av1/bitstream-frame.d.ts +11 -0
  60. package/dist/boxes/webm/bitstream/av1/bitstream-frame.js +14 -0
  61. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.d.ts +6 -0
  62. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.js +9 -0
  63. package/dist/boxes/webm/bitstream/av1/color-config.d.ts +16 -0
  64. package/dist/boxes/webm/bitstream/av1/color-config.js +103 -0
  65. package/dist/boxes/webm/bitstream/av1/color-primaries.d.ts +14 -0
  66. package/dist/boxes/webm/bitstream/av1/color-primaries.js +17 -0
  67. package/dist/boxes/webm/bitstream/av1/decoder-model-info.d.ts +9 -0
  68. package/dist/boxes/webm/bitstream/av1/decoder-model-info.js +17 -0
  69. package/dist/boxes/webm/bitstream/av1/header-segment.d.ts +51 -0
  70. package/dist/boxes/webm/bitstream/av1/header-segment.js +183 -0
  71. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.d.ts +17 -0
  72. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.js +20 -0
  73. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.d.ts +10 -0
  74. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.js +15 -0
  75. package/dist/boxes/webm/bitstream/av1/temporal-point-info.d.ts +5 -0
  76. package/dist/boxes/webm/bitstream/av1/temporal-point-info.js +8 -0
  77. package/dist/boxes/webm/bitstream/av1/timing-info.d.ts +8 -0
  78. package/dist/boxes/webm/bitstream/av1/timing-info.js +20 -0
  79. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.d.ts +21 -0
  80. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.js +24 -0
  81. package/dist/boxes/webm/bitstream/av1/uvlc.d.ts +2 -0
  82. package/dist/boxes/webm/bitstream/av1/uvlc.js +20 -0
  83. package/dist/boxes/webm/bitstream/av1.d.ts +20 -0
  84. package/dist/boxes/webm/bitstream/av1.js +118 -0
  85. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.d.ts +0 -0
  86. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.js +1 -0
  87. package/dist/boxes/webm/description.d.ts +2 -0
  88. package/dist/boxes/webm/description.js +83 -0
  89. package/dist/boxes/webm/get-ready-tracks.d.ts +3 -0
  90. package/dist/boxes/webm/get-ready-tracks.js +29 -0
  91. package/dist/boxes/webm/get-track.d.ts +6 -0
  92. package/dist/boxes/webm/get-track.js +183 -0
  93. package/dist/boxes/webm/parse-webm-header.d.ts +2 -1
  94. package/dist/boxes/webm/parse-webm-header.js +2 -2
  95. package/dist/boxes/webm/segments/all-segments.d.ts +269 -0
  96. package/dist/boxes/webm/segments/all-segments.js +277 -0
  97. package/dist/boxes/webm/segments/duration.d.ts +1 -1
  98. package/dist/boxes/webm/segments/duration.js +13 -9
  99. package/dist/boxes/webm/segments/info.d.ts +2 -1
  100. package/dist/boxes/webm/segments/info.js +12 -4
  101. package/dist/boxes/webm/segments/main.d.ts +0 -2
  102. package/dist/boxes/webm/segments/main.js +0 -11
  103. package/dist/boxes/webm/segments/muxing.d.ts +1 -1
  104. package/dist/boxes/webm/segments/muxing.js +1 -2
  105. package/dist/boxes/webm/segments/parse-children.d.ts +11 -1
  106. package/dist/boxes/webm/segments/parse-children.js +82 -6
  107. package/dist/boxes/webm/segments/seek-head.d.ts +2 -1
  108. package/dist/boxes/webm/segments/seek-head.js +12 -3
  109. package/dist/boxes/webm/segments/seek-position.d.ts +1 -1
  110. package/dist/boxes/webm/segments/seek-position.js +1 -2
  111. package/dist/boxes/webm/segments/seek.d.ts +7 -2
  112. package/dist/boxes/webm/segments/seek.js +22 -9
  113. package/dist/boxes/webm/segments/track-entry.d.ts +102 -22
  114. package/dist/boxes/webm/segments/track-entry.js +269 -57
  115. package/dist/boxes/webm/segments/tracks.d.ts +2 -1
  116. package/dist/boxes/webm/segments/tracks.js +12 -4
  117. package/dist/boxes/webm/segments/void.d.ts +1 -1
  118. package/dist/boxes/webm/segments/void.js +1 -2
  119. package/dist/boxes/webm/segments/writing.d.ts +1 -1
  120. package/dist/boxes/webm/segments/writing.js +1 -2
  121. package/dist/boxes/webm/segments.d.ts +8 -4
  122. package/dist/boxes/webm/segments.js +176 -40
  123. package/dist/boxes/webm/traversal.d.ts +7 -0
  124. package/dist/boxes/webm/traversal.js +25 -0
  125. package/dist/buffer-iterator.d.ts +15 -1
  126. package/dist/buffer-iterator.js +115 -46
  127. package/dist/combine-uint8array.d.ts +1 -0
  128. package/dist/combine-uint8array.js +13 -0
  129. package/dist/from-fetch.d.ts +2 -0
  130. package/dist/from-fetch.js +54 -0
  131. package/dist/from-node.js +6 -0
  132. package/dist/from-web-file.d.ts +2 -0
  133. package/dist/from-web-file.js +34 -0
  134. package/dist/from-web.js +6 -9
  135. package/dist/get-audio-codec.d.ts +19 -0
  136. package/dist/get-audio-codec.js +153 -60
  137. package/dist/get-dimensions.d.ts +8 -2
  138. package/dist/get-dimensions.js +13 -91
  139. package/dist/get-duration.js +4 -7
  140. package/dist/get-fps.d.ts +4 -3
  141. package/dist/get-fps.js +17 -116
  142. package/dist/get-sample-aspect-ratio.d.ts +37 -0
  143. package/dist/get-sample-aspect-ratio.js +137 -0
  144. package/dist/get-sample-positions.d.ts +11 -1
  145. package/dist/get-sample-positions.js +31 -2
  146. package/dist/get-tracks.d.ts +44 -5
  147. package/dist/get-tracks.js +66 -48
  148. package/dist/get-video-codec.d.ts +2 -0
  149. package/dist/get-video-codec.js +47 -31
  150. package/dist/get-video-metadata.d.ts +2 -0
  151. package/dist/get-video-metadata.js +44 -0
  152. package/dist/has-all-info.d.ts +2 -1
  153. package/dist/has-all-info.js +14 -5
  154. package/dist/index.d.ts +1 -0
  155. package/dist/make-hvc1-codec-strings.d.ts +2 -0
  156. package/dist/make-hvc1-codec-strings.js +47 -0
  157. package/dist/options.d.ts +26 -4
  158. package/dist/parse-media.js +62 -17
  159. package/dist/parse-result.d.ts +16 -5
  160. package/dist/parse-video.d.ts +11 -2
  161. package/dist/parse-video.js +14 -6
  162. package/dist/parser-context.d.ts +8 -0
  163. package/dist/parser-context.js +2 -0
  164. package/dist/parser-state.d.ts +23 -0
  165. package/dist/parser-state.js +112 -0
  166. package/dist/read-and-increment-offset.d.ts +28 -0
  167. package/dist/read-and-increment-offset.js +177 -0
  168. package/dist/reader.d.ts +2 -2
  169. package/dist/traversal.d.ts +37 -0
  170. package/dist/traversal.js +244 -1
  171. package/dist/understand-vorbis.d.ts +1 -0
  172. package/dist/understand-vorbis.js +12 -0
  173. package/dist/webcodec-sample-types.d.ts +21 -0
  174. package/dist/webcodec-sample-types.js +2 -0
  175. package/package.json +10 -2
  176. package/src/add-new-matroska-tracks.ts +23 -0
  177. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +61 -0
  178. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +33 -2
  179. package/src/boxes/iso-base-media/make-track.ts +157 -0
  180. package/src/boxes/iso-base-media/mdat/mdat.ts +131 -0
  181. package/src/boxes/iso-base-media/moov/moov.ts +8 -3
  182. package/src/boxes/iso-base-media/mvhd.ts +7 -1
  183. package/src/boxes/iso-base-media/process-box.ts +388 -38
  184. package/src/boxes/iso-base-media/stsd/av1c.ts +19 -0
  185. package/src/boxes/iso-base-media/stsd/avcc.ts +36 -0
  186. package/src/boxes/iso-base-media/stsd/colr.ts +49 -0
  187. package/src/boxes/iso-base-media/stsd/ctts.ts +55 -0
  188. package/src/boxes/iso-base-media/stsd/hvcc.ts +32 -0
  189. package/src/boxes/iso-base-media/stsd/keys.ts +2 -0
  190. package/src/boxes/iso-base-media/stsd/mebx.ts +8 -3
  191. package/src/boxes/iso-base-media/stsd/pasp.ts +32 -0
  192. package/src/boxes/iso-base-media/stsd/samples.ts +43 -16
  193. package/src/boxes/iso-base-media/stsd/stco.ts +50 -0
  194. package/src/boxes/iso-base-media/stsd/stsc.ts +61 -0
  195. package/src/boxes/iso-base-media/stsd/stsd.ts +10 -3
  196. package/src/boxes/iso-base-media/stsd/stss.ts +47 -0
  197. package/src/boxes/iso-base-media/stsd/stsz.ts +75 -0
  198. package/src/boxes/iso-base-media/tkhd.ts +63 -16
  199. package/src/boxes/iso-base-media/trak/trak.ts +8 -3
  200. package/src/boxes/iso-base-media/void-box.ts +4 -0
  201. package/src/boxes/webm/allowed-partial-segments.ts +1 -0
  202. package/src/boxes/webm/av1-codec-private.ts +113 -0
  203. package/src/boxes/webm/description.ts +101 -0
  204. package/src/boxes/webm/get-ready-tracks.ts +36 -0
  205. package/src/boxes/webm/get-track.ts +250 -0
  206. package/src/boxes/webm/parse-webm-header.ts +6 -2
  207. package/src/boxes/webm/segments/all-segments.ts +285 -0
  208. package/src/boxes/webm/segments/duration.ts +15 -8
  209. package/src/boxes/webm/segments/info.ts +18 -4
  210. package/src/boxes/webm/segments/main.ts +0 -13
  211. package/src/boxes/webm/segments/muxing.ts +1 -1
  212. package/src/boxes/webm/segments/parse-children.ts +132 -9
  213. package/src/boxes/webm/segments/seek-head.ts +17 -4
  214. package/src/boxes/webm/segments/seek-position.ts +1 -2
  215. package/src/boxes/webm/segments/seek.ts +31 -9
  216. package/src/boxes/webm/segments/track-entry.ts +475 -65
  217. package/src/boxes/webm/segments/tracks.ts +17 -7
  218. package/src/boxes/webm/segments/void.ts +4 -2
  219. package/src/boxes/webm/segments/writing.ts +1 -1
  220. package/src/boxes/webm/segments.ts +266 -42
  221. package/src/boxes/webm/traversal.ts +32 -0
  222. package/src/buffer-iterator.ts +140 -45
  223. package/src/combine-uint8array.ts +13 -0
  224. package/src/{from-web.ts → from-fetch.ts} +9 -1
  225. package/src/from-node.ts +8 -0
  226. package/src/from-web-file.ts +39 -0
  227. package/src/get-audio-codec.ts +213 -84
  228. package/src/get-dimensions.ts +25 -132
  229. package/src/get-duration.ts +4 -8
  230. package/src/get-fps.ts +27 -172
  231. package/src/get-sample-aspect-ratio.ts +204 -0
  232. package/src/get-sample-positions.ts +93 -0
  233. package/src/get-tracks.ts +147 -0
  234. package/src/get-video-codec.ts +62 -47
  235. package/src/has-all-info.ts +35 -5
  236. package/src/index.ts +8 -0
  237. package/src/make-hvc1-codec-strings.ts +55 -0
  238. package/src/options.ts +48 -9
  239. package/src/parse-media.ts +90 -21
  240. package/src/parse-result.ts +28 -4
  241. package/src/parse-video.ts +30 -7
  242. package/src/parser-context.ts +9 -0
  243. package/src/parser-state.ts +151 -0
  244. package/src/reader.ts +2 -2
  245. package/src/test/aspect-ratio.test.ts +42 -0
  246. package/src/test/av1.test.ts +108 -0
  247. package/src/test/duration.test.ts +5 -21
  248. package/src/test/matroska.test.ts +350 -31
  249. package/src/test/mvhd.test.ts +6 -1
  250. package/src/test/parse-esds.test.ts +29 -6
  251. package/src/test/parse-stco.test.ts +59 -0
  252. package/src/test/parse-stsc.test.ts +104 -0
  253. package/src/test/parse-stsz.test.ts +57 -0
  254. package/src/test/parse-stts.test.ts +1 -1
  255. package/src/test/parse-video.test.ts +23 -35
  256. package/src/test/parse-webm.test.ts +5 -5
  257. package/src/test/stream-local.test.ts +542 -46
  258. package/src/test/stream-remote.test.ts +15 -13
  259. package/src/test/stream-samples.test.ts +259 -0
  260. package/src/test/stsd.test.ts +60 -8
  261. package/src/test/tkhd.test.ts +4 -1
  262. package/src/traversal.ts +496 -0
  263. package/src/webcodec-sample-types.ts +30 -0
  264. package/tsconfig.json +5 -1
  265. package/tsconfig.tsbuildinfo +1 -1
  266. package/boxes.json +0 -1
  267. package/dist/boxes/iso-base-media/esds-descriptors.d.ts +0 -21
  268. package/dist/boxes/iso-base-media/esds-descriptors.js +0 -62
  269. package/dist/boxes/iso-base-media/esds.d.ts +0 -15
  270. package/dist/boxes/iso-base-media/esds.js +0 -27
  271. package/dist/get-codec.d.ts +0 -4
  272. package/dist/get-codec.js +0 -22
  273. /package/dist/{get-samples.d.ts → boxes/webm/bitstream/av1/frame.d.ts} +0 -0
  274. /package/dist/{get-samples.js → boxes/webm/bitstream/av1/frame.js} +0 -0
  275. /package/src/boxes/iso-base-media/{stts → stsd}/stts.ts +0 -0
@@ -0,0 +1,8 @@
1
+ import type { Track } from './get-tracks';
2
+ import type { ParserContext } from './parser-context';
3
+ import type { ParserState } from './parser-state';
4
+ export declare const registerTrack: ({ state, options, track, }: {
5
+ state: ParserState;
6
+ options: ParserContext;
7
+ track: Track;
8
+ }) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerTrack = void 0;
4
+ const registerTrack = async ({ state, options, track, }) => {
5
+ if (track.type === 'video' && options.onVideoTrack) {
6
+ const callback = await options.onVideoTrack(track);
7
+ await state.registerVideoSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
8
+ }
9
+ if (track.type === 'audio' && options.onAudioTrack) {
10
+ const callback = await options.onAudioTrack(track);
11
+ await state.registerAudioSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
12
+ }
13
+ };
14
+ exports.registerTrack = registerTrack;
@@ -0,0 +1,3 @@
1
+ import type { ColorParameterBox } from './boxes/iso-base-media/stsd/colr';
2
+ import type { Av1BitstreamHeaderSegment } from './boxes/webm/bitstream/av1/header-segment';
3
+ export declare const constructAv1CodecString: (av1BitstreamHeader: Av1BitstreamHeaderSegment, colrAtom: ColorParameterBox | null) => string;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ // https://aomediacodec.github.io/av1-isobmff/#codecsparam
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.constructAv1CodecString = void 0;
5
+ const constructAv1CodecString = (av1BitstreamHeader, colrAtom) => {
6
+ let str = 'av01.';
7
+ // Profile
8
+ str += av1BitstreamHeader.seq_profile;
9
+ str += '.';
10
+ // Level
11
+ // The level parameter value SHALL equal the first level value indicated by seq_level_idx in the Sequence Header OBU
12
+ str += av1BitstreamHeader.seq_level[0].seq_level_idx
13
+ .toString()
14
+ .padStart(2, '0');
15
+ // Tier
16
+ // The tier parameter value SHALL be equal to M when the first seq_tier value in the Sequence Header OBU is equal to 0, and H when it is equal to 1
17
+ str += av1BitstreamHeader.seq_level[0].seq_tier ? 'H' : 'M';
18
+ str += '.';
19
+ // bitDepth
20
+ // The bitDepth parameter value SHALL equal the value of BitDepth variable as defined in [AV1] derived from the Sequence Header OBU
21
+ str += av1BitstreamHeader.color_config.bitDepth.toString().padStart(2, '0');
22
+ str += '.';
23
+ // monochrome
24
+ // The monochrome parameter value, represented by a single digit decimal, SHALL equal the value of mono_chrome in the Sequence Header OBU
25
+ str += av1BitstreamHeader.color_config.mono_chrome ? '1' : '0';
26
+ str += '.';
27
+ // The chromaSubsampling parameter value, represented by a three-digit decimal,
28
+ // SHALL have its first digit equal to subsampling_x
29
+ str += av1BitstreamHeader.color_config.subsampling_x ? '1' : '0';
30
+ // and its second digit equal to subsampling_y.
31
+ str += av1BitstreamHeader.color_config.subsampling_y ? '1' : '0';
32
+ // If both subsampling_x and subsampling_y are set to 1, then the third digit SHALL be equal to chroma_sample_position, otherwise it SHALL be set to 0
33
+ str +=
34
+ av1BitstreamHeader.color_config.subsampling_x &&
35
+ av1BitstreamHeader.color_config.subsampling_y
36
+ ? av1BitstreamHeader.color_config.chroma_sample_position === 1
37
+ ? '1'
38
+ : '0'
39
+ : '0';
40
+ str += '.';
41
+ // The colorPrimaries, transferCharacteristics, matrixCoefficients, and videoFullRangeFlag parameter values are set as follows:
42
+ // If a colr box with colour_type set to nclx is present, the colorPrimaries, transferCharacteristics, matrixCoefficients, and videoFullRangeFlag parameter values SHALL equal the values of matching fields in the colr box.
43
+ if (colrAtom) {
44
+ str += colrAtom.primaries.toString().padStart(2, '0');
45
+ str += '.';
46
+ str += colrAtom.transfer.toString().padStart(2, '0');
47
+ str += '.';
48
+ str += colrAtom.matrixIndex.toString().padStart(2, '0');
49
+ str += '.';
50
+ str += colrAtom.fullRangeFlag ? '1' : '0';
51
+ }
52
+ // Otherwise, a colr box with colour_type set to nclx is absent.
53
+ // If the color_description_present_flag is set to 1 in the Sequence Header OBU, the colorPrimaries, transferCharacteristics, and matrixCoefficients parameter values SHALL equal the values of matching fields in the Sequence Header OBU.
54
+ else if (av1BitstreamHeader.color_config.color_description_present_flag) {
55
+ str += av1BitstreamHeader.color_config.color_primaries
56
+ .toString()
57
+ .padStart(2, '0');
58
+ str += '.';
59
+ str += av1BitstreamHeader.color_config.transfer_characteristics
60
+ .toString()
61
+ .padStart(2, '0');
62
+ str += '.';
63
+ str += av1BitstreamHeader.color_config.matrix_coefficients
64
+ .toString()
65
+ .padStart(2, '0');
66
+ str += '.';
67
+ // The videoFullRangeFlag parameter value SHALL equal the color_range flag in the Sequence Header OBU.
68
+ str += av1BitstreamHeader.color_config.color_range ? '1' : '0';
69
+ }
70
+ else {
71
+ // Otherwise, the color_description_present_flag is set to 0 in the Sequence Header OBU. The colorPrimaries, transferCharacteristics, and matrixCoefficients parameter values SHOULD be set to the default values below.
72
+ // colorPrimaries 01 (ITU-R BT.709)
73
+ str += '01';
74
+ str += '.';
75
+ // transferCharacteristics 01 (ITU-R BT.709)
76
+ str += '01';
77
+ str += '.';
78
+ // matrixCoefficients 00 (ITU-R BT.709)
79
+ str += '01';
80
+ str += '.';
81
+ // videoFullRangeFlag 0 (studio swing representation)
82
+ str += '0';
83
+ }
84
+ // If the codecs parameter string ends with ".0.110.01.01.01.0" (containing all the default values below), that trailing part of the string SHOULD be omitted.
85
+ const suffix = '.0.110.01.01.01.0';
86
+ if (str.endsWith(suffix)) {
87
+ str = str.slice(0, -suffix.length);
88
+ }
89
+ return str;
90
+ };
91
+ exports.constructAv1CodecString = constructAv1CodecString;
@@ -0,0 +1,14 @@
1
+ import type { BufferIterator } from '../../../buffer-iterator';
2
+ type UnknownDecoderSpecificConfig = {
3
+ type: 'unknown-decoder-specific-config';
4
+ };
5
+ type AudioSpecificConfig = {
6
+ type: 'audio-specific-config';
7
+ audioObjectType: number;
8
+ samplingFrequencyIndex: number;
9
+ channelConfiguration: number;
10
+ asBytes: Uint8Array;
11
+ };
12
+ export type DecoderSpecificConfig = UnknownDecoderSpecificConfig | AudioSpecificConfig;
13
+ export declare const parseDecoderSpecificConfig: (iterator: BufferIterator) => DecoderSpecificConfig;
14
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDecoderSpecificConfig = void 0;
4
+ const parseDecoderSpecificConfig = (iterator) => {
5
+ const layerTag = iterator.getUint8();
6
+ const layerSize = iterator.getPaddedFourByteNumber();
7
+ const start = iterator.counter.getOffset();
8
+ if (layerTag !== 5) {
9
+ iterator.discard(layerSize);
10
+ return {
11
+ type: 'unknown-decoder-specific-config',
12
+ };
13
+ }
14
+ // https://csclub.uwaterloo.ca/~pbarfuss/ISO14496-3-2009.pdf
15
+ // 1.6.2.1 AudioSpecificConfig
16
+ const bytes = iterator.getSlice(layerSize);
17
+ iterator.counter.decrement(layerSize);
18
+ iterator.startReadingBits();
19
+ const audioObjectType = iterator.getBits(5);
20
+ const samplingFrequencyIndex = iterator.getBits(4);
21
+ if (samplingFrequencyIndex === 0xf) {
22
+ iterator.getBits(24);
23
+ }
24
+ const channelConfiguration = iterator.getBits(4);
25
+ iterator.stopReadingBits();
26
+ const read = iterator.counter.getOffset() - start;
27
+ if (read < layerSize) {
28
+ iterator.discard(layerSize - read);
29
+ }
30
+ return {
31
+ type: 'audio-specific-config',
32
+ audioObjectType,
33
+ samplingFrequencyIndex,
34
+ channelConfiguration,
35
+ asBytes: bytes,
36
+ };
37
+ };
38
+ exports.parseDecoderSpecificConfig = parseDecoderSpecificConfig;
@@ -1,8 +1,16 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
+ import type { DecoderSpecificConfig } from './decoder-specific-config';
2
3
  type AudioObjectType = 'aac' | 'mp3' | 'unknown';
3
4
  type DecoderConfigDescriptor = {
4
5
  type: 'decoder-config-descriptor';
5
6
  objectTypeIndication: AudioObjectType;
7
+ asNumber: number;
8
+ streamType: number;
9
+ upStream: number;
10
+ bufferSizeDB: number;
11
+ maxBitrate: number;
12
+ avgBitrate: number;
13
+ decoderSpecificConfigs: DecoderSpecificConfig[];
6
14
  };
7
15
  type SlConfigDescriptor = {
8
16
  type: 'sl-config-descriptor';
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseDescriptors = exports.processDescriptor = void 0;
4
+ const decoder_specific_config_1 = require("./decoder-specific-config");
4
5
  const mapToObjectAudioIndicator = (num) => {
5
6
  // https://chromium.googlesource.com/chromium/src/media/+/master/formats/mp4/es_descriptor.h
6
7
  // http://netmedia.zju.edu.cn/multimedia2013/mpeg-4/ISO%20IEC%2014496-1%20MPEG-4%20System%20Standard.pdf
@@ -19,12 +20,31 @@ const processDescriptor = ({ iterator, }) => {
19
20
  const size = iterator.getPaddedFourByteNumber();
20
21
  const initialOffset = iterator.counter.getOffset();
21
22
  const objectTypeIndication = iterator.getUint8();
22
- const remaining = size - (iterator.counter.getOffset() - initialOffset);
23
- iterator.discard(remaining);
23
+ iterator.startReadingBits();
24
+ const streamType = iterator.getBits(6);
25
+ const upStream = iterator.getBits(1);
26
+ // reserved
27
+ iterator.getBits(1);
28
+ const bufferSizeDB = iterator.getBits(24);
29
+ iterator.stopReadingBits();
30
+ const maxBitrate = iterator.getUint32();
31
+ const avgBitrate = iterator.getUint32();
32
+ const decoderSpecificConfigs = [];
33
+ while (size - (iterator.counter.getOffset() - initialOffset) >= 0) {
34
+ const decoderSpecificConfig = (0, decoder_specific_config_1.parseDecoderSpecificConfig)(iterator);
35
+ decoderSpecificConfigs.push(decoderSpecificConfig);
36
+ }
24
37
  return {
25
38
  descriptor: {
26
39
  type: 'decoder-config-descriptor',
27
40
  objectTypeIndication: mapToObjectAudioIndicator(objectTypeIndication),
41
+ asNumber: objectTypeIndication,
42
+ bufferSizeDB,
43
+ streamType,
44
+ upStream,
45
+ avgBitrate,
46
+ maxBitrate,
47
+ decoderSpecificConfigs,
28
48
  },
29
49
  };
30
50
  }
@@ -0,0 +1,9 @@
1
+ import type { BaseBox } from './base-type';
2
+ export interface FtypBox extends BaseBox {
3
+ type: 'ftyp-box';
4
+ majorBrand: string;
5
+ minorVersion: number;
6
+ compatibleBrands: string[];
7
+ }
8
+ export declare const fourByteToNumber: (data: ArrayBuffer, from: number) => number;
9
+ export declare const parseFtyp: (data: ArrayBuffer, offset: number) => FtypBox;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFtyp = exports.fourByteToNumber = void 0;
4
+ const fourByteToNumber = (data, from) => {
5
+ const view = new DataView(data);
6
+ return ((view.getUint8(from + 0) << 24) |
7
+ (view.getUint8(from + 1) << 16) |
8
+ (view.getUint8(from + 2) << 8) |
9
+ view.getUint8(from + 3));
10
+ };
11
+ exports.fourByteToNumber = fourByteToNumber;
12
+ const parseFtyp = (data, offset) => {
13
+ const majorBrand = new TextDecoder().decode(data.slice(8, 12)).trim();
14
+ const minorVersion = (0, exports.fourByteToNumber)(data, 12);
15
+ const rest = data.slice(16);
16
+ const types = rest.byteLength / 4;
17
+ const compatibleBrands = [];
18
+ for (let i = 0; i < types; i++) {
19
+ const fourBytes = rest.slice(i * 4, i * 4 + 4);
20
+ compatibleBrands.push(new TextDecoder().decode(fourBytes).trim());
21
+ }
22
+ return {
23
+ type: 'ftyp-box',
24
+ majorBrand,
25
+ minorVersion,
26
+ compatibleBrands,
27
+ offset,
28
+ boxSize: data.byteLength,
29
+ };
30
+ };
31
+ exports.parseFtyp = parseFtyp;
@@ -0,0 +1,3 @@
1
+ import type { AudioTrack, OtherTrack, VideoTrack } from '../../get-tracks';
2
+ import type { TrakBox } from './trak/trak';
3
+ export declare const makeBaseMediaTrack: (trakBox: TrakBox) => VideoTrack | AudioTrack | OtherTrack | null;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBaseMediaTrack = void 0;
4
+ const get_audio_codec_1 = require("../../get-audio-codec");
5
+ const get_fps_1 = require("../../get-fps");
6
+ const get_sample_aspect_ratio_1 = require("../../get-sample-aspect-ratio");
7
+ const get_sample_positions_1 = require("../../get-sample-positions");
8
+ const get_video_codec_1 = require("../../get-video-codec");
9
+ const traversal_1 = require("../../traversal");
10
+ const makeBaseMediaTrack = (trakBox) => {
11
+ const stszBox = (0, traversal_1.getStszBox)(trakBox);
12
+ const stcoBox = (0, traversal_1.getStcoBox)(trakBox);
13
+ const stscBox = (0, traversal_1.getStscBox)(trakBox);
14
+ const stssBox = (0, traversal_1.getStssBox)(trakBox);
15
+ const sttsBox = (0, traversal_1.getSttsBox)(trakBox);
16
+ const tkhdBox = (0, traversal_1.getTkhdBox)(trakBox);
17
+ const cttsBox = (0, traversal_1.getCttsBox)(trakBox);
18
+ const videoDescriptors = (0, traversal_1.getVideoDescriptors)(trakBox);
19
+ const timescaleAndDuration = (0, get_fps_1.getTimescaleAndDuration)(trakBox);
20
+ if (!tkhdBox) {
21
+ throw new Error('Expected tkhd box in trak box');
22
+ }
23
+ if (!stszBox) {
24
+ throw new Error('Expected stsz box in trak box');
25
+ }
26
+ if (!stcoBox) {
27
+ throw new Error('Expected stco box in trak box');
28
+ }
29
+ if (!stscBox) {
30
+ throw new Error('Expected stsc box in trak box');
31
+ }
32
+ if (!sttsBox) {
33
+ throw new Error('Expected stts box in trak box');
34
+ }
35
+ if (!timescaleAndDuration) {
36
+ throw new Error('Expected timescale and duration in trak box');
37
+ }
38
+ const samplePositions = (0, get_sample_positions_1.getSamplePositions)({
39
+ stcoBox,
40
+ stscBox,
41
+ stszBox,
42
+ stssBox,
43
+ sttsBox,
44
+ cttsBox,
45
+ });
46
+ if ((0, get_fps_1.trakBoxContainsAudio)(trakBox)) {
47
+ const numberOfChannels = (0, get_audio_codec_1.getNumberOfChannelsFromTrak)(trakBox);
48
+ if (numberOfChannels === null) {
49
+ throw new Error('Could not find number of channels');
50
+ }
51
+ const sampleRate = (0, get_audio_codec_1.getSampleRate)(trakBox);
52
+ if (sampleRate === null) {
53
+ throw new Error('Could not find sample rate');
54
+ }
55
+ const { codecString, description } = (0, get_audio_codec_1.getAudioCodecStringFromTrak)(trakBox);
56
+ return {
57
+ type: 'audio',
58
+ samplePositions,
59
+ trackId: tkhdBox.trackId,
60
+ timescale: timescaleAndDuration.timescale,
61
+ codec: codecString,
62
+ numberOfChannels,
63
+ sampleRate,
64
+ description,
65
+ };
66
+ }
67
+ if (!(0, get_fps_1.trakBoxContainsVideo)(trakBox)) {
68
+ return {
69
+ type: 'other',
70
+ samplePositions,
71
+ trackId: tkhdBox.trackId,
72
+ timescale: timescaleAndDuration.timescale,
73
+ };
74
+ }
75
+ const videoSample = (0, get_sample_aspect_ratio_1.getVideoSample)(trakBox);
76
+ if (!videoSample) {
77
+ throw new Error('No video sample');
78
+ }
79
+ const sampleAspectRatio = (0, get_sample_aspect_ratio_1.getSampleAspectRatio)(trakBox);
80
+ const aspectRatioApplied = (0, get_sample_aspect_ratio_1.applyAspectRatios)({
81
+ dimensions: videoSample,
82
+ sampleAspectRatio,
83
+ displayAspectRatio: (0, get_sample_aspect_ratio_1.getDisplayAspectRatio)({
84
+ sampleAspectRatio,
85
+ nativeDimensions: videoSample,
86
+ }),
87
+ });
88
+ const { displayAspectHeight, displayAspectWidth, height, rotation, width } = (0, get_sample_aspect_ratio_1.applyTkhdBox)(aspectRatioApplied, tkhdBox);
89
+ const codec = (0, get_video_codec_1.getVideoCodecString)(trakBox);
90
+ if (!codec) {
91
+ throw new Error('Could not find video codec');
92
+ }
93
+ const track = {
94
+ type: 'video',
95
+ samplePositions,
96
+ trackId: tkhdBox.trackId,
97
+ description: videoDescriptors !== null && videoDescriptors !== void 0 ? videoDescriptors : undefined,
98
+ timescale: timescaleAndDuration.timescale,
99
+ codec,
100
+ sampleAspectRatio: (0, get_sample_aspect_ratio_1.getSampleAspectRatio)(trakBox),
101
+ width,
102
+ height,
103
+ codedWidth: videoSample.width,
104
+ codedHeight: videoSample.height,
105
+ // Repeating those keys because they get picked up by VideoDecoder
106
+ displayAspectWidth,
107
+ displayAspectHeight,
108
+ rotation,
109
+ };
110
+ return track;
111
+ };
112
+ exports.makeBaseMediaTrack = makeBaseMediaTrack;
@@ -1,12 +1,16 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { AnySegment } from '../../../parse-result';
3
+ import type { ParserContext } from '../../../parser-context';
3
4
  export interface MdatBox {
4
5
  type: 'mdat-box';
6
+ samplesProcessed: boolean;
5
7
  boxSize: number;
8
+ fileOffset: number;
6
9
  }
7
- export declare const parseMdat: ({ data, size, fileOffset, }: {
10
+ export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, options, }: {
8
11
  data: BufferIterator;
9
12
  size: number;
10
13
  fileOffset: number;
11
14
  existingBoxes: AnySegment[];
12
- }) => MdatBox;
15
+ options: ParserContext;
16
+ }) => Promise<MdatBox>;
@@ -1,13 +1,97 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMdat = void 0;
4
- const parseMdat = ({ data, size, fileOffset, }) => {
5
- // TODO: Do something cool with it
6
- // const tracks = getTracks(existingBoxes);
7
- data.discard(size - (data.counter.getOffset() - fileOffset));
8
- return {
4
+ const get_tracks_1 = require("../../../get-tracks");
5
+ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, }) => {
6
+ const alreadyHas = (0, get_tracks_1.hasTracks)(existingBoxes);
7
+ if (!alreadyHas) {
8
+ data.discard(size - 8);
9
+ return Promise.resolve({
10
+ type: 'mdat-box',
11
+ boxSize: size,
12
+ samplesProcessed: false,
13
+ fileOffset,
14
+ });
15
+ }
16
+ const tracks = (0, get_tracks_1.getTracks)(existingBoxes, options.parserState);
17
+ const allTracks = [
18
+ ...tracks.videoTracks,
19
+ ...tracks.audioTracks,
20
+ ...tracks.otherTracks,
21
+ ];
22
+ const flatSamples = allTracks
23
+ .map((track) => {
24
+ if (!track.samplePositions) {
25
+ throw new Error('No sample positions');
26
+ }
27
+ return track.samplePositions.map((samplePosition) => {
28
+ return {
29
+ track,
30
+ samplePosition,
31
+ };
32
+ });
33
+ })
34
+ .flat(1);
35
+ // eslint-disable-next-line no-constant-condition
36
+ while (true) {
37
+ const sampleWithIndex = flatSamples.find((sample) => {
38
+ return sample.samplePosition.offset === data.counter.getOffset();
39
+ });
40
+ if (!sampleWithIndex) {
41
+ // There are various reasons why in mdat we find weird stuff:
42
+ // - iphonevideo.hevc has a fake hoov atom which is not mapped
43
+ // - corrupted.mp4 has a corrupt table
44
+ const nextSample_ = flatSamples
45
+ .filter((s) => s.samplePosition.offset > data.counter.getOffset())
46
+ .sort((a, b) => a.samplePosition.offset - b.samplePosition.offset)[0];
47
+ if (nextSample_) {
48
+ data.discard(nextSample_.samplePosition.offset - data.counter.getOffset());
49
+ continue;
50
+ }
51
+ else {
52
+ const bytesRemaining = size + fileOffset - data.counter.getOffset();
53
+ data.discard(bytesRemaining);
54
+ break;
55
+ }
56
+ }
57
+ if (data.bytesRemaining() < sampleWithIndex.samplePosition.size) {
58
+ break;
59
+ }
60
+ const bytes = data.getSlice(sampleWithIndex.samplePosition.size);
61
+ if (sampleWithIndex.track.type === 'audio') {
62
+ await options.parserState.onAudioSample(sampleWithIndex.track.trackId, {
63
+ data: bytes,
64
+ timestamp: sampleWithIndex.samplePosition.offset,
65
+ offset: data.counter.getOffset(),
66
+ trackId: sampleWithIndex.track.trackId,
67
+ type: sampleWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
68
+ });
69
+ }
70
+ if (sampleWithIndex.track.type === 'video') {
71
+ const timestamp = (sampleWithIndex.samplePosition.cts * 1000000) /
72
+ sampleWithIndex.track.timescale;
73
+ const duration = (sampleWithIndex.samplePosition.duration * 1000000) /
74
+ sampleWithIndex.track.timescale;
75
+ await options.parserState.onVideoSample(sampleWithIndex.track.trackId, {
76
+ data: bytes,
77
+ timestamp,
78
+ duration,
79
+ cts: sampleWithIndex.samplePosition.cts,
80
+ dts: sampleWithIndex.samplePosition.dts,
81
+ trackId: sampleWithIndex.track.trackId,
82
+ type: sampleWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
83
+ });
84
+ }
85
+ const remaining = size - (data.counter.getOffset() - fileOffset);
86
+ if (remaining === 0) {
87
+ break;
88
+ }
89
+ }
90
+ return Promise.resolve({
9
91
  type: 'mdat-box',
10
92
  boxSize: size,
11
- };
93
+ samplesProcessed: true,
94
+ fileOffset,
95
+ });
12
96
  };
13
97
  exports.parseMdat = parseMdat;
@@ -1,12 +1,14 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { AnySegment } from '../../../parse-result';
3
+ import type { ParserContext } from '../../../parser-context';
3
4
  import type { BaseBox } from '../base-type';
4
5
  export interface MoovBox extends BaseBox {
5
6
  type: 'moov-box';
6
7
  children: AnySegment[];
7
8
  }
8
- export declare const parseMoov: ({ iterator, offset, size, }: {
9
+ export declare const parseMoov: ({ iterator, offset, size, options, }: {
9
10
  iterator: BufferIterator;
10
11
  offset: number;
11
12
  size: number;
12
- }) => MoovBox;
13
+ options: ParserContext;
14
+ }) => Promise<MoovBox>;
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMoov = void 0;
4
4
  const process_box_1 = require("../process-box");
5
- const parseMoov = ({ iterator, offset, size, }) => {
6
- const children = (0, process_box_1.parseBoxes)({
5
+ const parseMoov = async ({ iterator, offset, size, options, }) => {
6
+ const children = await (0, process_box_1.parseBoxes)({
7
7
  iterator,
8
8
  maxBytes: size - (iterator.counter.getOffset() - offset),
9
9
  allowIncompleteBoxes: false,
10
10
  initialBoxes: [],
11
+ options,
12
+ continueMdat: false,
11
13
  });
12
14
  if (children.status === 'incomplete') {
13
15
  throw new Error('Incomplete boxes are not allowed');
@@ -35,12 +35,18 @@ const parseMvhd = ({ iterator, offset, size, }) => {
35
35
  // matrix
36
36
  const matrix = [];
37
37
  for (let i = 0; i < 9; i++) {
38
- matrix.push(iterator.getUint32());
38
+ if (i % 3 === 2) {
39
+ matrix.push(iterator.getFixedPointSigned230Number());
40
+ }
41
+ else {
42
+ matrix.push(iterator.getFixedPointSigned1616Number());
43
+ }
39
44
  }
40
45
  // pre-defined
41
46
  iterator.discard(4 * 6);
42
47
  // next track id
43
48
  const nextTrackId = iterator.getUint32();
49
+ volumeView.destroy();
44
50
  return {
45
51
  creationTime: (0, to_date_1.toUnixTimestamp)(creationTime),
46
52
  modificationTime: (0, to_date_1.toUnixTimestamp)(modificationTime),
@@ -1,8 +1,25 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { IsoBaseMediaBox, ParseResult } from '../../parse-result';
3
- export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, }: {
2
+ import type { AnySegment, IsoBaseMediaBox, ParseResult } from '../../parse-result';
3
+ import type { BoxAndNext, PartialMdatBox } from '../../parse-video';
4
+ import type { ParserContext } from '../../parser-context';
5
+ export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, options, }: {
6
+ iterator: BufferIterator;
7
+ boxSize: number;
8
+ fileOffset: number;
9
+ parsedBoxes: AnySegment[];
10
+ options: ParserContext;
11
+ }) => Promise<BoxAndNext>;
12
+ export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, options, }: {
13
+ iterator: BufferIterator;
14
+ allowIncompleteBoxes: boolean;
15
+ parsedBoxes: AnySegment[];
16
+ options: ParserContext;
17
+ }) => Promise<BoxAndNext>;
18
+ export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, }: {
4
19
  iterator: BufferIterator;
5
20
  maxBytes: number;
6
21
  allowIncompleteBoxes: boolean;
7
22
  initialBoxes: IsoBaseMediaBox[];
8
- }) => ParseResult;
23
+ options: ParserContext;
24
+ continueMdat: false | PartialMdatBox;
25
+ }) => Promise<ParseResult>;