@kenzuya/mediabunny 1.26.0 → 1.28.6

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 (238) hide show
  1. package/README.md +1 -1
  2. package/dist/bundles/{mediabunny.mjs → mediabunny.js} +21963 -21390
  3. package/dist/bundles/mediabunny.min.js +490 -0
  4. package/dist/modules/shared/mp3-misc.d.ts.map +1 -1
  5. package/dist/modules/src/adts/adts-demuxer.d.ts +6 -6
  6. package/dist/modules/src/adts/adts-demuxer.d.ts.map +1 -1
  7. package/dist/modules/src/adts/adts-muxer.d.ts +4 -4
  8. package/dist/modules/src/adts/adts-muxer.d.ts.map +1 -1
  9. package/dist/modules/src/adts/adts-reader.d.ts +1 -1
  10. package/dist/modules/src/adts/adts-reader.d.ts.map +1 -1
  11. package/dist/modules/src/avi/avi-demuxer.d.ts +44 -0
  12. package/dist/modules/src/avi/avi-demuxer.d.ts.map +1 -0
  13. package/dist/modules/src/avi/avi-misc.d.ts +88 -0
  14. package/dist/modules/src/avi/avi-misc.d.ts.map +1 -0
  15. package/dist/modules/src/avi/avi-muxer.d.ts +45 -0
  16. package/dist/modules/src/avi/avi-muxer.d.ts.map +1 -0
  17. package/dist/modules/src/avi/riff-writer.d.ts +26 -0
  18. package/dist/modules/src/avi/riff-writer.d.ts.map +1 -0
  19. package/dist/modules/src/codec-data.d.ts +8 -3
  20. package/dist/modules/src/codec-data.d.ts.map +1 -1
  21. package/dist/modules/src/codec.d.ts +10 -10
  22. package/dist/modules/src/codec.d.ts.map +1 -1
  23. package/dist/modules/src/conversion.d.ts +33 -16
  24. package/dist/modules/src/conversion.d.ts.map +1 -1
  25. package/dist/modules/src/custom-coder.d.ts +8 -8
  26. package/dist/modules/src/custom-coder.d.ts.map +1 -1
  27. package/dist/modules/src/demuxer.d.ts +3 -3
  28. package/dist/modules/src/demuxer.d.ts.map +1 -1
  29. package/dist/modules/src/encode.d.ts +8 -8
  30. package/dist/modules/src/encode.d.ts.map +1 -1
  31. package/dist/modules/src/flac/flac-demuxer.d.ts +7 -7
  32. package/dist/modules/src/flac/flac-demuxer.d.ts.map +1 -1
  33. package/dist/modules/src/flac/flac-misc.d.ts +3 -3
  34. package/dist/modules/src/flac/flac-misc.d.ts.map +1 -1
  35. package/dist/modules/src/flac/flac-muxer.d.ts +5 -5
  36. package/dist/modules/src/flac/flac-muxer.d.ts.map +1 -1
  37. package/dist/modules/src/id3.d.ts +3 -3
  38. package/dist/modules/src/id3.d.ts.map +1 -1
  39. package/dist/modules/src/index.d.ts +20 -20
  40. package/dist/modules/src/index.d.ts.map +1 -1
  41. package/dist/modules/src/input-format.d.ts +22 -0
  42. package/dist/modules/src/input-format.d.ts.map +1 -1
  43. package/dist/modules/src/input-track.d.ts +8 -8
  44. package/dist/modules/src/input-track.d.ts.map +1 -1
  45. package/dist/modules/src/input.d.ts +12 -12
  46. package/dist/modules/src/isobmff/isobmff-boxes.d.ts +2 -2
  47. package/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -1
  48. package/dist/modules/src/isobmff/isobmff-demuxer.d.ts +12 -12
  49. package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
  50. package/dist/modules/src/isobmff/isobmff-misc.d.ts.map +1 -1
  51. package/dist/modules/src/isobmff/isobmff-muxer.d.ts +11 -11
  52. package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
  53. package/dist/modules/src/isobmff/isobmff-reader.d.ts +2 -2
  54. package/dist/modules/src/isobmff/isobmff-reader.d.ts.map +1 -1
  55. package/dist/modules/src/matroska/ebml.d.ts +3 -3
  56. package/dist/modules/src/matroska/ebml.d.ts.map +1 -1
  57. package/dist/modules/src/matroska/matroska-demuxer.d.ts +13 -13
  58. package/dist/modules/src/matroska/matroska-demuxer.d.ts.map +1 -1
  59. package/dist/modules/src/matroska/matroska-input.d.ts +33 -0
  60. package/dist/modules/src/matroska/matroska-input.d.ts.map +1 -0
  61. package/dist/modules/src/matroska/matroska-misc.d.ts.map +1 -1
  62. package/dist/modules/src/matroska/matroska-muxer.d.ts +5 -5
  63. package/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -1
  64. package/dist/modules/src/media-sink.d.ts +5 -5
  65. package/dist/modules/src/media-sink.d.ts.map +1 -1
  66. package/dist/modules/src/media-source.d.ts +22 -4
  67. package/dist/modules/src/media-source.d.ts.map +1 -1
  68. package/dist/modules/src/metadata.d.ts +2 -2
  69. package/dist/modules/src/metadata.d.ts.map +1 -1
  70. package/dist/modules/src/misc.d.ts +5 -4
  71. package/dist/modules/src/misc.d.ts.map +1 -1
  72. package/dist/modules/src/mp3/mp3-demuxer.d.ts +7 -7
  73. package/dist/modules/src/mp3/mp3-demuxer.d.ts.map +1 -1
  74. package/dist/modules/src/mp3/mp3-muxer.d.ts +4 -4
  75. package/dist/modules/src/mp3/mp3-muxer.d.ts.map +1 -1
  76. package/dist/modules/src/mp3/mp3-reader.d.ts +2 -2
  77. package/dist/modules/src/mp3/mp3-reader.d.ts.map +1 -1
  78. package/dist/modules/src/mp3/mp3-writer.d.ts +1 -1
  79. package/dist/modules/src/mp3/mp3-writer.d.ts.map +1 -1
  80. package/dist/modules/src/muxer.d.ts +4 -4
  81. package/dist/modules/src/muxer.d.ts.map +1 -1
  82. package/dist/modules/src/ogg/ogg-demuxer.d.ts +7 -7
  83. package/dist/modules/src/ogg/ogg-demuxer.d.ts.map +1 -1
  84. package/dist/modules/src/ogg/ogg-misc.d.ts +1 -1
  85. package/dist/modules/src/ogg/ogg-misc.d.ts.map +1 -1
  86. package/dist/modules/src/ogg/ogg-muxer.d.ts +5 -5
  87. package/dist/modules/src/ogg/ogg-muxer.d.ts.map +1 -1
  88. package/dist/modules/src/ogg/ogg-reader.d.ts +1 -1
  89. package/dist/modules/src/ogg/ogg-reader.d.ts.map +1 -1
  90. package/dist/modules/src/output-format.d.ts +51 -6
  91. package/dist/modules/src/output-format.d.ts.map +1 -1
  92. package/dist/modules/src/output.d.ts +13 -13
  93. package/dist/modules/src/output.d.ts.map +1 -1
  94. package/dist/modules/src/packet.d.ts +1 -1
  95. package/dist/modules/src/packet.d.ts.map +1 -1
  96. package/dist/modules/src/pcm.d.ts.map +1 -1
  97. package/dist/modules/src/reader.d.ts +2 -2
  98. package/dist/modules/src/reader.d.ts.map +1 -1
  99. package/dist/modules/src/sample.d.ts +57 -15
  100. package/dist/modules/src/sample.d.ts.map +1 -1
  101. package/dist/modules/src/source.d.ts +3 -3
  102. package/dist/modules/src/source.d.ts.map +1 -1
  103. package/dist/modules/src/subtitles.d.ts +1 -1
  104. package/dist/modules/src/subtitles.d.ts.map +1 -1
  105. package/dist/modules/src/target.d.ts +2 -2
  106. package/dist/modules/src/target.d.ts.map +1 -1
  107. package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
  108. package/dist/modules/src/wave/riff-writer.d.ts +1 -1
  109. package/dist/modules/src/wave/riff-writer.d.ts.map +1 -1
  110. package/dist/modules/src/wave/wave-demuxer.d.ts +6 -6
  111. package/dist/modules/src/wave/wave-demuxer.d.ts.map +1 -1
  112. package/dist/modules/src/wave/wave-muxer.d.ts +4 -4
  113. package/dist/modules/src/wave/wave-muxer.d.ts.map +1 -1
  114. package/dist/modules/src/writer.d.ts +1 -1
  115. package/dist/modules/src/writer.d.ts.map +1 -1
  116. package/dist/packages/eac3/eac3.wasm +0 -0
  117. package/dist/packages/eac3/mediabunny-eac3.js +1058 -0
  118. package/dist/packages/eac3/mediabunny-eac3.min.js +44 -0
  119. package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.js +694 -0
  120. package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.min.js +58 -0
  121. package/dist/packages/mpeg4/mediabunny-mpeg4.js +1198 -0
  122. package/dist/packages/mpeg4/mediabunny-mpeg4.min.js +44 -0
  123. package/dist/packages/mpeg4/xvid.wasm +0 -0
  124. package/package.json +18 -57
  125. package/dist/bundles/mediabunny.cjs +0 -26140
  126. package/dist/bundles/mediabunny.min.cjs +0 -147
  127. package/dist/bundles/mediabunny.min.mjs +0 -146
  128. package/dist/mediabunny.d.ts +0 -3319
  129. package/dist/modules/shared/mp3-misc.js +0 -147
  130. package/dist/modules/src/adts/adts-demuxer.js +0 -239
  131. package/dist/modules/src/adts/adts-muxer.js +0 -80
  132. package/dist/modules/src/adts/adts-reader.js +0 -63
  133. package/dist/modules/src/codec-data.js +0 -1730
  134. package/dist/modules/src/codec.js +0 -869
  135. package/dist/modules/src/conversion.js +0 -1459
  136. package/dist/modules/src/custom-coder.js +0 -117
  137. package/dist/modules/src/demuxer.js +0 -12
  138. package/dist/modules/src/encode.js +0 -442
  139. package/dist/modules/src/flac/flac-demuxer.js +0 -504
  140. package/dist/modules/src/flac/flac-misc.js +0 -135
  141. package/dist/modules/src/flac/flac-muxer.js +0 -222
  142. package/dist/modules/src/id3.js +0 -848
  143. package/dist/modules/src/index.js +0 -28
  144. package/dist/modules/src/input-format.js +0 -480
  145. package/dist/modules/src/input-track.js +0 -372
  146. package/dist/modules/src/input.js +0 -188
  147. package/dist/modules/src/isobmff/isobmff-boxes.js +0 -1480
  148. package/dist/modules/src/isobmff/isobmff-demuxer.js +0 -2618
  149. package/dist/modules/src/isobmff/isobmff-misc.js +0 -20
  150. package/dist/modules/src/isobmff/isobmff-muxer.js +0 -966
  151. package/dist/modules/src/isobmff/isobmff-reader.js +0 -72
  152. package/dist/modules/src/matroska/ebml.js +0 -653
  153. package/dist/modules/src/matroska/matroska-demuxer.js +0 -2133
  154. package/dist/modules/src/matroska/matroska-misc.js +0 -20
  155. package/dist/modules/src/matroska/matroska-muxer.js +0 -1017
  156. package/dist/modules/src/media-sink.js +0 -1736
  157. package/dist/modules/src/media-source.js +0 -1825
  158. package/dist/modules/src/metadata.js +0 -193
  159. package/dist/modules/src/misc.js +0 -623
  160. package/dist/modules/src/mp3/mp3-demuxer.js +0 -285
  161. package/dist/modules/src/mp3/mp3-muxer.js +0 -123
  162. package/dist/modules/src/mp3/mp3-reader.js +0 -26
  163. package/dist/modules/src/mp3/mp3-writer.js +0 -78
  164. package/dist/modules/src/muxer.js +0 -50
  165. package/dist/modules/src/node.d.ts +0 -9
  166. package/dist/modules/src/node.d.ts.map +0 -1
  167. package/dist/modules/src/node.js +0 -9
  168. package/dist/modules/src/ogg/ogg-demuxer.js +0 -763
  169. package/dist/modules/src/ogg/ogg-misc.js +0 -78
  170. package/dist/modules/src/ogg/ogg-muxer.js +0 -353
  171. package/dist/modules/src/ogg/ogg-reader.js +0 -65
  172. package/dist/modules/src/output-format.js +0 -527
  173. package/dist/modules/src/output.js +0 -300
  174. package/dist/modules/src/packet.js +0 -182
  175. package/dist/modules/src/pcm.js +0 -85
  176. package/dist/modules/src/reader.js +0 -236
  177. package/dist/modules/src/sample.js +0 -1056
  178. package/dist/modules/src/source.js +0 -1182
  179. package/dist/modules/src/subtitles.js +0 -575
  180. package/dist/modules/src/target.js +0 -140
  181. package/dist/modules/src/wave/riff-writer.js +0 -30
  182. package/dist/modules/src/wave/wave-demuxer.js +0 -447
  183. package/dist/modules/src/wave/wave-muxer.js +0 -318
  184. package/dist/modules/src/writer.js +0 -370
  185. package/src/adts/adts-demuxer.ts +0 -331
  186. package/src/adts/adts-muxer.ts +0 -111
  187. package/src/adts/adts-reader.ts +0 -85
  188. package/src/codec-data.ts +0 -2078
  189. package/src/codec.ts +0 -1092
  190. package/src/conversion.ts +0 -2112
  191. package/src/custom-coder.ts +0 -197
  192. package/src/demuxer.ts +0 -24
  193. package/src/encode.ts +0 -739
  194. package/src/flac/flac-demuxer.ts +0 -730
  195. package/src/flac/flac-misc.ts +0 -164
  196. package/src/flac/flac-muxer.ts +0 -320
  197. package/src/id3.ts +0 -925
  198. package/src/index.ts +0 -221
  199. package/src/input-format.ts +0 -541
  200. package/src/input-track.ts +0 -529
  201. package/src/input.ts +0 -235
  202. package/src/isobmff/isobmff-boxes.ts +0 -1719
  203. package/src/isobmff/isobmff-demuxer.ts +0 -3190
  204. package/src/isobmff/isobmff-misc.ts +0 -29
  205. package/src/isobmff/isobmff-muxer.ts +0 -1348
  206. package/src/isobmff/isobmff-reader.ts +0 -91
  207. package/src/matroska/ebml.ts +0 -730
  208. package/src/matroska/matroska-demuxer.ts +0 -2481
  209. package/src/matroska/matroska-misc.ts +0 -29
  210. package/src/matroska/matroska-muxer.ts +0 -1276
  211. package/src/media-sink.ts +0 -2179
  212. package/src/media-source.ts +0 -2243
  213. package/src/metadata.ts +0 -320
  214. package/src/misc.ts +0 -798
  215. package/src/mp3/mp3-demuxer.ts +0 -383
  216. package/src/mp3/mp3-muxer.ts +0 -166
  217. package/src/mp3/mp3-reader.ts +0 -34
  218. package/src/mp3/mp3-writer.ts +0 -120
  219. package/src/muxer.ts +0 -88
  220. package/src/node.ts +0 -11
  221. package/src/ogg/ogg-demuxer.ts +0 -1053
  222. package/src/ogg/ogg-misc.ts +0 -116
  223. package/src/ogg/ogg-muxer.ts +0 -497
  224. package/src/ogg/ogg-reader.ts +0 -93
  225. package/src/output-format.ts +0 -945
  226. package/src/output.ts +0 -488
  227. package/src/packet.ts +0 -263
  228. package/src/pcm.ts +0 -112
  229. package/src/reader.ts +0 -323
  230. package/src/sample.ts +0 -1461
  231. package/src/source.ts +0 -1688
  232. package/src/subtitles.ts +0 -711
  233. package/src/target.ts +0 -204
  234. package/src/tsconfig.json +0 -16
  235. package/src/wave/riff-writer.ts +0 -36
  236. package/src/wave/wave-demuxer.ts +0 -529
  237. package/src/wave/wave-muxer.ts +0 -371
  238. package/src/writer.ts +0 -490
