mediabunny 1.0.2 → 1.0.4
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.
- package/README.md +4 -4
- package/dist/mediabunny.d.ts +4 -2
- package/dist/modules/codec-data.d.ts +95 -0
- package/dist/modules/codec-data.d.ts.map +1 -0
- package/dist/modules/codec-data.js +1103 -0
- package/dist/modules/codec.d.ts +250 -0
- package/dist/modules/codec.d.ts.map +1 -0
- package/dist/modules/codec.js +1100 -0
- package/dist/modules/conversion.d.ts +158 -0
- package/dist/modules/conversion.d.ts.map +1 -0
- package/dist/modules/conversion.js +866 -0
- package/dist/modules/custom-coder.d.ts +119 -0
- package/dist/modules/custom-coder.d.ts.map +1 -0
- package/dist/modules/custom-coder.js +91 -0
- package/dist/modules/demuxer.d.ts +17 -0
- package/dist/modules/demuxer.d.ts.map +1 -0
- package/dist/modules/demuxer.js +12 -0
- package/dist/modules/index.d.ts +25 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +24 -0
- package/dist/modules/input-format.d.ts +121 -0
- package/dist/modules/input-format.d.ts.map +1 -0
- package/dist/modules/input-format.js +333 -0
- package/dist/modules/input-track.d.ts +138 -0
- package/dist/modules/input-track.d.ts.map +1 -0
- package/dist/modules/input-track.js +230 -0
- package/dist/modules/input.d.ts +55 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +104 -0
- package/dist/modules/isobmff/isobmff-boxes.d.ts +202 -0
- package/dist/modules/isobmff/isobmff-boxes.d.ts.map +1 -0
- package/dist/modules/isobmff/isobmff-boxes.js +1111 -0
- package/dist/modules/isobmff/isobmff-demuxer.d.ts +163 -0
- package/dist/modules/isobmff/isobmff-demuxer.d.ts.map +1 -0
- package/dist/modules/isobmff/isobmff-demuxer.js +2080 -0
- package/dist/modules/isobmff/isobmff-misc.d.ts +14 -0
- package/dist/modules/isobmff/isobmff-misc.d.ts.map +1 -0
- package/dist/modules/isobmff/isobmff-misc.js +20 -0
- package/dist/modules/isobmff/isobmff-muxer.d.ts +142 -0
- package/dist/modules/isobmff/isobmff-muxer.d.ts.map +1 -0
- package/dist/modules/isobmff/isobmff-muxer.js +858 -0
- package/dist/modules/isobmff/isobmff-reader.d.ts +36 -0
- package/dist/modules/isobmff/isobmff-reader.d.ts.map +1 -0
- package/dist/modules/isobmff/isobmff-reader.js +105 -0
- package/dist/modules/matroska/ebml.d.ts +156 -0
- package/dist/modules/matroska/ebml.d.ts.map +1 -0
- package/dist/modules/matroska/ebml.js +529 -0
- package/dist/modules/matroska/matroska-demuxer.d.ts +119 -0
- package/dist/modules/matroska/matroska-demuxer.d.ts.map +1 -0
- package/dist/modules/matroska/matroska-demuxer.js +1330 -0
- package/dist/modules/matroska/matroska-misc.d.ts +14 -0
- package/dist/modules/matroska/matroska-misc.d.ts.map +1 -0
- package/dist/modules/matroska/matroska-misc.js +20 -0
- package/dist/modules/matroska/matroska-muxer.d.ts +71 -0
- package/dist/modules/matroska/matroska-muxer.d.ts.map +1 -0
- package/dist/modules/matroska/matroska-muxer.js +729 -0
- package/dist/modules/media-sink.d.ts +272 -0
- package/dist/modules/media-sink.d.ts.map +1 -0
- package/dist/modules/media-sink.js +1264 -0
- package/dist/modules/media-source.d.ts +230 -0
- package/dist/modules/media-source.d.ts.map +1 -0
- package/dist/modules/media-source.js +1095 -0
- package/dist/modules/misc.d.ts +127 -0
- package/dist/modules/misc.d.ts.map +1 -0
- package/dist/modules/misc.js +462 -0
- package/dist/modules/mp3/mp3-demuxer.d.ts +32 -0
- package/dist/modules/mp3/mp3-demuxer.d.ts.map +1 -0
- package/dist/modules/mp3/mp3-demuxer.js +160 -0
- package/dist/modules/mp3/mp3-misc.d.ts +37 -0
- package/dist/modules/mp3/mp3-misc.d.ts.map +1 -0
- package/dist/modules/mp3/mp3-misc.js +122 -0
- package/dist/modules/mp3/mp3-muxer.d.ts +27 -0
- package/dist/modules/mp3/mp3-muxer.d.ts.map +1 -0
- package/dist/modules/mp3/mp3-muxer.js +112 -0
- package/dist/modules/mp3/mp3-reader.d.ts +25 -0
- package/dist/modules/mp3/mp3-reader.d.ts.map +1 -0
- package/dist/modules/mp3/mp3-reader.js +73 -0
- package/dist/modules/mp3/mp3-writer.d.ts +30 -0
- package/dist/modules/mp3/mp3-writer.d.ts.map +1 -0
- package/dist/modules/mp3/mp3-writer.js +72 -0
- package/dist/modules/muxer.d.ts +32 -0
- package/dist/modules/muxer.d.ts.map +1 -0
- package/dist/modules/muxer.js +50 -0
- package/dist/modules/ogg/ogg-demuxer.d.ts +53 -0
- package/dist/modules/ogg/ogg-demuxer.d.ts.map +1 -0
- package/dist/modules/ogg/ogg-demuxer.js +701 -0
- package/dist/modules/ogg/ogg-misc.d.ts +27 -0
- package/dist/modules/ogg/ogg-misc.d.ts.map +1 -0
- package/dist/modules/ogg/ogg-misc.js +78 -0
- package/dist/modules/ogg/ogg-muxer.d.ts +58 -0
- package/dist/modules/ogg/ogg-muxer.d.ts.map +1 -0
- package/dist/modules/ogg/ogg-muxer.js +345 -0
- package/dist/modules/ogg/ogg-reader.d.ts +37 -0
- package/dist/modules/ogg/ogg-reader.d.ts.map +1 -0
- package/dist/modules/ogg/ogg-reader.js +104 -0
- package/dist/modules/output-format.d.ts +285 -0
- package/dist/modules/output-format.d.ts.map +1 -0
- package/dist/modules/output-format.js +385 -0
- package/dist/modules/output.d.ts +134 -0
- package/dist/modules/output.d.ts.map +1 -0
- package/dist/modules/output.js +269 -0
- package/dist/modules/packet.d.ts +86 -0
- package/dist/modules/packet.d.ts.map +1 -0
- package/dist/modules/packet.js +133 -0
- package/dist/modules/pcm.d.ts +12 -0
- package/dist/modules/pcm.d.ts.map +1 -0
- package/dist/modules/pcm.js +85 -0
- package/dist/modules/reader.d.ts +40 -0
- package/dist/modules/reader.d.ts.map +1 -0
- package/dist/modules/reader.js +153 -0
- package/dist/modules/sample.d.ts +186 -0
- package/dist/modules/sample.d.ts.map +1 -0
- package/dist/modules/sample.js +798 -0
- package/dist/modules/source.d.ts +76 -0
- package/dist/modules/source.d.ts.map +1 -0
- package/dist/modules/source.js +183 -0
- package/dist/modules/subtitles.d.ts +37 -0
- package/dist/modules/subtitles.d.ts.map +1 -0
- package/dist/modules/subtitles.js +89 -0
- package/dist/modules/target.d.ts +58 -0
- package/dist/modules/target.d.ts.map +1 -0
- package/dist/modules/target.js +63 -0
- package/dist/modules/wave/riff-reader.d.ts +19 -0
- package/dist/modules/wave/riff-reader.d.ts.map +1 -0
- package/dist/modules/wave/riff-reader.js +38 -0
- package/dist/modules/wave/riff-writer.d.ts +18 -0
- package/dist/modules/wave/riff-writer.d.ts.map +1 -0
- package/dist/modules/wave/riff-writer.js +25 -0
- package/dist/modules/wave/wave-demuxer.d.ts +42 -0
- package/dist/modules/wave/wave-demuxer.d.ts.map +1 -0
- package/dist/modules/wave/wave-demuxer.js +239 -0
- package/dist/modules/wave/wave-muxer.d.ts +27 -0
- package/dist/modules/wave/wave-muxer.d.ts.map +1 -0
- package/dist/modules/wave/wave-muxer.js +108 -0
- package/dist/modules/writer.d.ts +85 -0
- package/dist/modules/writer.d.ts.map +1 -0
- package/dist/modules/writer.js +347 -0
- package/package.json +14 -10
- package/src/codec-data.ts +1394 -0
- package/src/codec.ts +1392 -0
- package/src/conversion.ts +1199 -0
- package/src/custom-coder.ts +162 -0
- package/src/demuxer.ts +22 -0
- package/src/index.ts +148 -0
- package/src/input-format.ts +386 -0
- package/src/input-track.ts +341 -0
- package/src/input.ts +138 -0
- package/src/isobmff/isobmff-boxes.ts +1365 -0
- package/src/isobmff/isobmff-demuxer.ts +2646 -0
- package/src/isobmff/isobmff-misc.ts +29 -0
- package/src/isobmff/isobmff-muxer.ts +1210 -0
- package/src/isobmff/isobmff-reader.ts +137 -0
- package/src/matroska/ebml.ts +595 -0
- package/src/matroska/matroska-demuxer.ts +1677 -0
- package/src/matroska/matroska-misc.ts +29 -0
- package/src/matroska/matroska-muxer.ts +999 -0
- package/src/media-sink.ts +1577 -0
- package/src/media-source.ts +1406 -0
- package/src/misc.ts +584 -0
- package/src/mp3/mp3-demuxer.ts +228 -0
- package/src/mp3/mp3-misc.ts +154 -0
- package/src/mp3/mp3-muxer.ts +153 -0
- package/src/mp3/mp3-reader.ts +93 -0
- package/src/mp3/mp3-writer.ts +112 -0
- package/src/muxer.ts +88 -0
- package/src/ogg/ogg-demuxer.ts +985 -0
- package/src/ogg/ogg-misc.ts +116 -0
- package/src/ogg/ogg-muxer.ts +480 -0
- package/src/ogg/ogg-reader.ts +143 -0
- package/src/output-format.ts +689 -0
- package/src/output.ts +427 -0
- package/src/packet.ts +180 -0
- package/src/pcm.ts +112 -0
- package/src/reader.ts +205 -0
- package/src/sample.ts +1029 -0
- package/src/source.ts +279 -0
- package/src/subtitles.ts +131 -0
- package/src/target.ts +106 -0
- package/src/tsconfig.json +13 -0
- package/src/wave/riff-reader.ts +48 -0
- package/src/wave/riff-writer.ts +30 -0
- package/src/wave/wave-demuxer.ts +317 -0
- package/src/wave/wave-muxer.ts +145 -0
- package/src/writer.ts +461 -0
- /package/dist/{mediabunny.js → bundles/mediabunny.cjs} +0 -0
- /package/dist/{mediabunny.min.js → bundles/mediabunny.min.cjs} +0 -0
- /package/dist/{mediabunny.min.mjs → bundles/mediabunny.min.mjs} +0 -0
- /package/dist/{mediabunny.mjs → bundles/mediabunny.mjs} +0 -0
|
@@ -0,0 +1,333 @@
|
|
|
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 { IsobmffDemuxer } from './isobmff/isobmff-demuxer.js';
|
|
9
|
+
import { IsobmffReader } from './isobmff/isobmff-reader.js';
|
|
10
|
+
import { EBMLId, EBMLReader } from './matroska/ebml.js';
|
|
11
|
+
import { MatroskaDemuxer } from './matroska/matroska-demuxer.js';
|
|
12
|
+
import { Mp3Demuxer } from './mp3/mp3-demuxer.js';
|
|
13
|
+
import { Mp3Reader } from './mp3/mp3-reader.js';
|
|
14
|
+
import { OggDemuxer } from './ogg/ogg-demuxer.js';
|
|
15
|
+
import { OggReader } from './ogg/ogg-reader.js';
|
|
16
|
+
import { RiffReader } from './wave/riff-reader.js';
|
|
17
|
+
import { WaveDemuxer } from './wave/wave-demuxer.js';
|
|
18
|
+
/**
|
|
19
|
+
* Base class representing an input media file format.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export class InputFormat {
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Format representing files compatible with the ISO base media file format (ISOBMFF), like MP4 or MOV files.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class IsobmffInputFormat extends InputFormat {
|
|
29
|
+
/** @internal */
|
|
30
|
+
async _getMajorBrand(input) {
|
|
31
|
+
const sourceSize = await input._mainReader.source.getSize();
|
|
32
|
+
if (sourceSize < 12) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const isobmffReader = new IsobmffReader(input._mainReader);
|
|
36
|
+
isobmffReader.pos = 4;
|
|
37
|
+
const fourCc = isobmffReader.readAscii(4);
|
|
38
|
+
if (fourCc !== 'ftyp') {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return isobmffReader.readAscii(4);
|
|
42
|
+
}
|
|
43
|
+
/** @internal */
|
|
44
|
+
_createDemuxer(input) {
|
|
45
|
+
return new IsobmffDemuxer(input);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* MPEG-4 Part 14 (MP4) file format.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export class Mp4InputFormat extends IsobmffInputFormat {
|
|
53
|
+
/** @internal */
|
|
54
|
+
async _canReadInput(input) {
|
|
55
|
+
const majorBrand = await this._getMajorBrand(input);
|
|
56
|
+
return !!majorBrand && majorBrand !== 'qt ';
|
|
57
|
+
}
|
|
58
|
+
get name() {
|
|
59
|
+
return 'MP4';
|
|
60
|
+
}
|
|
61
|
+
get mimeType() {
|
|
62
|
+
return 'video/mp4';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* QuickTime File Format (QTFF), often called MOV.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export class QuickTimeInputFormat extends IsobmffInputFormat {
|
|
70
|
+
/** @internal */
|
|
71
|
+
async _canReadInput(input) {
|
|
72
|
+
const majorBrand = await this._getMajorBrand(input);
|
|
73
|
+
return majorBrand === 'qt ';
|
|
74
|
+
}
|
|
75
|
+
get name() {
|
|
76
|
+
return 'QuickTime File Format';
|
|
77
|
+
}
|
|
78
|
+
get mimeType() {
|
|
79
|
+
return 'video/quicktime';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Matroska file format.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export class MatroskaInputFormat extends InputFormat {
|
|
87
|
+
/** @internal */
|
|
88
|
+
async isSupportedEBMLOfDocType(input, desiredDocType) {
|
|
89
|
+
const sourceSize = await input._mainReader.source.getSize();
|
|
90
|
+
if (sourceSize < 8) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const ebmlReader = new EBMLReader(input._mainReader);
|
|
94
|
+
const varIntSize = ebmlReader.readVarIntSize();
|
|
95
|
+
if (varIntSize < 1 || varIntSize > 8) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const id = ebmlReader.readUnsignedInt(varIntSize);
|
|
99
|
+
if (id !== EBMLId.EBML) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const dataSize = ebmlReader.readElementSize();
|
|
103
|
+
if (dataSize === null) {
|
|
104
|
+
return false; // Miss me with that shit
|
|
105
|
+
}
|
|
106
|
+
const startPos = ebmlReader.pos;
|
|
107
|
+
while (ebmlReader.pos < startPos + dataSize) {
|
|
108
|
+
const { id, size } = ebmlReader.readElementHeader();
|
|
109
|
+
const dataStartPos = ebmlReader.pos;
|
|
110
|
+
if (size === null)
|
|
111
|
+
return false;
|
|
112
|
+
switch (id) {
|
|
113
|
+
case EBMLId.EBMLVersion:
|
|
114
|
+
{
|
|
115
|
+
const ebmlVersion = ebmlReader.readUnsignedInt(size);
|
|
116
|
+
if (ebmlVersion !== 1) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
;
|
|
121
|
+
break;
|
|
122
|
+
case EBMLId.EBMLReadVersion:
|
|
123
|
+
{
|
|
124
|
+
const ebmlReadVersion = ebmlReader.readUnsignedInt(size);
|
|
125
|
+
if (ebmlReadVersion !== 1) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
;
|
|
130
|
+
break;
|
|
131
|
+
case EBMLId.DocType:
|
|
132
|
+
{
|
|
133
|
+
const docType = ebmlReader.readString(size);
|
|
134
|
+
if (docType !== desiredDocType) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
;
|
|
139
|
+
break;
|
|
140
|
+
case EBMLId.DocTypeVersion:
|
|
141
|
+
{
|
|
142
|
+
const docTypeVersion = ebmlReader.readUnsignedInt(size);
|
|
143
|
+
if (docTypeVersion > 4) { // Support up to Matroska v4
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
ebmlReader.pos = dataStartPos + size;
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
/** @internal */
|
|
155
|
+
_canReadInput(input) {
|
|
156
|
+
return this.isSupportedEBMLOfDocType(input, 'matroska');
|
|
157
|
+
}
|
|
158
|
+
/** @internal */
|
|
159
|
+
_createDemuxer(input) {
|
|
160
|
+
return new MatroskaDemuxer(input);
|
|
161
|
+
}
|
|
162
|
+
get name() {
|
|
163
|
+
return 'Matroska';
|
|
164
|
+
}
|
|
165
|
+
get mimeType() {
|
|
166
|
+
return 'video/x-matroska';
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* WebM file format, based on Matroska.
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
export class WebMInputFormat extends MatroskaInputFormat {
|
|
174
|
+
/** @internal */
|
|
175
|
+
_canReadInput(input) {
|
|
176
|
+
return this.isSupportedEBMLOfDocType(input, 'webm');
|
|
177
|
+
}
|
|
178
|
+
get name() {
|
|
179
|
+
return 'WebM';
|
|
180
|
+
}
|
|
181
|
+
get mimeType() {
|
|
182
|
+
return 'video/webm';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* MP3 file format.
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
export class Mp3InputFormat extends InputFormat {
|
|
190
|
+
/** @internal */
|
|
191
|
+
async _canReadInput(input) {
|
|
192
|
+
const sourceSize = await input._mainReader.source.getSize();
|
|
193
|
+
if (sourceSize < 4) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const mp3Reader = new Mp3Reader(input._mainReader);
|
|
197
|
+
mp3Reader.fileSize = sourceSize;
|
|
198
|
+
const id3Tag = mp3Reader.readId3();
|
|
199
|
+
if (id3Tag) {
|
|
200
|
+
mp3Reader.pos += id3Tag.size;
|
|
201
|
+
}
|
|
202
|
+
const framesStartPos = mp3Reader.pos;
|
|
203
|
+
await mp3Reader.reader.loadRange(mp3Reader.pos, mp3Reader.pos + 4096);
|
|
204
|
+
const firstHeader = mp3Reader.readNextFrameHeader(Math.min(framesStartPos + 4096, sourceSize));
|
|
205
|
+
if (!firstHeader) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (id3Tag) {
|
|
209
|
+
// If there was an ID3 tag at the start, we can be pretty sure this is MP3 by now
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
// Fine, we found one frame header, but we're still not entirely sure this is MP3. Let's check if we can find
|
|
213
|
+
// another header nearby:
|
|
214
|
+
mp3Reader.pos = firstHeader.startPos + firstHeader.totalSize;
|
|
215
|
+
const secondHeader = mp3Reader.readNextFrameHeader(Math.min(framesStartPos + 4096, sourceSize));
|
|
216
|
+
if (!secondHeader) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
// In a well-formed MP3 file, we'd expect these two frames to share some similarities:
|
|
220
|
+
if (firstHeader.channel !== secondHeader.channel || firstHeader.sampleRate !== secondHeader.sampleRate) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
// We have found two matching MP3 frames, a strong indicator that this is an MP3 file
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
/** @internal */
|
|
227
|
+
_createDemuxer(input) {
|
|
228
|
+
return new Mp3Demuxer(input);
|
|
229
|
+
}
|
|
230
|
+
get name() {
|
|
231
|
+
return 'MP3';
|
|
232
|
+
}
|
|
233
|
+
get mimeType() {
|
|
234
|
+
return 'audio/mpeg';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* WAVE file format, based on RIFF.
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
export class WaveInputFormat extends InputFormat {
|
|
242
|
+
/** @internal */
|
|
243
|
+
async _canReadInput(input) {
|
|
244
|
+
const sourceSize = await input._mainReader.source.getSize();
|
|
245
|
+
if (sourceSize < 12) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const riffReader = new RiffReader(input._mainReader);
|
|
249
|
+
const riffType = riffReader.readAscii(4);
|
|
250
|
+
if (riffType !== 'RIFF' && riffType !== 'RIFX') {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
riffReader.pos = 8;
|
|
254
|
+
const format = riffReader.readAscii(4);
|
|
255
|
+
return format === 'WAVE';
|
|
256
|
+
}
|
|
257
|
+
/** @internal */
|
|
258
|
+
_createDemuxer(input) {
|
|
259
|
+
return new WaveDemuxer(input);
|
|
260
|
+
}
|
|
261
|
+
get name() {
|
|
262
|
+
return 'WAVE';
|
|
263
|
+
}
|
|
264
|
+
get mimeType() {
|
|
265
|
+
return 'audio/wav';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Ogg file format.
|
|
270
|
+
* @public
|
|
271
|
+
*/
|
|
272
|
+
export class OggInputFormat extends InputFormat {
|
|
273
|
+
/** @internal */
|
|
274
|
+
async _canReadInput(input) {
|
|
275
|
+
const sourceSize = await input._mainReader.source.getSize();
|
|
276
|
+
if (sourceSize < 4) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
const oggReader = new OggReader(input._mainReader);
|
|
280
|
+
return oggReader.readAscii(4) === 'OggS';
|
|
281
|
+
}
|
|
282
|
+
/** @internal */
|
|
283
|
+
_createDemuxer(input) {
|
|
284
|
+
return new OggDemuxer(input);
|
|
285
|
+
}
|
|
286
|
+
get name() {
|
|
287
|
+
return 'Ogg';
|
|
288
|
+
}
|
|
289
|
+
get mimeType() {
|
|
290
|
+
return 'application/ogg';
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* MP4 input format singleton.
|
|
295
|
+
* @public
|
|
296
|
+
*/
|
|
297
|
+
export const MP4 = new Mp4InputFormat();
|
|
298
|
+
/**
|
|
299
|
+
* QuickTime File Format input format singleton.
|
|
300
|
+
* @public
|
|
301
|
+
*/
|
|
302
|
+
export const QTFF = new QuickTimeInputFormat();
|
|
303
|
+
/**
|
|
304
|
+
* Matroska input format singleton.
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
export const MATROSKA = new MatroskaInputFormat();
|
|
308
|
+
/**
|
|
309
|
+
* WebM input format singleton.
|
|
310
|
+
* @public
|
|
311
|
+
*/
|
|
312
|
+
export const WEBM = new WebMInputFormat();
|
|
313
|
+
/**
|
|
314
|
+
* MP3 input format singleton.
|
|
315
|
+
* @public
|
|
316
|
+
*/
|
|
317
|
+
export const MP3 = new Mp3InputFormat();
|
|
318
|
+
/**
|
|
319
|
+
* WAVE input format singleton.
|
|
320
|
+
* @public
|
|
321
|
+
*/
|
|
322
|
+
export const WAVE = new WaveInputFormat();
|
|
323
|
+
/**
|
|
324
|
+
* Ogg input format singleton.
|
|
325
|
+
* @public
|
|
326
|
+
*/
|
|
327
|
+
export const OGG = new OggInputFormat();
|
|
328
|
+
/**
|
|
329
|
+
* List of all input format singletons. If you don't need to support all input formats, you should specify the
|
|
330
|
+
* formats individually for better tree shaking.
|
|
331
|
+
* @public
|
|
332
|
+
*/
|
|
333
|
+
export const ALL_FORMATS = [MP4, QTFF, MATROSKA, WEBM, WAVE, OGG, MP3];
|
|
@@ -0,0 +1,138 @@
|
|
|
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 { AudioCodec, MediaCodec, VideoCodec } from './codec';
|
|
9
|
+
import { PacketRetrievalOptions } from './media-sink';
|
|
10
|
+
import { Rotation } from './misc';
|
|
11
|
+
import { TrackType } from './output';
|
|
12
|
+
import { EncodedPacket } from './packet';
|
|
13
|
+
/**
|
|
14
|
+
* Contains aggregate statistics about the encoded packets of a track.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export type PacketStats = {
|
|
18
|
+
/** The total number of packets. */
|
|
19
|
+
packetCount: number;
|
|
20
|
+
/** The average number of packets per second. For video tracks, this will equal the average frame rate (FPS). */
|
|
21
|
+
averagePacketRate: number;
|
|
22
|
+
/** The average number of bits per second. */
|
|
23
|
+
averageBitrate: number;
|
|
24
|
+
};
|
|
25
|
+
export interface InputTrackBacking {
|
|
26
|
+
getId(): number;
|
|
27
|
+
getCodec(): MediaCodec | null;
|
|
28
|
+
getLanguageCode(): string;
|
|
29
|
+
getTimeResolution(): number;
|
|
30
|
+
getFirstTimestamp(): Promise<number>;
|
|
31
|
+
computeDuration(): Promise<number>;
|
|
32
|
+
getFirstPacket(options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
|
|
33
|
+
getPacket(timestamp: number, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
|
|
34
|
+
getNextPacket(packet: EncodedPacket, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
|
|
35
|
+
getKeyPacket(timestamp: number, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
|
|
36
|
+
getNextKeyPacket(packet: EncodedPacket, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Represents a media track in an input file.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare abstract class InputTrack {
|
|
43
|
+
/** The type of the track. */
|
|
44
|
+
abstract get type(): TrackType;
|
|
45
|
+
/** The codec of the track's packets. */
|
|
46
|
+
abstract get codec(): MediaCodec | null;
|
|
47
|
+
/** Returns the full codec parameter string for this track. */
|
|
48
|
+
abstract getCodecParameterString(): Promise<string | null>;
|
|
49
|
+
/** Checks if this track's packets can be decoded by the browser. */
|
|
50
|
+
abstract canDecode(): Promise<boolean>;
|
|
51
|
+
/** Returns true iff this track is a video track. */
|
|
52
|
+
isVideoTrack(): this is InputVideoTrack;
|
|
53
|
+
/** Returns true iff this track is an audio track. */
|
|
54
|
+
isAudioTrack(): this is InputAudioTrack;
|
|
55
|
+
/** The unique ID of this track in the input file. */
|
|
56
|
+
get id(): number;
|
|
57
|
+
/** The ISO 639-2/T language code for this track. If the language is unknown, this field is 'und' (undetermined). */
|
|
58
|
+
get languageCode(): string;
|
|
59
|
+
/**
|
|
60
|
+
* A positive number x such that all timestamps and durations of all packets of this track are
|
|
61
|
+
* integer multiples of 1/x.
|
|
62
|
+
*/
|
|
63
|
+
get timeResolution(): number;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value
|
|
66
|
+
* may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples
|
|
67
|
+
* with a negative timestamp should not be presented.
|
|
68
|
+
*/
|
|
69
|
+
getFirstTimestamp(): Promise<number>;
|
|
70
|
+
/** Returns the end timestamp of the last packet of this track, in seconds. */
|
|
71
|
+
computeDuration(): Promise<number>;
|
|
72
|
+
/**
|
|
73
|
+
* Computes aggregate packet statistics for this track, such as average packet rate or bitrate.
|
|
74
|
+
*
|
|
75
|
+
* @param targetPacketCount - This optional parameter sets a target for how many packets this method must have
|
|
76
|
+
* looked at before it can return early; this means, you can use it to aggregate only a subset (prefix) of all
|
|
77
|
+
* packets. This is very useful for getting a great estimate of video frame rate without having to scan through the
|
|
78
|
+
* entire file.
|
|
79
|
+
*/
|
|
80
|
+
computePacketStats(targetPacketCount?: number): Promise<PacketStats>;
|
|
81
|
+
}
|
|
82
|
+
export interface InputVideoTrackBacking extends InputTrackBacking {
|
|
83
|
+
getCodec(): VideoCodec | null;
|
|
84
|
+
getCodedWidth(): number;
|
|
85
|
+
getCodedHeight(): number;
|
|
86
|
+
getRotation(): Rotation;
|
|
87
|
+
getColorSpace(): Promise<VideoColorSpaceInit>;
|
|
88
|
+
getDecoderConfig(): Promise<VideoDecoderConfig | null>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Represents a video track in an input file.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
export declare class InputVideoTrack extends InputTrack {
|
|
95
|
+
get type(): TrackType;
|
|
96
|
+
get codec(): "avc" | "hevc" | "vp9" | "av1" | "vp8" | null;
|
|
97
|
+
/** The width in pixels of the track's coded samples, before any transformations or rotations. */
|
|
98
|
+
get codedWidth(): number;
|
|
99
|
+
/** The height in pixels of the track's coded samples, before any transformations or rotations. */
|
|
100
|
+
get codedHeight(): number;
|
|
101
|
+
/** The angle in degrees by which the track's frames should be rotated (clockwise). */
|
|
102
|
+
get rotation(): Rotation;
|
|
103
|
+
/** The width in pixels of the track's frames after rotation. */
|
|
104
|
+
get displayWidth(): number;
|
|
105
|
+
/** The height in pixels of the track's frames after rotation. */
|
|
106
|
+
get displayHeight(): number;
|
|
107
|
+
/** Returns the color space of the track's samples. */
|
|
108
|
+
getColorSpace(): Promise<VideoColorSpaceInit>;
|
|
109
|
+
/** If this method returns true, the track's samples use a high dynamic range (HDR). */
|
|
110
|
+
hasHighDynamicRange(): Promise<boolean>;
|
|
111
|
+
/** Returns the decoder configuration for decoding the track's packets using a VideoDecoder. */
|
|
112
|
+
getDecoderConfig(): Promise<VideoDecoderConfig | null>;
|
|
113
|
+
getCodecParameterString(): Promise<string | null>;
|
|
114
|
+
canDecode(): Promise<boolean>;
|
|
115
|
+
}
|
|
116
|
+
export interface InputAudioTrackBacking extends InputTrackBacking {
|
|
117
|
+
getCodec(): AudioCodec | null;
|
|
118
|
+
getNumberOfChannels(): number;
|
|
119
|
+
getSampleRate(): number;
|
|
120
|
+
getDecoderConfig(): Promise<AudioDecoderConfig | null>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Represents an audio track in an input file.
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export declare class InputAudioTrack extends InputTrack {
|
|
127
|
+
get type(): TrackType;
|
|
128
|
+
get codec(): AudioCodec | null;
|
|
129
|
+
/** The number of audio channels in the track. */
|
|
130
|
+
get numberOfChannels(): number;
|
|
131
|
+
/** The track's audio sample rate in hertz. */
|
|
132
|
+
get sampleRate(): number;
|
|
133
|
+
/** Returns the decoder configuration for decoding the track's packets using an AudioDecoder. */
|
|
134
|
+
getDecoderConfig(): Promise<AudioDecoderConfig | null>;
|
|
135
|
+
getCodecParameterString(): Promise<string | null>;
|
|
136
|
+
canDecode(): Promise<boolean>;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=input-track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-track.d.ts","sourceRoot":"","sources":["../../src/input-track.ts"],"names":[],"mappings":"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"}
|