@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,372 +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
- import { determineVideoPacketType } from './codec-data.js';
9
- import { customAudioDecoders, customVideoDecoders } from './custom-coder.js';
10
- import { EncodedPacketSink } from './media-sink.js';
11
- import { assert } from './misc.js';
12
- import { EncodedPacket } from './packet.js';
13
- /**
14
- * Represents a media track in an input file.
15
- * @group Input files & tracks
16
- * @public
17
- */
18
- export class InputTrack {
19
- /** @internal */
20
- constructor(input, backing) {
21
- this.input = input;
22
- this._backing = backing;
23
- }
24
- /** Returns true if and only if this track is a video track. */
25
- isVideoTrack() {
26
- return this instanceof InputVideoTrack;
27
- }
28
- /** Returns true if and only if this track is an audio track. */
29
- isAudioTrack() {
30
- return this instanceof InputAudioTrack;
31
- }
32
- /** Returns true if and only if this track is a subtitle track. */
33
- isSubtitleTrack() {
34
- return this instanceof InputSubtitleTrack;
35
- }
36
- /** The unique ID of this track in the input file. */
37
- get id() {
38
- return this._backing.getId();
39
- }
40
- /**
41
- * The identifier of the codec used internally by the container. It is not homogenized by Mediabunny
42
- * and depends entirely on the container format.
43
- *
44
- * This field can be used to determine the codec of a track in case Mediabunny doesn't know that codec.
45
- *
46
- * - For ISOBMFF files, this field returns the name of the Sample Description Box (e.g. `'avc1'`).
47
- * - For Matroska files, this field returns the value of the `CodecID` element.
48
- * - For WAVE files, this field returns the value of the format tag in the `'fmt '` chunk.
49
- * - For ADTS files, this field contains the `MPEG-4 Audio Object Type`.
50
- * - In all other cases, this field is `null`.
51
- */
52
- get internalCodecId() {
53
- return this._backing.getInternalCodecId();
54
- }
55
- /**
56
- * The ISO 639-2/T language code for this track. If the language is unknown, this field is `'und'` (undetermined).
57
- */
58
- get languageCode() {
59
- return this._backing.getLanguageCode();
60
- }
61
- /** A user-defined name for this track. */
62
- get name() {
63
- return this._backing.getName();
64
- }
65
- /**
66
- * A positive number x such that all timestamps and durations of all packets of this track are
67
- * integer multiples of 1/x.
68
- */
69
- get timeResolution() {
70
- return this._backing.getTimeResolution();
71
- }
72
- /** The track's disposition, i.e. information about its intended usage. */
73
- get disposition() {
74
- return this._backing.getDisposition();
75
- }
76
- /**
77
- * Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value
78
- * may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples
79
- * with a negative timestamp should not be presented.
80
- */
81
- getFirstTimestamp() {
82
- return this._backing.getFirstTimestamp();
83
- }
84
- /** Returns the end timestamp of the last packet of this track, in seconds. */
85
- computeDuration() {
86
- return this._backing.computeDuration();
87
- }
88
- /**
89
- * Computes aggregate packet statistics for this track, such as average packet rate or bitrate.
90
- *
91
- * @param targetPacketCount - This optional parameter sets a target for how many packets this method must have
92
- * looked at before it can return early; this means, you can use it to aggregate only a subset (prefix) of all
93
- * packets. This is very useful for getting a great estimate of video frame rate without having to scan through the
94
- * entire file.
95
- */
96
- async computePacketStats(targetPacketCount = Infinity) {
97
- const sink = new EncodedPacketSink(this);
98
- let startTimestamp = Infinity;
99
- let endTimestamp = -Infinity;
100
- let packetCount = 0;
101
- let totalPacketBytes = 0;
102
- for await (const packet of sink.packets(undefined, undefined, { metadataOnly: true })) {
103
- if (packetCount >= targetPacketCount
104
- // This additional condition is needed to produce correct results with out-of-presentation-order packets
105
- && packet.timestamp >= endTimestamp) {
106
- break;
107
- }
108
- startTimestamp = Math.min(startTimestamp, packet.timestamp);
109
- endTimestamp = Math.max(endTimestamp, packet.timestamp + packet.duration);
110
- packetCount++;
111
- totalPacketBytes += packet.byteLength;
112
- }
113
- return {
114
- packetCount,
115
- averagePacketRate: packetCount
116
- ? Number((packetCount / (endTimestamp - startTimestamp)).toPrecision(16))
117
- : 0,
118
- averageBitrate: packetCount
119
- ? Number((8 * totalPacketBytes / (endTimestamp - startTimestamp)).toPrecision(16))
120
- : 0,
121
- };
122
- }
123
- }
124
- /**
125
- * Represents a video track in an input file.
126
- * @group Input files & tracks
127
- * @public
128
- */
129
- export class InputVideoTrack extends InputTrack {
130
- /** @internal */
131
- constructor(input, backing) {
132
- super(input, backing);
133
- this._backing = backing;
134
- }
135
- get type() {
136
- return 'video';
137
- }
138
- get codec() {
139
- return this._backing.getCodec();
140
- }
141
- /** The width in pixels of the track's coded samples, before any transformations or rotations. */
142
- get codedWidth() {
143
- return this._backing.getCodedWidth();
144
- }
145
- /** The height in pixels of the track's coded samples, before any transformations or rotations. */
146
- get codedHeight() {
147
- return this._backing.getCodedHeight();
148
- }
149
- /** The angle in degrees by which the track's frames should be rotated (clockwise). */
150
- get rotation() {
151
- return this._backing.getRotation();
152
- }
153
- /** The width in pixels of the track's frames after rotation. */
154
- get displayWidth() {
155
- const rotation = this._backing.getRotation();
156
- return rotation % 180 === 0 ? this._backing.getCodedWidth() : this._backing.getCodedHeight();
157
- }
158
- /** The height in pixels of the track's frames after rotation. */
159
- get displayHeight() {
160
- const rotation = this._backing.getRotation();
161
- return rotation % 180 === 0 ? this._backing.getCodedHeight() : this._backing.getCodedWidth();
162
- }
163
- /** Returns the color space of the track's samples. */
164
- getColorSpace() {
165
- return this._backing.getColorSpace();
166
- }
167
- /** If this method returns true, the track's samples use a high dynamic range (HDR). */
168
- async hasHighDynamicRange() {
169
- const colorSpace = await this._backing.getColorSpace();
170
- return colorSpace.primaries === 'bt2020' || colorSpace.primaries === 'smpte432'
171
- || colorSpace.transfer === 'pg' || colorSpace.transfer === 'hlg'
172
- || colorSpace.matrix === 'bt2020-ncl';
173
- }
174
- /** Checks if this track may contain transparent samples with alpha data. */
175
- canBeTransparent() {
176
- return this._backing.canBeTransparent();
177
- }
178
- /**
179
- * Returns the [decoder configuration](https://www.w3.org/TR/webcodecs/#video-decoder-config) for decoding the
180
- * track's packets using a [`VideoDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/VideoDecoder). Returns
181
- * null if the track's codec is unknown.
182
- */
183
- getDecoderConfig() {
184
- return this._backing.getDecoderConfig();
185
- }
186
- async getCodecParameterString() {
187
- const decoderConfig = await this._backing.getDecoderConfig();
188
- return decoderConfig?.codec ?? null;
189
- }
190
- async canDecode() {
191
- try {
192
- const decoderConfig = await this._backing.getDecoderConfig();
193
- if (!decoderConfig) {
194
- return false;
195
- }
196
- const codec = this._backing.getCodec();
197
- assert(codec !== null);
198
- if (customVideoDecoders.some(x => x.supports(codec, decoderConfig))) {
199
- return true;
200
- }
201
- if (typeof VideoDecoder === 'undefined') {
202
- return false;
203
- }
204
- const support = await VideoDecoder.isConfigSupported(decoderConfig);
205
- return support.supported === true;
206
- }
207
- catch (error) {
208
- console.error('Error during decodability check:', error);
209
- return false;
210
- }
211
- }
212
- async determinePacketType(packet) {
213
- if (!(packet instanceof EncodedPacket)) {
214
- throw new TypeError('packet must be an EncodedPacket.');
215
- }
216
- if (packet.isMetadataOnly) {
217
- throw new TypeError('packet must not be metadata-only to determine its type.');
218
- }
219
- if (this.codec === null) {
220
- return null;
221
- }
222
- const decoderConfig = await this.getDecoderConfig();
223
- assert(decoderConfig);
224
- return determineVideoPacketType(this.codec, decoderConfig, packet.data);
225
- }
226
- }
227
- /**
228
- * Represents an audio track in an input file.
229
- * @group Input files & tracks
230
- * @public
231
- */
232
- export class InputAudioTrack extends InputTrack {
233
- /** @internal */
234
- constructor(input, backing) {
235
- super(input, backing);
236
- this._backing = backing;
237
- }
238
- get type() {
239
- return 'audio';
240
- }
241
- get codec() {
242
- return this._backing.getCodec();
243
- }
244
- /** The number of audio channels in the track. */
245
- get numberOfChannels() {
246
- return this._backing.getNumberOfChannels();
247
- }
248
- /** The track's audio sample rate in hertz. */
249
- get sampleRate() {
250
- return this._backing.getSampleRate();
251
- }
252
- /**
253
- * Returns the [decoder configuration](https://www.w3.org/TR/webcodecs/#audio-decoder-config) for decoding the
254
- * track's packets using an [`AudioDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/AudioDecoder). Returns
255
- * null if the track's codec is unknown.
256
- */
257
- getDecoderConfig() {
258
- return this._backing.getDecoderConfig();
259
- }
260
- async getCodecParameterString() {
261
- const decoderConfig = await this._backing.getDecoderConfig();
262
- return decoderConfig?.codec ?? null;
263
- }
264
- async canDecode() {
265
- try {
266
- const decoderConfig = await this._backing.getDecoderConfig();
267
- if (!decoderConfig) {
268
- return false;
269
- }
270
- const codec = this._backing.getCodec();
271
- assert(codec !== null);
272
- if (customAudioDecoders.some(x => x.supports(codec, decoderConfig))) {
273
- return true;
274
- }
275
- if (decoderConfig.codec.startsWith('pcm-')) {
276
- return true; // Since we decode it ourselves
277
- }
278
- else {
279
- if (typeof AudioDecoder === 'undefined') {
280
- return false;
281
- }
282
- const support = await AudioDecoder.isConfigSupported(decoderConfig);
283
- return support.supported === true;
284
- }
285
- }
286
- catch (error) {
287
- console.error('Error during decodability check:', error);
288
- return false;
289
- }
290
- }
291
- async determinePacketType(packet) {
292
- if (!(packet instanceof EncodedPacket)) {
293
- throw new TypeError('packet must be an EncodedPacket.');
294
- }
295
- if (this.codec === null) {
296
- return null;
297
- }
298
- return 'key'; // No audio codec with delta packets
299
- }
300
- }
301
- /**
302
- * Represents a subtitle track in an input file.
303
- * @group Input files & tracks
304
- * @public
305
- */
306
- export class InputSubtitleTrack extends InputTrack {
307
- /** @internal */
308
- constructor(input, backing) {
309
- super(input, backing);
310
- this._backing = backing;
311
- }
312
- get type() {
313
- return 'subtitle';
314
- }
315
- get codec() {
316
- return this._backing.getCodec();
317
- }
318
- /**
319
- * Returns an async iterator that yields all subtitle cues in this track.
320
- */
321
- getCues() {
322
- return this._backing.getCues();
323
- }
324
- /**
325
- * Exports all subtitle cues to text format. If targetFormat is specified,
326
- * attempts to convert to that format (limited conversion support).
327
- */
328
- async exportToText(targetFormat) {
329
- const cues = [];
330
- for await (const cue of this.getCues()) {
331
- cues.push(cue);
332
- }
333
- const codec = targetFormat || this.codec;
334
- const codecPrivate = this._backing.getCodecPrivate();
335
- if (codec === 'srt') {
336
- const { formatCuesToSrt } = await import('./subtitles.js');
337
- return formatCuesToSrt(cues);
338
- }
339
- else if (codec === 'ass' || codec === 'ssa') {
340
- const { formatCuesToAss, splitAssIntoCues } = await import('./subtitles.js');
341
- // For ASS, we need to merge Comment lines from CodecPrivate with Dialogue lines from blocks
342
- // CodecPrivate contains: header + Comment lines
343
- // Blocks contain: Dialogue lines (without timestamps)
344
- // We need to reconstruct full ASS file
345
- // Parse CodecPrivate to extract the header with Comments preserved
346
- const parsed = codecPrivate ? splitAssIntoCues(codecPrivate) : { header: '', cues: [] };
347
- // Use the header (includes Comment lines) and add our cues (from blocks)
348
- return formatCuesToAss(cues, parsed.header);
349
- }
350
- else if (codec === 'webvtt') {
351
- const { formatCuesToWebVTT } = await import('./subtitles.js');
352
- // Use codecPrivate as preamble if available
353
- return formatCuesToWebVTT(cues, codecPrivate || undefined);
354
- }
355
- else {
356
- // Fallback to SRT for unknown formats
357
- const { formatCuesToSrt } = await import('./subtitles.js');
358
- return formatCuesToSrt(cues);
359
- }
360
- }
361
- async getCodecParameterString() {
362
- return this.codec;
363
- }
364
- async canDecode() {
365
- // Subtitles are always text-based and can be decoded
366
- return this.codec !== null;
367
- }
368
- async determinePacketType(packet) {
369
- // Subtitle packets are always key packets
370
- return 'key';
371
- }
372
- }
@@ -1,188 +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
- import { InputFormat } from './input-format.js';
9
- import { assert, polyfillSymbolDispose } from './misc.js';
10
- import { Reader } from './reader.js';
11
- import { Source } from './source.js';
12
- polyfillSymbolDispose();
13
- /**
14
- * Represents an input media file. This is the root object from which all media read operations start.
15
- * @group Input files & tracks
16
- * @public
17
- */
18
- export class Input {
19
- /** True if the input has been disposed. */
20
- get disposed() {
21
- return this._disposed;
22
- }
23
- /**
24
- * Creates a new input file from the specified options. No reading operations will be performed until methods are
25
- * called on this instance.
26
- */
27
- constructor(options) {
28
- /** @internal */
29
- this._demuxerPromise = null;
30
- /** @internal */
31
- this._format = null;
32
- /** @internal */
33
- this._disposed = false;
34
- if (!options || typeof options !== 'object') {
35
- throw new TypeError('options must be an object.');
36
- }
37
- if (!Array.isArray(options.formats) || options.formats.some(x => !(x instanceof InputFormat))) {
38
- throw new TypeError('options.formats must be an array of InputFormat.');
39
- }
40
- if (!(options.source instanceof Source)) {
41
- throw new TypeError('options.source must be a Source.');
42
- }
43
- if (options.source._disposed) {
44
- throw new Error('options.source must not be disposed.');
45
- }
46
- this._formats = options.formats;
47
- this._source = options.source;
48
- this._reader = new Reader(options.source);
49
- }
50
- /** @internal */
51
- _getDemuxer() {
52
- return this._demuxerPromise ??= (async () => {
53
- this._reader.fileSize = await this._source.getSizeOrNull();
54
- for (const format of this._formats) {
55
- const canRead = await format._canReadInput(this);
56
- if (canRead) {
57
- this._format = format;
58
- return format._createDemuxer(this);
59
- }
60
- }
61
- throw new Error('Input has an unsupported or unrecognizable format.');
62
- })();
63
- }
64
- /**
65
- * Returns the source from which this input file reads its data. This is the same source that was passed to the
66
- * constructor.
67
- */
68
- get source() {
69
- return this._source;
70
- }
71
- /**
72
- * Returns the format of the input file. You can compare this result directly to the {@link InputFormat} singletons
73
- * or use `instanceof` checks for subset-aware logic (for example, `format instanceof MatroskaInputFormat` is true
74
- * for both MKV and WebM).
75
- */
76
- async getFormat() {
77
- await this._getDemuxer();
78
- assert(this._format);
79
- return this._format;
80
- }
81
- /**
82
- * Computes the duration of the input file, in seconds. More precisely, returns the largest end timestamp among
83
- * all tracks.
84
- */
85
- async computeDuration() {
86
- const demuxer = await this._getDemuxer();
87
- return demuxer.computeDuration();
88
- }
89
- /** Returns the list of all tracks of this input file. */
90
- async getTracks() {
91
- const demuxer = await this._getDemuxer();
92
- return demuxer.getTracks();
93
- }
94
- /** Returns the list of all video tracks of this input file. */
95
- async getVideoTracks() {
96
- const tracks = await this.getTracks();
97
- return tracks.filter(x => x.isVideoTrack());
98
- }
99
- /** Returns the list of all audio tracks of this input file. */
100
- async getAudioTracks() {
101
- const tracks = await this.getTracks();
102
- return tracks.filter(x => x.isAudioTrack());
103
- }
104
- /** Returns the list of all subtitle tracks of this input file. */
105
- async getSubtitleTracks() {
106
- const tracks = await this.getTracks();
107
- return tracks.filter(x => x.isSubtitleTrack());
108
- }
109
- /** Returns the primary video track of this input file, or null if there are no video tracks. */
110
- async getPrimaryVideoTrack() {
111
- const tracks = await this.getTracks();
112
- return tracks.find(x => x.isVideoTrack()) ?? null;
113
- }
114
- /** Returns the primary audio track of this input file, or null if there are no audio tracks. */
115
- async getPrimaryAudioTrack() {
116
- const tracks = await this.getTracks();
117
- return tracks.find(x => x.isAudioTrack()) ?? null;
118
- }
119
- /**
120
- * Returns the list of all subtitle tracks of this input file. This is a convenience property that calls
121
- * {@link Input.getSubtitleTracks} and caches the result. Note that this property is a promise!
122
- */
123
- get subtitleTracks() {
124
- return this.getSubtitleTracks();
125
- }
126
- /**
127
- * Returns the list of all video tracks of this input file. This is a convenience property that calls
128
- * {@link Input.getVideoTracks} and caches the result. Note that this property is a promise!
129
- */
130
- get videoTracks() {
131
- return this.getVideoTracks();
132
- }
133
- /**
134
- * Returns the list of all audio tracks of this input file. This is a convenience property that calls
135
- * {@link Input.getAudioTracks} and caches the result. Note that this property is a promise!
136
- */
137
- get audioTracks() {
138
- return this.getAudioTracks();
139
- }
140
- /** Returns the full MIME type of this input file, including track codecs. */
141
- async getMimeType() {
142
- const demuxer = await this._getDemuxer();
143
- return demuxer.getMimeType();
144
- }
145
- /**
146
- * Returns descriptive metadata tags about the media file, such as title, author, date, cover art, or other
147
- * attached files.
148
- */
149
- async getMetadataTags() {
150
- const demuxer = await this._getDemuxer();
151
- return demuxer.getMetadataTags();
152
- }
153
- /**
154
- * Disposes this input and frees connected resources. When an input is disposed, ongoing read operations will be
155
- * canceled, all future read operations will fail, any open decoders will be closed, and all ongoing media sink
156
- * operations will be canceled. Disallowed and canceled operations will throw an {@link InputDisposedError}.
157
- *
158
- * You are expected not to use an input after disposing it. While some operations may still work, it is not
159
- * specified and may change in any future update.
160
- */
161
- dispose() {
162
- if (this._disposed) {
163
- return;
164
- }
165
- this._disposed = true;
166
- this._source._disposed = true;
167
- this._source._dispose();
168
- }
169
- /**
170
- * Calls `.dispose()` on the input, implementing the `Disposable` interface for use with
171
- * JavaScript Explicit Resource Management features.
172
- */
173
- [Symbol.dispose]() {
174
- this.dispose();
175
- }
176
- }
177
- /**
178
- * Thrown when an operation was prevented because the corresponding {@link Input} has been disposed.
179
- * @group Input files & tracks
180
- * @public
181
- */
182
- export class InputDisposedError extends Error {
183
- /** Creates a new {@link InputDisposedError}. */
184
- constructor(message = 'Input has been disposed.') {
185
- super(message);
186
- this.name = 'InputDisposedError';
187
- }
188
- }