@@ -1,945 +0,0 @@
1
- /*!
2
- * Copyright (c) 2025-present, Vanilagy and contributors
3
- *
4
- * This Source Code Form is subject to the terms of the Mozilla Public
5
- * License, v. 2.0. If a copy of the MPL was not distributed with this
6
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
- */
8
-
9
- import { AdtsMuxer } from './adts/adts-muxer';
10
- import {
11
- AUDIO_CODECS,
12
- AudioCodec,
13
- MediaCodec,
14
- NON_PCM_AUDIO_CODECS,
15
- PCM_AUDIO_CODECS,
16
- SUBTITLE_CODECS,
17
- SubtitleCodec,
18
- VIDEO_CODECS,
19
- VideoCodec,
20
- } from './codec';
21
- import { FlacMuxer } from './flac/flac-muxer';
22
- import { IsobmffMuxer } from './isobmff/isobmff-muxer';
23
- import { MatroskaMuxer } from './matroska/matroska-muxer';
24
- import { MediaSource } from './media-source';
25
- import { Mp3Muxer } from './mp3/mp3-muxer';
26
- import { Muxer } from './muxer';
27
- import { OggMuxer } from './ogg/ogg-muxer';
28
- import { Output, TrackType } from './output';
29
- import { WaveMuxer } from './wave/wave-muxer';
30
-
31
- /**
32
- * Specifies an inclusive range of integers.
33
- * @group Miscellaneous
34
- * @public
35
- */
36
- export type InclusiveIntegerRange = {
37
- /** The integer cannot be less than this. */
38
- min: number;
39
- /** The integer cannot be greater than this. */
40
- max: number;
41
- };
42
-
43
- /**
44
- * Specifies the number of tracks (for each track type and in total) that an output format supports.
45
- * @group Output formats
46
- * @public
47
- */
48
- export type TrackCountLimits = {
49
- [K in TrackType]: InclusiveIntegerRange;
50
- } & {
51
- /** Specifies the overall allowed range of track counts for the output format. */
52
- total: InclusiveIntegerRange;
53
- };
54
-
55
- /**
56
- * Base class representing an output media file format.
57
- * @group Output formats
58
- * @public
59
- */
60
- export abstract class OutputFormat {
61
- /** @internal */
62
- abstract _createMuxer(output: Output): Muxer;
63
- /** @internal */
64
- abstract get _name(): string;
65
-
66
- /** The file extension used by this output format, beginning with a dot. */
67
- abstract get fileExtension(): string;
68
- /** The base MIME type of the output format. */
69
- abstract get mimeType(): string;
70
- /** Returns a list of media codecs that this output format can contain. */
71
- abstract getSupportedCodecs(): MediaCodec[];
72
- /** Returns the number of tracks that this output format supports. */
73
- abstract getSupportedTrackCounts(): TrackCountLimits;
74
- /** Whether this output format supports video rotation metadata. */
75
- abstract get supportsVideoRotationMetadata(): boolean;
76
-
77
- /** Returns a list of video codecs that this output format can contain. */
78
- getSupportedVideoCodecs() {
79
- return this.getSupportedCodecs()
80
- .filter(codec => (VIDEO_CODECS as readonly string[]).includes(codec)) as VideoCodec[];
81
- }
82
-
83
- /** Returns a list of audio codecs that this output format can contain. */
84
- getSupportedAudioCodecs() {
85
- return this.getSupportedCodecs()
86
- .filter(codec => (AUDIO_CODECS as readonly string[]).includes(codec)) as AudioCodec[];
87
- }
88
-
89
- /** Returns a list of subtitle codecs that this output format can contain. */
90
- getSupportedSubtitleCodecs() {
91
- return this.getSupportedCodecs()
92
- .filter(codec => (SUBTITLE_CODECS as readonly string[]).includes(codec)) as SubtitleCodec[];
93
- }
94
-
95
- /** @internal */
96
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
97
- _codecUnsupportedHint(codec: MediaCodec) {
98
- return '';
99
- }
100
- }
101
-
102
- /**
103
- * ISOBMFF-specific output options.
104
- * @group Output formats
105
- * @public
106
- */
107
- export type IsobmffOutputFormatOptions = {
108
- /**
109
- * Controls the placement of metadata in the file. Placing metadata at the start of the file is known as "Fast
110
- * Start", which results in better playback at the cost of more required processing or memory.
111
- *
112
- * Use `false` to disable Fast Start, placing the metadata at the end of the file. Fastest and uses the least
113
- * memory.
114
- *
115
- * Use `'in-memory'` to produce a file with Fast Start by keeping all media chunks in memory until the file is
116
- * finalized. This produces a high-quality and compact output at the cost of a more expensive finalization step and
117
- * higher memory requirements. Data will be written monotonically (in order) when this option is set.
118
- *
119
- * Use `'reserve'` to reserve space at the start of the file into which the metadata will be written later. This
120
- * produces a file with Fast Start but requires knowledge about the expected length of the file beforehand. When
121
- * using this option, you must set the {@link BaseTrackMetadata.maximumPacketCount} field in the track metadata
122
- * for all tracks.
123
- *
124
- * Use `'fragmented'` to place metadata at the start of the file by creating a fragmented file (fMP4). In a
125
- * fragmented file, chunks of media and their metadata are written to the file in "fragments", eliminating the need
126
- * to put all metadata in one place. Fragmented files are useful for streaming contexts, as each fragment can be
127
- * played individually without requiring knowledge of the other fragments. Furthermore, they remain lightweight to
128
- * create even for very large files, as they don't require all media to be kept in memory. However, fragmented files
129
- * are not as widely and wholly supported as regular MP4/MOV files. Data will be written monotonically (in order)
130
- * when this option is set.
131
- *
132
- * When this field is not defined, either `false` or `'in-memory'` will be used, automatically determined based on
133
- * the type of output target used.
134
- */
135
- fastStart?: false | 'in-memory' | 'reserve' | 'fragmented';
136
-
137
- /**
138
- * When using `fastStart: 'fragmented'`, this field controls the minimum duration of each fragment, in seconds.
139
- * New fragments will only be created when the current fragment is longer than this value. Defaults to 1 second.
140
- */
141
- minimumFragmentDuration?: number;
142
-
143
- /**
144
- * The metadata format to use for writing metadata tags.
145
- *
146
- * - `'auto'` (default): Behaves like `'mdir'` for MP4 and like `'udta'` for QuickTime, matching FFmpeg's default
147
- * behavior.
148
- * - `'mdir'`: Write tags into `moov/udta/meta` using the 'mdir' handler format.
149
- * - `'mdta'`: Write tags into `moov/udta/meta` using the 'mdta' handler format, equivalent to FFmpeg's
150
- * `use_metadata_tags` flag. This allows for custom keys of arbitrary length.
151
- * - `'udta'`: Write tags directly into `moov/udta`.
152
- */
153
- metadataFormat?: 'auto' | 'mdir' | 'mdta' | 'udta';
154
-
155
- /**
156
- * Will be called once the ftyp (File Type) box of the output file has been written.
157
- *
158
- * @param data - The raw bytes.
159
- * @param position - The byte offset of the data in the file.
160
- */
161
- onFtyp?: (data: Uint8Array, position: number) => unknown;
162
-
163
- /**
164
- * Will be called once the moov (Movie) box of the output file has been written.
165
- *
166
- * @param data - The raw bytes.
167
- * @param position - The byte offset of the data in the file.
168
- */
169
- onMoov?: (data: Uint8Array, position: number) => unknown;
170
-
171
- /**
172
- * Will be called for each finalized mdat (Media Data) box of the output file. Usage of this callback is not
173
- * recommended when not using `fastStart: 'fragmented'`, as there will be one monolithic mdat box which might
174
- * require large amounts of memory.
175
- *
176
- * @param data - The raw bytes.
177
- * @param position - The byte offset of the data in the file.
178
- */
179
- onMdat?: (data: Uint8Array, position: number) => unknown;
180
-
181
- /**
182
- * Will be called for each finalized moof (Movie Fragment) box of the output file.
183
- *
184
- * @param data - The raw bytes.
185
- * @param position - The byte offset of the data in the file.
186
- * @param timestamp - The start timestamp of the fragment in seconds.
187
- */
188
- onMoof?: (data: Uint8Array, position: number, timestamp: number) => unknown;
189
- };
190
-
191
- /**
192
- * Format representing files compatible with the ISO base media file format (ISOBMFF), like MP4 or MOV files.
193
- * @group Output formats
194
- * @public
195
- */
196
- export abstract class IsobmffOutputFormat extends OutputFormat {
197
- /** @internal */
198
- _options: IsobmffOutputFormatOptions;
199
-
200
- /** Internal constructor. */
201
- constructor(options: IsobmffOutputFormatOptions = {}) {
202
- if (!options || typeof options !== 'object') {
203
- throw new TypeError('options must be an object.');
204
- }
205
- if (
206
- options.fastStart !== undefined
207
- && ![false, 'in-memory', 'reserve', 'fragmented'].includes(options.fastStart)
208
- ) {
209
- throw new TypeError(
210
- 'options.fastStart, when provided, must be false, \'in-memory\', \'reserve\', or \'fragmented\'.',
211
- );
212
- }
213
- if (
214
- options.minimumFragmentDuration !== undefined
215
- && (!Number.isFinite(options.minimumFragmentDuration) || options.minimumFragmentDuration < 0)
216
- ) {
217
- throw new TypeError('options.minimumFragmentDuration, when provided, must be a non-negative number.');
218
- }
219
- if (options.onFtyp !== undefined && typeof options.onFtyp !== 'function') {
220
- throw new TypeError('options.onFtyp, when provided, must be a function.');
221
- }
222
- if (options.onMoov !== undefined && typeof options.onMoov !== 'function') {
223
- throw new TypeError('options.onMoov, when provided, must be a function.');
224
- }
225
- if (options.onMdat !== undefined && typeof options.onMdat !== 'function') {
226
- throw new TypeError('options.onMdat, when provided, must be a function.');
227
- }
228
- if (options.onMoof !== undefined && typeof options.onMoof !== 'function') {
229
- throw new TypeError('options.onMoof, when provided, must be a function.');
230
- }
231
- if (
232
- options.metadataFormat !== undefined
233
- && !['mdir', 'mdta', 'udta', 'auto'].includes(options.metadataFormat)
234
- ) {
235
- throw new TypeError(
236
- 'options.metadataFormat, when provided, must be either \'auto\', \'mdir\', \'mdta\', or \'udta\'.',
237
- );
238
- }
239
-
240
- super();
241
-
242
- this._options = options;
243
- }
244
-
245
- getSupportedTrackCounts(): TrackCountLimits {
246
- return {
247
- video: { min: 0, max: Infinity },
248
- audio: { min: 0, max: Infinity },
249
- subtitle: { min: 0, max: Infinity },
250
- total: { min: 1, max: 2 ** 32 - 1 }, // Have fun reaching this one
251
- };
252
- }
253
-
254
- get supportsVideoRotationMetadata() {
255
- return true;
256
- }
257
-
258
- /** @internal */
259
- _createMuxer(output: Output) {
260
- return new IsobmffMuxer(output, this);
261
- }
262
- }
263
-
264
- /**
265
- * MPEG-4 Part 14 (MP4) file format. Supports most codecs.
266
- * @group Output formats
267
- * @public
268
- */
269
- export class Mp4OutputFormat extends IsobmffOutputFormat {
270
- /** Creates a new {@link Mp4OutputFormat} configured with the specified `options`. */
271
- constructor(options?: IsobmffOutputFormatOptions) {
272
- super(options);
273
- }
274
-
275
- /** @internal */
276
- get _name() {
277
- return 'MP4';
278
- }
279
-
280
- get fileExtension() {
281
- return '.mp4';
282
- }
283
-
284
- get mimeType() {
285
- return 'video/mp4';
286
- }
287
-
288
- getSupportedCodecs(): MediaCodec[] {
289
- return [
290
- ...VIDEO_CODECS,
291
- ...NON_PCM_AUDIO_CODECS,
292
- // These are supported via ISO/IEC 23003-5
293
- 'pcm-s16',
294
- 'pcm-s16be',
295
- 'pcm-s24',
296
- 'pcm-s24be',
297
- 'pcm-s32',
298
- 'pcm-s32be',
299
- 'pcm-f32',
300
- 'pcm-f32be',
301
- 'pcm-f64',
302
- 'pcm-f64be',
303
- // Only WebVTT subtitles are supported in MP4
304
- 'webvtt',
305
- ];
306
- }
307
-
308
- /** @internal */
309
- override _codecUnsupportedHint(codec: MediaCodec) {
310
- if (new MovOutputFormat().getSupportedCodecs().includes(codec)) {
311
- return ' Switching to MOV will grant support for this codec.';
312
- }
313
-
314
- return '';
315
- }
316
- }
317
-
318
- /**
319
- * QuickTime File Format (QTFF), often called MOV. Supports all video and audio codecs, but not subtitle codecs.
320
- * @group Output formats
321
- * @public
322
- */
323
- export class MovOutputFormat extends IsobmffOutputFormat {
324
- /** Creates a new {@link MovOutputFormat} configured with the specified `options`. */
325
- constructor(options?: IsobmffOutputFormatOptions) {
326
- super(options);
327
- }
328
-
329
- /** @internal */
330
- get _name() {
331
- return 'MOV';
332
- }
333
-
334
- get fileExtension() {
335
- return '.mov';
336
- }
337
-
338
- get mimeType() {
339
- return 'video/quicktime';
340
- }
341
-
342
- getSupportedCodecs(): MediaCodec[] {
343
- return [
344
- ...VIDEO_CODECS,
345
- ...AUDIO_CODECS,
346
- // Only WebVTT subtitles are supported in MOV
347
- 'webvtt',
348
- ];
349
- }
350
-
351
- /** @internal */
352
- override _codecUnsupportedHint(codec: MediaCodec) {
353
- if (new Mp4OutputFormat().getSupportedCodecs().includes(codec)) {
354
- return ' Switching to MP4 will grant support for this codec.';
355
- }
356
-
357
- return '';
358
- }
359
- }
360
-
361
- /**
362
- * Matroska-specific output options.
363
- * @group Output formats
364
- * @public
365
- */
366
- export type MkvOutputFormatOptions = {
367
- /**
368
- * Configures the output to only append new data at the end, useful for live-streaming the file as it's being
369
- * created. When enabled, some features such as storing duration and seeking will be disabled or impacted, so don't
370
- * use this option when you want to write out a clean file for later use.
371
- */
372
- appendOnly?: boolean;
373
-
374
- /**
375
- * This field controls the minimum duration of each Matroska cluster, in seconds. New clusters will only be created
376
- * when the current cluster is longer than this value. Defaults to 1 second.
377
- */
378
- minimumClusterDuration?: number;
379
-
380
- /**
381
- * Will be called once the EBML header of the output file has been written.
382
- *
383
- * @param data - The raw bytes.
384
- * @param position - The byte offset of the data in the file.
385
- */
386
- onEbmlHeader?: (data: Uint8Array, position: number) => void;
387
-
388
- /**
389
- * Will be called once the header part of the Matroska Segment element has been written. The header data includes
390
- * the Segment element and everything inside it, up to (but excluding) the first Matroska Cluster.
391
- *
392
- * @param data - The raw bytes.
393
- * @param position - The byte offset of the data in the file.
394
- */
395
- onSegmentHeader?: (data: Uint8Array, position: number) => unknown;
396
-
397
- /**
398
- * Will be called for each finalized Matroska Cluster of the output file.
399
- *
400
- * @param data - The raw bytes.
401
- * @param position - The byte offset of the data in the file.
402
- * @param timestamp - The start timestamp of the cluster in seconds.
403
- */
404
- onCluster?: (data: Uint8Array, position: number, timestamp: number) => unknown;
405
- };
406
-
407
- /**
408
- * Matroska file format.
409
- *
410
- * Supports writing transparent video. For a video track to be marked as transparent, the first packet added must
411
- * contain alpha side data.
412
- *
413
- * @group Output formats
414
- * @public
415
- */
416
- export class MkvOutputFormat extends OutputFormat {
417
- /** @internal */
418
- _options: MkvOutputFormatOptions;
419
-
420
- /** Creates a new {@link MkvOutputFormat} configured with the specified `options`. */
421
- constructor(options: MkvOutputFormatOptions = {}) {
422
- if (!options || typeof options !== 'object') {
423
- throw new TypeError('options must be an object.');
424
- }
425
- if (options.appendOnly !== undefined && typeof options.appendOnly !== 'boolean') {
426
- throw new TypeError('options.appendOnly, when provided, must be a boolean.');
427
- }
428
- if (
429
- options.minimumClusterDuration !== undefined
430
- && (!Number.isFinite(options.minimumClusterDuration) || options.minimumClusterDuration < 0)
431
- ) {
432
- throw new TypeError('options.minimumClusterDuration, when provided, must be a non-negative number.');
433
- }
434
- if (options.onEbmlHeader !== undefined && typeof options.onEbmlHeader !== 'function') {
435
- throw new TypeError('options.onEbmlHeader, when provided, must be a function.');
436
- }
437
- if (options.onSegmentHeader !== undefined && typeof options.onSegmentHeader !== 'function') {
438
- throw new TypeError('options.onHeader, when provided, must be a function.');
439
- }
440
- if (options.onCluster !== undefined && typeof options.onCluster !== 'function') {
441
- throw new TypeError('options.onCluster, when provided, must be a function.');
442
- }
443
-
444
- super();
445
-
446
- this._options = options;
447
- }
448
-
449
- /** @internal */
450
- _createMuxer(output: Output) {
451
- return new MatroskaMuxer(output, this);
452
- }
453
-
454
- /** @internal */
455
- get _name() {
456
- return 'Matroska';
457
- }
458
-
459
- getSupportedTrackCounts(): TrackCountLimits {
460
- return {
461
- video: { min: 0, max: Infinity },
462
- audio: { min: 0, max: Infinity },
463
- subtitle: { min: 0, max: Infinity },
464
- total: { min: 1, max: 127 },
465
- };
466
- }
467
-
468
- get fileExtension() {
469
- return '.mkv';
470
- }
471
-
472
- get mimeType() {
473
- return 'video/x-matroska';
474
- }
475
-
476
- getSupportedCodecs(): MediaCodec[] {
477
- return [
478
- ...VIDEO_CODECS,
479
- ...NON_PCM_AUDIO_CODECS,
480
- ...PCM_AUDIO_CODECS.filter(codec => !['pcm-s8', 'pcm-f32be', 'pcm-f64be', 'ulaw', 'alaw'].includes(codec)),
481
- ...SUBTITLE_CODECS,
482
- ];
483
- }
484
-
485
- get supportsVideoRotationMetadata() {
486
- // While it technically does support it with ProjectionPoseRoll, many players appear to ignore this value
487
- return false;
488
- }
489
- }
490
-
491
- /**
492
- * WebM-specific output options.
493
- * @group Output formats
494
- * @public
495
- */
496
- export type WebMOutputFormatOptions = MkvOutputFormatOptions;
497
-
498
- /**
499
- * WebM file format, based on Matroska.
500
- *
501
- * Supports writing transparent video. For a video track to be marked as transparent, the first packet added must
502
- * contain alpha side data.
503
- *
504
- * @group Output formats
505
- * @public
506
- */
507
- export class WebMOutputFormat extends MkvOutputFormat {
508
- /** Creates a new {@link WebMOutputFormat} configured with the specified `options`. */
509
- constructor(options?: MkvOutputFormatOptions) {
510
- super(options);
511
- }
512
-
513
- override getSupportedCodecs(): MediaCodec[] {
514
- return [
515
- ...VIDEO_CODECS.filter(codec => ['vp8', 'vp9', 'av1'].includes(codec)),
516
- ...AUDIO_CODECS.filter(codec => ['opus', 'vorbis'].includes(codec)),
517
- ...SUBTITLE_CODECS,
518
- ];
519
- }
520
-
521
- /** @internal */
522
- override get _name() {
523
- return 'WebM';
524
- }
525
-
526
- override get fileExtension() {
527
- return '.webm';
528
- }
529
-
530
- override get mimeType() {
531
- return 'video/webm';
532
- }
533
-
534
- /** @internal */
535
- override _codecUnsupportedHint(codec: MediaCodec) {
536
- if (new MkvOutputFormat().getSupportedCodecs().includes(codec)) {
537
- return ' Switching to MKV will grant support for this codec.';
538
- }
539
-
540
- return '';
541
- }
542
- }
543
-
544
- /**
545
- * MP3-specific output options.
546
- * @group Output formats
547
- * @public
548
- */
549
- export type Mp3OutputFormatOptions = {
550
- /**
551
- * Controls whether the Xing header, which contains additional metadata as well as an index, is written to the start
552
- * of the MP3 file. When disabled, the writing process becomes append-only. Defaults to `true`.
553
- */
554
- xingHeader?: boolean;
555
-
556
- /**
557
- * Will be called once the Xing metadata frame is finalized.
558
- *
559
- * @param data - The raw bytes.
560
- * @param position - The byte offset of the data in the file.
561
- */
562
- onXingFrame?: (data: Uint8Array, position: number) => unknown;
563
- };
564
-
565
- /**
566
- * MP3 file format.
567
- * @group Output formats
568
- * @public
569
- */
570
- export class Mp3OutputFormat extends OutputFormat {
571
- /** @internal */
572
- _options: Mp3OutputFormatOptions;
573
-
574
- /** Creates a new {@link Mp3OutputFormat} configured with the specified `options`. */
575
- constructor(options: Mp3OutputFormatOptions = {}) {
576
- if (!options || typeof options !== 'object') {
577
- throw new TypeError('options must be an object.');
578
- }
579
- if (options.xingHeader !== undefined && typeof options.xingHeader !== 'boolean') {
580
- throw new TypeError('options.xingHeader, when provided, must be a boolean.');
581
- }
582
- if (options.onXingFrame !== undefined && typeof options.onXingFrame !== 'function') {
583
- throw new TypeError('options.onXingFrame, when provided, must be a function.');
584
- }
585
-
586
- super();
587
-
588
- this._options = options;
589
- }
590
-
591
- /** @internal */
592
- _createMuxer(output: Output) {
593
- return new Mp3Muxer(output, this);
594
- }
595
-
596
- /** @internal */
597
- get _name() {
598
- return 'MP3';
599
- }
600
-
601
- getSupportedTrackCounts(): TrackCountLimits {
602
- return {
603
- video: { min: 0, max: 0 },
604
- audio: { min: 1, max: 1 },
605
- subtitle: { min: 0, max: 0 },
606
- total: { min: 1, max: 1 },
607
- };
608
- }
609
-
610
- get fileExtension() {
611
- return '.mp3';
612
- }
613
-
614
- get mimeType() {
615
- return 'audio/mpeg';
616
- }
617
-
618
- getSupportedCodecs(): MediaCodec[] {
619
- return ['mp3'];
620
- }
621
-
622
- get supportsVideoRotationMetadata() {
623
- return false;
624
- }
625
- }
626
-
627
- /**
628
- * WAVE-specific output options.
629
- * @group Output formats
630
- * @public
631
- */
632
- export type WavOutputFormatOptions = {
633
- /**
634
- * When enabled, an RF64 file will be written, allowing for file sizes to exceed 4 GiB, which is otherwise not
635
- * possible for regular WAVE files.
636
- */
637
- large?: boolean;
638
-
639
- /**
640
- * The metadata format to use for writing metadata tags.
641
- *
642
- * - `'info'` (default): Writes metadata into a RIFF INFO LIST chunk, the default way to contain metadata tags
643
- * within WAVE. Only allows for a limited subset of tags to be written.
644
- * - `'id3'`: Writes metadata into an ID3 chunk. Non-default, but used by many taggers in practice. Allows for a
645
- * much larger and richer set of tags to be written.
646
- */
647
- metadataFormat?: 'info' | 'id3';
648
-
649
- /**
650
- * Will be called once the file header is written. The header consists of the RIFF header, the format chunk,
651
- * metadata chunks, and the start of the data chunk (with a placeholder size of 0).
652
- */
653
- onHeader?: (data: Uint8Array, position: number) => unknown;
654
- };
655
-
656
- /**
657
- * WAVE file format, based on RIFF.
658
- * @group Output formats
659
- * @public
660
- */
661
- export class WavOutputFormat extends OutputFormat {
662
- /** @internal */
663
- _options: WavOutputFormatOptions;
664
-
665
- /** Creates a new {@link WavOutputFormat} configured with the specified `options`. */
666
- constructor(options: WavOutputFormatOptions = {}) {
667
- if (!options || typeof options !== 'object') {
668
- throw new TypeError('options must be an object.');
669
- }
670
- if (options.large !== undefined && typeof options.large !== 'boolean') {
671
- throw new TypeError('options.large, when provided, must be a boolean.');
672
- }
673
- if (options.metadataFormat !== undefined && !['info', 'id3'].includes(options.metadataFormat)) {
674
- throw new TypeError('options.metadataFormat, when provided, must be either \'info\' or \'id3\'.');
675
- }
676
- if (options.onHeader !== undefined && typeof options.onHeader !== 'function') {
677
- throw new TypeError('options.onHeader, when provided, must be a function.');
678
- }
679
-
680
- super();
681
-
682
- this._options = options;
683
- }
684
-
685
- /** @internal */
686
- _createMuxer(output: Output) {
687
- return new WaveMuxer(output, this);
688
- }
689
-
690
- /** @internal */
691
- get _name() {
692
- return 'WAVE';
693
- }
694
-
695
- getSupportedTrackCounts(): TrackCountLimits {
696
- return {
697
- video: { min: 0, max: 0 },
698
- audio: { min: 1, max: 1 },
699
- subtitle: { min: 0, max: 0 },
700
- total: { min: 1, max: 1 },
701
- };
702
- }
703
-
704
- get fileExtension() {
705
- return '.wav';
706
- }
707
-
708
- get mimeType() {
709
- return 'audio/wav';
710
- }
711
-
712
- getSupportedCodecs(): MediaCodec[] {
713
- return [
714
- ...PCM_AUDIO_CODECS.filter(codec =>
715
- ['pcm-s16', 'pcm-s24', 'pcm-s32', 'pcm-f32', 'pcm-u8', 'ulaw', 'alaw'].includes(codec),
716
- ),
717
- ];
718
- }
719
-
720
- get supportsVideoRotationMetadata() {
721
- return false;
722
- }
723
- }
724
-
725
- /**
726
- * Ogg-specific output options.
727
- * @group Output formats
728
- * @public
729
- */
730
- export type OggOutputFormatOptions = {
731
- /**
732
- * Will be called for each Ogg page that is written.
733
- *
734
- * @param data - The raw bytes.
735
- * @param position - The byte offset of the data in the file.
736
- * @param source - The {@link MediaSource} backing the page's logical bitstream (track).
737
- */
738
- onPage?: (data: Uint8Array, position: number, source: MediaSource) => unknown;
739
- };
740
-
741
- /**
742
- * Ogg file format.
743
- * @group Output formats
744
- * @public
745
- */
746
- export class OggOutputFormat extends OutputFormat {
747
- /** @internal */
748
- _options: OggOutputFormatOptions;
749
-
750
- /** Creates a new {@link OggOutputFormat} configured with the specified `options`. */
751
- constructor(options: OggOutputFormatOptions = {}) {
752
- if (!options || typeof options !== 'object') {
753
- throw new TypeError('options must be an object.');
754
- }
755
- if (options.onPage !== undefined && typeof options.onPage !== 'function') {
756
- throw new TypeError('options.onPage, when provided, must be a function.');
757
- }
758
-
759
- super();
760
-
761
- this._options = options;
762
- }
763
-
764
- /** @internal */
765
- _createMuxer(output: Output) {
766
- return new OggMuxer(output, this);
767
- }
768
-
769
- /** @internal */
770
- get _name() {
771
- return 'Ogg';
772
- }
773
-
774
- getSupportedTrackCounts(): TrackCountLimits {
775
- return {
776
- video: { min: 0, max: 0 },
777
- audio: { min: 0, max: Infinity },
778
- subtitle: { min: 0, max: 0 },
779
- total: { min: 1, max: 2 ** 32 },
780
- };
781
- }
782
-
783
- get fileExtension() {
784
- return '.ogg';
785
- }
786
-
787
- get mimeType() {
788
- return 'application/ogg';
789
- }
790
-
791
- getSupportedCodecs(): MediaCodec[] {
792
- return [
793
- ...AUDIO_CODECS.filter(codec => ['vorbis', 'opus'].includes(codec)),
794
- ];
795
- }
796
-
797
- get supportsVideoRotationMetadata() {
798
- return false;
799
- }
800
- }
801
-
802
- /**
803
- * ADTS-specific output options.
804
- * @group Output formats
805
- * @public
806
- */
807
- export type AdtsOutputFormatOptions = {
808
- /**
809
- * Will be called for each ADTS frame that is written.
810
- *
811
- * @param data - The raw bytes.
812
- * @param position - The byte offset of the data in the file.
813
- */
814
- onFrame?: (data: Uint8Array, position: number) => unknown;
815
- };
816
-
817
- /**
818
- * ADTS file format.
819
- * @group Output formats
820
- * @public
821
- */
822
- export class AdtsOutputFormat extends OutputFormat {
823
- /** @internal */
824
- _options: AdtsOutputFormatOptions;
825
-
826
- /** Creates a new {@link AdtsOutputFormat} configured with the specified `options`. */
827
- constructor(options: AdtsOutputFormatOptions = {}) {
828
- if (!options || typeof options !== 'object') {
829
- throw new TypeError('options must be an object.');
830
- }
831
- if (options.onFrame !== undefined && typeof options.onFrame !== 'function') {
832
- throw new TypeError('options.onFrame, when provided, must be a function.');
833
- }
834
-
835
- super();
836
-
837
- this._options = options;
838
- }
839
-
840
- /** @internal */
841
- _createMuxer(output: Output) {
842
- return new AdtsMuxer(output, this);
843
- }
844
-
845
- /** @internal */
846
- get _name() {
847
- return 'ADTS';
848
- }
849
-
850
- getSupportedTrackCounts(): TrackCountLimits {
851
- return {
852
- video: { min: 0, max: 0 },
853
- audio: { min: 1, max: 1 },
854
- subtitle: { min: 0, max: 0 },
855
- total: { min: 1, max: 1 },
856
- };
857
- }
858
-
859
- get fileExtension() {
860
- return '.aac';
861
- }
862
-
863
- get mimeType() {
864
- return 'audio/aac';
865
- }
866
-
867
- getSupportedCodecs(): MediaCodec[] {
868
- return ['aac'];
869
- }
870
-
871
- get supportsVideoRotationMetadata() {
872
- return false;
873
- }
874
- }
875
-
876
- /**
877
- * FLAC-specific output options.
878
- * @group Output formats
879
- * @public
880
- */
881
- export type FlacOutputFormatOptions = {
882
- /**
883
- * Will be called for each FLAC frame that is written.
884
- *
885
- * @param data - The raw bytes.
886
- * @param position - The byte offset of the data in the file.
887
- */
888
- onFrame?: (data: Uint8Array, position: number) => unknown;
889
- };
890
-
891
- /**
892
- * FLAC file format.
893
- * @group Output formats
894
- * @public
895
- */
896
- export class FlacOutputFormat extends OutputFormat {
897
- /** @internal */
898
- _options: FlacOutputFormatOptions;
899
-
900
- /** Creates a new {@link FlacOutputFormat} configured with the specified `options`. */
901
- constructor(options: FlacOutputFormatOptions = {}) {
902
- if (!options || typeof options !== 'object') {
903
- throw new TypeError('options must be an object.');
904
- }
905
-
906
- super();
907
-
908
- this._options = options;
909
- }
910
-
911
- /** @internal */
912
- _createMuxer(output: Output) {
913
- return new FlacMuxer(output, this);
914
- }
915
-
916
- /** @internal */
917
- get _name() {
918
- return 'FLAC';
919
- }
920
-
921
- getSupportedTrackCounts(): TrackCountLimits {
922
- return {
923
- video: { min: 0, max: 0 },
924
- audio: { min: 1, max: 1 },
925
- subtitle: { min: 0, max: 0 },
926
- total: { min: 1, max: 1 },
927
- };
928
- }
929
-
930
- get fileExtension() {
931
- return '.flac';
932
- }
933
-
934
- get mimeType() {
935
- return 'audio/flac';
936
- }
937
-
938
- getSupportedCodecs(): MediaCodec[] {
939
- return ['flac'];
940
- }
941
-
942
- get supportsVideoRotationMetadata() {
943
- return false;
944
- }
945
- }