@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.
- package/README.md +1 -1
- package/dist/bundles/{mediabunny.mjs → mediabunny.js} +21963 -21390
- package/dist/bundles/mediabunny.min.js +490 -0
- package/dist/modules/shared/mp3-misc.d.ts.map +1 -1
- package/dist/modules/src/adts/adts-demuxer.d.ts +6 -6
- package/dist/modules/src/adts/adts-demuxer.d.ts.map +1 -1
- package/dist/modules/src/adts/adts-muxer.d.ts +4 -4
- package/dist/modules/src/adts/adts-muxer.d.ts.map +1 -1
- package/dist/modules/src/adts/adts-reader.d.ts +1 -1
- package/dist/modules/src/adts/adts-reader.d.ts.map +1 -1
- package/dist/modules/src/avi/avi-demuxer.d.ts +44 -0
- package/dist/modules/src/avi/avi-demuxer.d.ts.map +1 -0
- package/dist/modules/src/avi/avi-misc.d.ts +88 -0
- package/dist/modules/src/avi/avi-misc.d.ts.map +1 -0
- package/dist/modules/src/avi/avi-muxer.d.ts +45 -0
- package/dist/modules/src/avi/avi-muxer.d.ts.map +1 -0
- package/dist/modules/src/avi/riff-writer.d.ts +26 -0
- package/dist/modules/src/avi/riff-writer.d.ts.map +1 -0
- package/dist/modules/src/codec-data.d.ts +8 -3
- package/dist/modules/src/codec-data.d.ts.map +1 -1
- package/dist/modules/src/codec.d.ts +10 -10
- package/dist/modules/src/codec.d.ts.map +1 -1
- package/dist/modules/src/conversion.d.ts +33 -16
- package/dist/modules/src/conversion.d.ts.map +1 -1
- package/dist/modules/src/custom-coder.d.ts +8 -8
- package/dist/modules/src/custom-coder.d.ts.map +1 -1
- package/dist/modules/src/demuxer.d.ts +3 -3
- package/dist/modules/src/demuxer.d.ts.map +1 -1
- package/dist/modules/src/encode.d.ts +8 -8
- package/dist/modules/src/encode.d.ts.map +1 -1
- package/dist/modules/src/flac/flac-demuxer.d.ts +7 -7
- package/dist/modules/src/flac/flac-demuxer.d.ts.map +1 -1
- package/dist/modules/src/flac/flac-misc.d.ts +3 -3
- package/dist/modules/src/flac/flac-misc.d.ts.map +1 -1
- package/dist/modules/src/flac/flac-muxer.d.ts +5 -5
- package/dist/modules/src/flac/flac-muxer.d.ts.map +1 -1
- package/dist/modules/src/id3.d.ts +3 -3
- package/dist/modules/src/id3.d.ts.map +1 -1
- package/dist/modules/src/index.d.ts +20 -20
- package/dist/modules/src/index.d.ts.map +1 -1
- package/dist/modules/src/input-format.d.ts +22 -0
- package/dist/modules/src/input-format.d.ts.map +1 -1
- package/dist/modules/src/input-track.d.ts +8 -8
- package/dist/modules/src/input-track.d.ts.map +1 -1
- package/dist/modules/src/input.d.ts +12 -12
- package/dist/modules/src/isobmff/isobmff-boxes.d.ts +2 -2
- package/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts +12 -12
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-misc.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-muxer.d.ts +11 -11
- package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-reader.d.ts +2 -2
- package/dist/modules/src/isobmff/isobmff-reader.d.ts.map +1 -1
- package/dist/modules/src/matroska/ebml.d.ts +3 -3
- package/dist/modules/src/matroska/ebml.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-demuxer.d.ts +13 -13
- package/dist/modules/src/matroska/matroska-demuxer.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-input.d.ts +33 -0
- package/dist/modules/src/matroska/matroska-input.d.ts.map +1 -0
- package/dist/modules/src/matroska/matroska-misc.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-muxer.d.ts +5 -5
- package/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -1
- package/dist/modules/src/media-sink.d.ts +5 -5
- package/dist/modules/src/media-sink.d.ts.map +1 -1
- package/dist/modules/src/media-source.d.ts +22 -4
- package/dist/modules/src/media-source.d.ts.map +1 -1
- package/dist/modules/src/metadata.d.ts +2 -2
- package/dist/modules/src/metadata.d.ts.map +1 -1
- package/dist/modules/src/misc.d.ts +5 -4
- package/dist/modules/src/misc.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-demuxer.d.ts +7 -7
- package/dist/modules/src/mp3/mp3-demuxer.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-muxer.d.ts +4 -4
- package/dist/modules/src/mp3/mp3-muxer.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-reader.d.ts +2 -2
- package/dist/modules/src/mp3/mp3-reader.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-writer.d.ts +1 -1
- package/dist/modules/src/mp3/mp3-writer.d.ts.map +1 -1
- package/dist/modules/src/muxer.d.ts +4 -4
- package/dist/modules/src/muxer.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-demuxer.d.ts +7 -7
- package/dist/modules/src/ogg/ogg-demuxer.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-misc.d.ts +1 -1
- package/dist/modules/src/ogg/ogg-misc.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-muxer.d.ts +5 -5
- package/dist/modules/src/ogg/ogg-muxer.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-reader.d.ts +1 -1
- package/dist/modules/src/ogg/ogg-reader.d.ts.map +1 -1
- package/dist/modules/src/output-format.d.ts +51 -6
- package/dist/modules/src/output-format.d.ts.map +1 -1
- package/dist/modules/src/output.d.ts +13 -13
- package/dist/modules/src/output.d.ts.map +1 -1
- package/dist/modules/src/packet.d.ts +1 -1
- package/dist/modules/src/packet.d.ts.map +1 -1
- package/dist/modules/src/pcm.d.ts.map +1 -1
- package/dist/modules/src/reader.d.ts +2 -2
- package/dist/modules/src/reader.d.ts.map +1 -1
- package/dist/modules/src/sample.d.ts +57 -15
- package/dist/modules/src/sample.d.ts.map +1 -1
- package/dist/modules/src/source.d.ts +3 -3
- package/dist/modules/src/source.d.ts.map +1 -1
- package/dist/modules/src/subtitles.d.ts +1 -1
- package/dist/modules/src/subtitles.d.ts.map +1 -1
- package/dist/modules/src/target.d.ts +2 -2
- package/dist/modules/src/target.d.ts.map +1 -1
- package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
- package/dist/modules/src/wave/riff-writer.d.ts +1 -1
- package/dist/modules/src/wave/riff-writer.d.ts.map +1 -1
- package/dist/modules/src/wave/wave-demuxer.d.ts +6 -6
- package/dist/modules/src/wave/wave-demuxer.d.ts.map +1 -1
- package/dist/modules/src/wave/wave-muxer.d.ts +4 -4
- package/dist/modules/src/wave/wave-muxer.d.ts.map +1 -1
- package/dist/modules/src/writer.d.ts +1 -1
- package/dist/modules/src/writer.d.ts.map +1 -1
- package/dist/packages/eac3/eac3.wasm +0 -0
- package/dist/packages/eac3/mediabunny-eac3.js +1058 -0
- package/dist/packages/eac3/mediabunny-eac3.min.js +44 -0
- package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.js +694 -0
- package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.min.js +58 -0
- package/dist/packages/mpeg4/mediabunny-mpeg4.js +1198 -0
- package/dist/packages/mpeg4/mediabunny-mpeg4.min.js +44 -0
- package/dist/packages/mpeg4/xvid.wasm +0 -0
- package/package.json +18 -57
- package/dist/bundles/mediabunny.cjs +0 -26140
- package/dist/bundles/mediabunny.min.cjs +0 -147
- package/dist/bundles/mediabunny.min.mjs +0 -146
- package/dist/mediabunny.d.ts +0 -3319
- package/dist/modules/shared/mp3-misc.js +0 -147
- package/dist/modules/src/adts/adts-demuxer.js +0 -239
- package/dist/modules/src/adts/adts-muxer.js +0 -80
- package/dist/modules/src/adts/adts-reader.js +0 -63
- package/dist/modules/src/codec-data.js +0 -1730
- package/dist/modules/src/codec.js +0 -869
- package/dist/modules/src/conversion.js +0 -1459
- package/dist/modules/src/custom-coder.js +0 -117
- package/dist/modules/src/demuxer.js +0 -12
- package/dist/modules/src/encode.js +0 -442
- package/dist/modules/src/flac/flac-demuxer.js +0 -504
- package/dist/modules/src/flac/flac-misc.js +0 -135
- package/dist/modules/src/flac/flac-muxer.js +0 -222
- package/dist/modules/src/id3.js +0 -848
- package/dist/modules/src/index.js +0 -28
- package/dist/modules/src/input-format.js +0 -480
- package/dist/modules/src/input-track.js +0 -372
- package/dist/modules/src/input.js +0 -188
- package/dist/modules/src/isobmff/isobmff-boxes.js +0 -1480
- package/dist/modules/src/isobmff/isobmff-demuxer.js +0 -2618
- package/dist/modules/src/isobmff/isobmff-misc.js +0 -20
- package/dist/modules/src/isobmff/isobmff-muxer.js +0 -966
- package/dist/modules/src/isobmff/isobmff-reader.js +0 -72
- package/dist/modules/src/matroska/ebml.js +0 -653
- package/dist/modules/src/matroska/matroska-demuxer.js +0 -2133
- package/dist/modules/src/matroska/matroska-misc.js +0 -20
- package/dist/modules/src/matroska/matroska-muxer.js +0 -1017
- package/dist/modules/src/media-sink.js +0 -1736
- package/dist/modules/src/media-source.js +0 -1825
- package/dist/modules/src/metadata.js +0 -193
- package/dist/modules/src/misc.js +0 -623
- package/dist/modules/src/mp3/mp3-demuxer.js +0 -285
- package/dist/modules/src/mp3/mp3-muxer.js +0 -123
- package/dist/modules/src/mp3/mp3-reader.js +0 -26
- package/dist/modules/src/mp3/mp3-writer.js +0 -78
- package/dist/modules/src/muxer.js +0 -50
- package/dist/modules/src/node.d.ts +0 -9
- package/dist/modules/src/node.d.ts.map +0 -1
- package/dist/modules/src/node.js +0 -9
- package/dist/modules/src/ogg/ogg-demuxer.js +0 -763
- package/dist/modules/src/ogg/ogg-misc.js +0 -78
- package/dist/modules/src/ogg/ogg-muxer.js +0 -353
- package/dist/modules/src/ogg/ogg-reader.js +0 -65
- package/dist/modules/src/output-format.js +0 -527
- package/dist/modules/src/output.js +0 -300
- package/dist/modules/src/packet.js +0 -182
- package/dist/modules/src/pcm.js +0 -85
- package/dist/modules/src/reader.js +0 -236
- package/dist/modules/src/sample.js +0 -1056
- package/dist/modules/src/source.js +0 -1182
- package/dist/modules/src/subtitles.js +0 -575
- package/dist/modules/src/target.js +0 -140
- package/dist/modules/src/wave/riff-writer.js +0 -30
- package/dist/modules/src/wave/wave-demuxer.js +0 -447
- package/dist/modules/src/wave/wave-muxer.js +0 -318
- package/dist/modules/src/writer.js +0 -370
- package/src/adts/adts-demuxer.ts +0 -331
- package/src/adts/adts-muxer.ts +0 -111
- package/src/adts/adts-reader.ts +0 -85
- package/src/codec-data.ts +0 -2078
- package/src/codec.ts +0 -1092
- package/src/conversion.ts +0 -2112
- package/src/custom-coder.ts +0 -197
- package/src/demuxer.ts +0 -24
- package/src/encode.ts +0 -739
- package/src/flac/flac-demuxer.ts +0 -730
- package/src/flac/flac-misc.ts +0 -164
- package/src/flac/flac-muxer.ts +0 -320
- package/src/id3.ts +0 -925
- package/src/index.ts +0 -221
- package/src/input-format.ts +0 -541
- package/src/input-track.ts +0 -529
- package/src/input.ts +0 -235
- package/src/isobmff/isobmff-boxes.ts +0 -1719
- package/src/isobmff/isobmff-demuxer.ts +0 -3190
- package/src/isobmff/isobmff-misc.ts +0 -29
- package/src/isobmff/isobmff-muxer.ts +0 -1348
- package/src/isobmff/isobmff-reader.ts +0 -91
- package/src/matroska/ebml.ts +0 -730
- package/src/matroska/matroska-demuxer.ts +0 -2481
- package/src/matroska/matroska-misc.ts +0 -29
- package/src/matroska/matroska-muxer.ts +0 -1276
- package/src/media-sink.ts +0 -2179
- package/src/media-source.ts +0 -2243
- package/src/metadata.ts +0 -320
- package/src/misc.ts +0 -798
- package/src/mp3/mp3-demuxer.ts +0 -383
- package/src/mp3/mp3-muxer.ts +0 -166
- package/src/mp3/mp3-reader.ts +0 -34
- package/src/mp3/mp3-writer.ts +0 -120
- package/src/muxer.ts +0 -88
- package/src/node.ts +0 -11
- package/src/ogg/ogg-demuxer.ts +0 -1053
- package/src/ogg/ogg-misc.ts +0 -116
- package/src/ogg/ogg-muxer.ts +0 -497
- package/src/ogg/ogg-reader.ts +0 -93
- package/src/output-format.ts +0 -945
- package/src/output.ts +0 -488
- package/src/packet.ts +0 -263
- package/src/pcm.ts +0 -112
- package/src/reader.ts +0 -323
- package/src/sample.ts +0 -1461
- package/src/source.ts +0 -1688
- package/src/subtitles.ts +0 -711
- package/src/target.ts +0 -204
- package/src/tsconfig.json +0 -16
- package/src/wave/riff-writer.ts +0 -36
- package/src/wave/wave-demuxer.ts +0 -529
- package/src/wave/wave-muxer.ts +0 -371
- package/src/writer.ts +0 -490
|
@@ -1,140 +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 { BufferTargetWriter, NullTargetWriter, StreamTargetWriter } from './writer.js';
|
|
9
|
-
import * as nodeAlias from './node.js';
|
|
10
|
-
import { assert } from './misc.js';
|
|
11
|
-
const node = typeof nodeAlias !== 'undefined'
|
|
12
|
-
? nodeAlias // Aliasing it prevents some bundler warnings
|
|
13
|
-
: undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Base class for targets, specifying where output files are written.
|
|
16
|
-
* @group Output targets
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export class Target {
|
|
20
|
-
constructor() {
|
|
21
|
-
/** @internal */
|
|
22
|
-
this._output = null;
|
|
23
|
-
/**
|
|
24
|
-
* Called each time data is written to the target. Will be called with the byte range into which data was written.
|
|
25
|
-
*
|
|
26
|
-
* Use this callback to track the size of the output file as it grows. But be warned, this function is chatty and
|
|
27
|
-
* gets called *extremely* often.
|
|
28
|
-
*/
|
|
29
|
-
this.onwrite = null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* A target that writes data directly into an ArrayBuffer in memory. Great for performance, but not suitable for very
|
|
34
|
-
* large files. The buffer will be available once the output has been finalized.
|
|
35
|
-
* @group Output targets
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export class BufferTarget extends Target {
|
|
39
|
-
constructor() {
|
|
40
|
-
super(...arguments);
|
|
41
|
-
/** Stores the final output buffer. Until the output is finalized, this will be `null`. */
|
|
42
|
-
this.buffer = null;
|
|
43
|
-
}
|
|
44
|
-
/** @internal */
|
|
45
|
-
_createWriter() {
|
|
46
|
-
return new BufferTargetWriter(this);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* This target writes data to a [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream),
|
|
51
|
-
* making it a general-purpose target for writing data anywhere. It is also compatible with
|
|
52
|
-
* [`FileSystemWritableFileStream`](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream) for
|
|
53
|
-
* use with the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API). The
|
|
54
|
-
* `WritableStream` can also apply backpressure, which will propagate to the output and throttle the encoders.
|
|
55
|
-
* @group Output targets
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export class StreamTarget extends Target {
|
|
59
|
-
/** Creates a new {@link StreamTarget} which writes to the specified `writable`. */
|
|
60
|
-
constructor(writable, options = {}) {
|
|
61
|
-
super();
|
|
62
|
-
if (!(writable instanceof WritableStream)) {
|
|
63
|
-
throw new TypeError('StreamTarget requires a WritableStream instance.');
|
|
64
|
-
}
|
|
65
|
-
if (options != null && typeof options !== 'object') {
|
|
66
|
-
throw new TypeError('StreamTarget options, when provided, must be an object.');
|
|
67
|
-
}
|
|
68
|
-
if (options.chunked !== undefined && typeof options.chunked !== 'boolean') {
|
|
69
|
-
throw new TypeError('options.chunked, when provided, must be a boolean.');
|
|
70
|
-
}
|
|
71
|
-
if (options.chunkSize !== undefined && (!Number.isInteger(options.chunkSize) || options.chunkSize < 1024)) {
|
|
72
|
-
throw new TypeError('options.chunkSize, when provided, must be an integer and not smaller than 1024.');
|
|
73
|
-
}
|
|
74
|
-
this._writable = writable;
|
|
75
|
-
this._options = options;
|
|
76
|
-
}
|
|
77
|
-
/** @internal */
|
|
78
|
-
_createWriter() {
|
|
79
|
-
return new StreamTargetWriter(this);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* A target that writes to a file at the specified path. Intended for server-side usage in Node, Bun, or Deno.
|
|
84
|
-
*
|
|
85
|
-
* Writing is chunked by default. The internally held file handle will be closed when `.finalize()` or `.cancel()` are
|
|
86
|
-
* called on the corresponding {@link Output}.
|
|
87
|
-
* @group Output targets
|
|
88
|
-
* @public
|
|
89
|
-
*/
|
|
90
|
-
export class FilePathTarget extends Target {
|
|
91
|
-
/** Creates a new {@link FilePathTarget} that writes to the file at the specified file path. */
|
|
92
|
-
constructor(filePath, options = {}) {
|
|
93
|
-
if (typeof filePath !== 'string') {
|
|
94
|
-
throw new TypeError('filePath must be a string.');
|
|
95
|
-
}
|
|
96
|
-
if (!options || typeof options !== 'object') {
|
|
97
|
-
throw new TypeError('options must be an object.');
|
|
98
|
-
}
|
|
99
|
-
super();
|
|
100
|
-
/** @internal */
|
|
101
|
-
this._fileHandle = null;
|
|
102
|
-
// Let's back this target with a StreamTarget, makes the implementation very simple
|
|
103
|
-
const writable = new WritableStream({
|
|
104
|
-
start: async () => {
|
|
105
|
-
this._fileHandle = await node.fs.open(filePath, 'w');
|
|
106
|
-
},
|
|
107
|
-
write: async (chunk) => {
|
|
108
|
-
assert(this._fileHandle);
|
|
109
|
-
await this._fileHandle.write(chunk.data, 0, chunk.data.byteLength, chunk.position);
|
|
110
|
-
},
|
|
111
|
-
close: async () => {
|
|
112
|
-
if (this._fileHandle) {
|
|
113
|
-
await this._fileHandle.close();
|
|
114
|
-
this._fileHandle = null;
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
this._streamTarget = new StreamTarget(writable, {
|
|
119
|
-
chunked: true,
|
|
120
|
-
...options,
|
|
121
|
-
});
|
|
122
|
-
this._streamTarget._output = this._output;
|
|
123
|
-
}
|
|
124
|
-
/** @internal */
|
|
125
|
-
_createWriter() {
|
|
126
|
-
return this._streamTarget._createWriter();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* This target just discards all incoming data. It is useful for when you need an {@link Output} but extract data from
|
|
131
|
-
* it differently, for example through format-specific callbacks (`onMoof`, `onMdat`, ...) or encoder events.
|
|
132
|
-
* @group Output targets
|
|
133
|
-
* @public
|
|
134
|
-
*/
|
|
135
|
-
export class NullTarget extends Target {
|
|
136
|
-
/** @internal */
|
|
137
|
-
_createWriter() {
|
|
138
|
-
return new NullTargetWriter(this);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,30 +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
|
-
export class RiffWriter {
|
|
9
|
-
constructor(writer) {
|
|
10
|
-
this.writer = writer;
|
|
11
|
-
this.helper = new Uint8Array(8);
|
|
12
|
-
this.helperView = new DataView(this.helper.buffer);
|
|
13
|
-
}
|
|
14
|
-
writeU16(value) {
|
|
15
|
-
this.helperView.setUint16(0, value, true);
|
|
16
|
-
this.writer.write(this.helper.subarray(0, 2));
|
|
17
|
-
}
|
|
18
|
-
writeU32(value) {
|
|
19
|
-
this.helperView.setUint32(0, value, true);
|
|
20
|
-
this.writer.write(this.helper.subarray(0, 4));
|
|
21
|
-
}
|
|
22
|
-
writeU64(value) {
|
|
23
|
-
this.helperView.setUint32(0, value, true);
|
|
24
|
-
this.helperView.setUint32(4, Math.floor(value / 2 ** 32), true);
|
|
25
|
-
this.writer.write(this.helper);
|
|
26
|
-
}
|
|
27
|
-
writeAscii(text) {
|
|
28
|
-
this.writer.write(new TextEncoder().encode(text));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,447 +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 { Demuxer } from '../demuxer.js';
|
|
9
|
-
import { InputAudioTrack } from '../input-track.js';
|
|
10
|
-
import { DEFAULT_TRACK_DISPOSITION } from '../metadata.js';
|
|
11
|
-
import { assert, UNDETERMINED_LANGUAGE } from '../misc.js';
|
|
12
|
-
import { EncodedPacket, PLACEHOLDER_DATA } from '../packet.js';
|
|
13
|
-
import { readAscii, readBytes, readU16, readU32, readU64 } from '../reader.js';
|
|
14
|
-
import { parseId3V2Tag, readId3V2Header } from '../id3.js';
|
|
15
|
-
export var WaveFormat;
|
|
16
|
-
(function (WaveFormat) {
|
|
17
|
-
WaveFormat[WaveFormat["PCM"] = 1] = "PCM";
|
|
18
|
-
WaveFormat[WaveFormat["IEEE_FLOAT"] = 3] = "IEEE_FLOAT";
|
|
19
|
-
WaveFormat[WaveFormat["ALAW"] = 6] = "ALAW";
|
|
20
|
-
WaveFormat[WaveFormat["MULAW"] = 7] = "MULAW";
|
|
21
|
-
WaveFormat[WaveFormat["EXTENSIBLE"] = 65534] = "EXTENSIBLE";
|
|
22
|
-
})(WaveFormat || (WaveFormat = {}));
|
|
23
|
-
export class WaveDemuxer extends Demuxer {
|
|
24
|
-
constructor(input) {
|
|
25
|
-
super(input);
|
|
26
|
-
this.metadataPromise = null;
|
|
27
|
-
this.dataStart = -1;
|
|
28
|
-
this.dataSize = -1;
|
|
29
|
-
this.audioInfo = null;
|
|
30
|
-
this.tracks = [];
|
|
31
|
-
this.lastKnownPacketIndex = 0;
|
|
32
|
-
this.metadataTags = {};
|
|
33
|
-
this.reader = input._reader;
|
|
34
|
-
}
|
|
35
|
-
async readMetadata() {
|
|
36
|
-
return this.metadataPromise ??= (async () => {
|
|
37
|
-
let slice = this.reader.requestSlice(0, 12);
|
|
38
|
-
if (slice instanceof Promise)
|
|
39
|
-
slice = await slice;
|
|
40
|
-
assert(slice);
|
|
41
|
-
const riffType = readAscii(slice, 4);
|
|
42
|
-
const littleEndian = riffType !== 'RIFX';
|
|
43
|
-
const isRf64 = riffType === 'RF64';
|
|
44
|
-
const outerChunkSize = readU32(slice, littleEndian);
|
|
45
|
-
let totalFileSize = isRf64
|
|
46
|
-
? this.reader.fileSize
|
|
47
|
-
: Math.min(outerChunkSize + 8, this.reader.fileSize ?? Infinity);
|
|
48
|
-
const format = readAscii(slice, 4);
|
|
49
|
-
if (format !== 'WAVE') {
|
|
50
|
-
throw new Error('Invalid WAVE file - wrong format');
|
|
51
|
-
}
|
|
52
|
-
let chunksRead = 0;
|
|
53
|
-
let dataChunkSize = null;
|
|
54
|
-
let currentPos = slice.filePos;
|
|
55
|
-
while (totalFileSize === null || currentPos < totalFileSize) {
|
|
56
|
-
let slice = this.reader.requestSlice(currentPos, 8);
|
|
57
|
-
if (slice instanceof Promise)
|
|
58
|
-
slice = await slice;
|
|
59
|
-
if (!slice)
|
|
60
|
-
break;
|
|
61
|
-
const chunkId = readAscii(slice, 4);
|
|
62
|
-
const chunkSize = readU32(slice, littleEndian);
|
|
63
|
-
const startPos = slice.filePos;
|
|
64
|
-
if (isRf64 && chunksRead === 0 && chunkId !== 'ds64') {
|
|
65
|
-
throw new Error('Invalid RF64 file: First chunk must be "ds64".');
|
|
66
|
-
}
|
|
67
|
-
if (chunkId === 'fmt ') {
|
|
68
|
-
await this.parseFmtChunk(startPos, chunkSize, littleEndian);
|
|
69
|
-
}
|
|
70
|
-
else if (chunkId === 'data') {
|
|
71
|
-
dataChunkSize ??= chunkSize;
|
|
72
|
-
this.dataStart = slice.filePos;
|
|
73
|
-
this.dataSize = Math.min(dataChunkSize, (totalFileSize ?? Infinity) - this.dataStart);
|
|
74
|
-
if (this.reader.fileSize === null) {
|
|
75
|
-
break; // Stop once we hit the data chunk
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else if (chunkId === 'ds64') {
|
|
79
|
-
// File and data chunk sizes are defined in here instead
|
|
80
|
-
let ds64Slice = this.reader.requestSlice(startPos, chunkSize);
|
|
81
|
-
if (ds64Slice instanceof Promise)
|
|
82
|
-
ds64Slice = await ds64Slice;
|
|
83
|
-
if (!ds64Slice)
|
|
84
|
-
break;
|
|
85
|
-
const riffChunkSize = readU64(ds64Slice, littleEndian);
|
|
86
|
-
dataChunkSize = readU64(ds64Slice, littleEndian);
|
|
87
|
-
totalFileSize = Math.min(riffChunkSize + 8, this.reader.fileSize ?? Infinity);
|
|
88
|
-
}
|
|
89
|
-
else if (chunkId === 'LIST') {
|
|
90
|
-
await this.parseListChunk(startPos, chunkSize, littleEndian);
|
|
91
|
-
}
|
|
92
|
-
else if (chunkId === 'ID3 ' || chunkId === 'id3 ') {
|
|
93
|
-
await this.parseId3Chunk(startPos, chunkSize);
|
|
94
|
-
}
|
|
95
|
-
currentPos = startPos + chunkSize + (chunkSize & 1); // Handle padding
|
|
96
|
-
chunksRead++;
|
|
97
|
-
}
|
|
98
|
-
if (!this.audioInfo) {
|
|
99
|
-
throw new Error('Invalid WAVE file - missing "fmt " chunk');
|
|
100
|
-
}
|
|
101
|
-
if (this.dataStart === -1) {
|
|
102
|
-
throw new Error('Invalid WAVE file - missing "data" chunk');
|
|
103
|
-
}
|
|
104
|
-
const blockSize = this.audioInfo.blockSizeInBytes;
|
|
105
|
-
this.dataSize = Math.floor(this.dataSize / blockSize) * blockSize;
|
|
106
|
-
this.tracks.push(new InputAudioTrack(this.input, new WaveAudioTrackBacking(this)));
|
|
107
|
-
})();
|
|
108
|
-
}
|
|
109
|
-
async parseFmtChunk(startPos, size, littleEndian) {
|
|
110
|
-
let slice = this.reader.requestSlice(startPos, size);
|
|
111
|
-
if (slice instanceof Promise)
|
|
112
|
-
slice = await slice;
|
|
113
|
-
if (!slice)
|
|
114
|
-
return; // File too short
|
|
115
|
-
let formatTag = readU16(slice, littleEndian);
|
|
116
|
-
const numChannels = readU16(slice, littleEndian);
|
|
117
|
-
const sampleRate = readU32(slice, littleEndian);
|
|
118
|
-
slice.skip(4); // Bytes per second
|
|
119
|
-
const blockAlign = readU16(slice, littleEndian);
|
|
120
|
-
let bitsPerSample;
|
|
121
|
-
if (size === 14) { // Plain WAVEFORMAT
|
|
122
|
-
bitsPerSample = 8;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
bitsPerSample = readU16(slice, littleEndian);
|
|
126
|
-
}
|
|
127
|
-
// Handle WAVEFORMATEXTENSIBLE
|
|
128
|
-
if (size >= 18 && formatTag !== 0x0165) {
|
|
129
|
-
const cbSize = readU16(slice, littleEndian);
|
|
130
|
-
const remainingSize = size - 18;
|
|
131
|
-
const extensionSize = Math.min(remainingSize, cbSize);
|
|
132
|
-
if (extensionSize >= 22 && formatTag === WaveFormat.EXTENSIBLE) {
|
|
133
|
-
// Parse WAVEFORMATEXTENSIBLE
|
|
134
|
-
slice.skip(2 + 4);
|
|
135
|
-
const subFormat = readBytes(slice, 16);
|
|
136
|
-
// Get actual format from subFormat GUID
|
|
137
|
-
formatTag = subFormat[0] | (subFormat[1] << 8);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (formatTag === WaveFormat.MULAW || formatTag === WaveFormat.ALAW) {
|
|
141
|
-
bitsPerSample = 8;
|
|
142
|
-
}
|
|
143
|
-
this.audioInfo = {
|
|
144
|
-
format: formatTag,
|
|
145
|
-
numberOfChannels: numChannels,
|
|
146
|
-
sampleRate,
|
|
147
|
-
sampleSizeInBytes: Math.ceil(bitsPerSample / 8),
|
|
148
|
-
blockSizeInBytes: blockAlign,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
async parseListChunk(startPos, size, littleEndian) {
|
|
152
|
-
let slice = this.reader.requestSlice(startPos, size);
|
|
153
|
-
if (slice instanceof Promise)
|
|
154
|
-
slice = await slice;
|
|
155
|
-
if (!slice)
|
|
156
|
-
return; // File too short
|
|
157
|
-
const infoType = readAscii(slice, 4);
|
|
158
|
-
if (infoType !== 'INFO' && infoType !== 'INF0') { // exiftool.org claims INF0 can happen
|
|
159
|
-
return; // Not an INFO chunk
|
|
160
|
-
}
|
|
161
|
-
let currentPos = slice.filePos;
|
|
162
|
-
while (currentPos <= startPos + size - 8) {
|
|
163
|
-
slice.filePos = currentPos;
|
|
164
|
-
const chunkName = readAscii(slice, 4);
|
|
165
|
-
const chunkSize = readU32(slice, littleEndian);
|
|
166
|
-
const bytes = readBytes(slice, chunkSize);
|
|
167
|
-
let stringLength = 0;
|
|
168
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
169
|
-
if (bytes[i] === 0) {
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
stringLength++;
|
|
173
|
-
}
|
|
174
|
-
const value = String.fromCharCode(...bytes.subarray(0, stringLength));
|
|
175
|
-
this.metadataTags.raw ??= {};
|
|
176
|
-
this.metadataTags.raw[chunkName] = value;
|
|
177
|
-
switch (chunkName) {
|
|
178
|
-
case 'INAM':
|
|
179
|
-
case 'TITL':
|
|
180
|
-
{
|
|
181
|
-
this.metadataTags.title ??= value;
|
|
182
|
-
}
|
|
183
|
-
;
|
|
184
|
-
break;
|
|
185
|
-
case 'TIT3':
|
|
186
|
-
{
|
|
187
|
-
this.metadataTags.description ??= value;
|
|
188
|
-
}
|
|
189
|
-
;
|
|
190
|
-
break;
|
|
191
|
-
case 'IART':
|
|
192
|
-
{
|
|
193
|
-
this.metadataTags.artist ??= value;
|
|
194
|
-
}
|
|
195
|
-
;
|
|
196
|
-
break;
|
|
197
|
-
case 'IPRD':
|
|
198
|
-
{
|
|
199
|
-
this.metadataTags.album ??= value;
|
|
200
|
-
}
|
|
201
|
-
;
|
|
202
|
-
break;
|
|
203
|
-
case 'IPRT':
|
|
204
|
-
case 'ITRK':
|
|
205
|
-
case 'TRCK':
|
|
206
|
-
{
|
|
207
|
-
const parts = value.split('/');
|
|
208
|
-
const trackNum = Number.parseInt(parts[0], 10);
|
|
209
|
-
const tracksTotal = parts[1] && Number.parseInt(parts[1], 10);
|
|
210
|
-
if (Number.isInteger(trackNum) && trackNum > 0) {
|
|
211
|
-
this.metadataTags.trackNumber ??= trackNum;
|
|
212
|
-
}
|
|
213
|
-
if (tracksTotal && Number.isInteger(tracksTotal) && tracksTotal > 0) {
|
|
214
|
-
this.metadataTags.tracksTotal ??= tracksTotal;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
;
|
|
218
|
-
break;
|
|
219
|
-
case 'ICRD':
|
|
220
|
-
case 'IDIT':
|
|
221
|
-
{
|
|
222
|
-
const date = new Date(value);
|
|
223
|
-
if (!Number.isNaN(date.getTime())) {
|
|
224
|
-
this.metadataTags.date ??= date;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
;
|
|
228
|
-
break;
|
|
229
|
-
case 'YEAR':
|
|
230
|
-
{
|
|
231
|
-
const year = Number.parseInt(value, 10);
|
|
232
|
-
if (Number.isInteger(year) && year > 0) {
|
|
233
|
-
this.metadataTags.date ??= new Date(year, 0, 1);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
;
|
|
237
|
-
break;
|
|
238
|
-
case 'IGNR':
|
|
239
|
-
case 'GENR':
|
|
240
|
-
{
|
|
241
|
-
this.metadataTags.genre ??= value;
|
|
242
|
-
}
|
|
243
|
-
;
|
|
244
|
-
break;
|
|
245
|
-
case 'ICMT':
|
|
246
|
-
case 'CMNT':
|
|
247
|
-
case 'COMM':
|
|
248
|
-
{
|
|
249
|
-
this.metadataTags.comment ??= value;
|
|
250
|
-
}
|
|
251
|
-
;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
currentPos += 8 + chunkSize + (chunkSize & 1); // Handle padding
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
async parseId3Chunk(startPos, size) {
|
|
258
|
-
// Parse ID3 tag embedded in WAV file (non-default, but used a lot in practice anyway)
|
|
259
|
-
let slice = this.reader.requestSlice(startPos, size);
|
|
260
|
-
if (slice instanceof Promise)
|
|
261
|
-
slice = await slice;
|
|
262
|
-
if (!slice)
|
|
263
|
-
return; // File too short
|
|
264
|
-
const id3V2Header = readId3V2Header(slice);
|
|
265
|
-
if (id3V2Header) {
|
|
266
|
-
// Extract the content portion (skip the 10-byte header)
|
|
267
|
-
const contentSlice = slice.slice(startPos + 10, id3V2Header.size);
|
|
268
|
-
parseId3V2Tag(contentSlice, id3V2Header, this.metadataTags);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
getCodec() {
|
|
272
|
-
assert(this.audioInfo);
|
|
273
|
-
if (this.audioInfo.format === WaveFormat.MULAW) {
|
|
274
|
-
return 'ulaw';
|
|
275
|
-
}
|
|
276
|
-
if (this.audioInfo.format === WaveFormat.ALAW) {
|
|
277
|
-
return 'alaw';
|
|
278
|
-
}
|
|
279
|
-
if (this.audioInfo.format === WaveFormat.PCM) {
|
|
280
|
-
// All formats are little-endian
|
|
281
|
-
if (this.audioInfo.sampleSizeInBytes === 1) {
|
|
282
|
-
return 'pcm-u8';
|
|
283
|
-
}
|
|
284
|
-
else if (this.audioInfo.sampleSizeInBytes === 2) {
|
|
285
|
-
return 'pcm-s16';
|
|
286
|
-
}
|
|
287
|
-
else if (this.audioInfo.sampleSizeInBytes === 3) {
|
|
288
|
-
return 'pcm-s24';
|
|
289
|
-
}
|
|
290
|
-
else if (this.audioInfo.sampleSizeInBytes === 4) {
|
|
291
|
-
return 'pcm-s32';
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (this.audioInfo.format === WaveFormat.IEEE_FLOAT) {
|
|
295
|
-
if (this.audioInfo.sampleSizeInBytes === 4) {
|
|
296
|
-
return 'pcm-f32';
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
async getMimeType() {
|
|
302
|
-
return 'audio/wav';
|
|
303
|
-
}
|
|
304
|
-
async computeDuration() {
|
|
305
|
-
await this.readMetadata();
|
|
306
|
-
const track = this.tracks[0];
|
|
307
|
-
assert(track);
|
|
308
|
-
return track.computeDuration();
|
|
309
|
-
}
|
|
310
|
-
async getTracks() {
|
|
311
|
-
await this.readMetadata();
|
|
312
|
-
return this.tracks;
|
|
313
|
-
}
|
|
314
|
-
async getMetadataTags() {
|
|
315
|
-
await this.readMetadata();
|
|
316
|
-
return this.metadataTags;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const PACKET_SIZE_IN_FRAMES = 2048;
|
|
320
|
-
class WaveAudioTrackBacking {
|
|
321
|
-
constructor(demuxer) {
|
|
322
|
-
this.demuxer = demuxer;
|
|
323
|
-
}
|
|
324
|
-
getId() {
|
|
325
|
-
return 1;
|
|
326
|
-
}
|
|
327
|
-
getCodec() {
|
|
328
|
-
return this.demuxer.getCodec();
|
|
329
|
-
}
|
|
330
|
-
getInternalCodecId() {
|
|
331
|
-
assert(this.demuxer.audioInfo);
|
|
332
|
-
return this.demuxer.audioInfo.format;
|
|
333
|
-
}
|
|
334
|
-
async getDecoderConfig() {
|
|
335
|
-
const codec = this.demuxer.getCodec();
|
|
336
|
-
if (!codec) {
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
assert(this.demuxer.audioInfo);
|
|
340
|
-
return {
|
|
341
|
-
codec,
|
|
342
|
-
numberOfChannels: this.demuxer.audioInfo.numberOfChannels,
|
|
343
|
-
sampleRate: this.demuxer.audioInfo.sampleRate,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
async computeDuration() {
|
|
347
|
-
const lastPacket = await this.getPacket(Infinity, { metadataOnly: true });
|
|
348
|
-
return (lastPacket?.timestamp ?? 0) + (lastPacket?.duration ?? 0);
|
|
349
|
-
}
|
|
350
|
-
getNumberOfChannels() {
|
|
351
|
-
assert(this.demuxer.audioInfo);
|
|
352
|
-
return this.demuxer.audioInfo.numberOfChannels;
|
|
353
|
-
}
|
|
354
|
-
getSampleRate() {
|
|
355
|
-
assert(this.demuxer.audioInfo);
|
|
356
|
-
return this.demuxer.audioInfo.sampleRate;
|
|
357
|
-
}
|
|
358
|
-
getTimeResolution() {
|
|
359
|
-
assert(this.demuxer.audioInfo);
|
|
360
|
-
return this.demuxer.audioInfo.sampleRate;
|
|
361
|
-
}
|
|
362
|
-
getName() {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
getLanguageCode() {
|
|
366
|
-
return UNDETERMINED_LANGUAGE;
|
|
367
|
-
}
|
|
368
|
-
getDisposition() {
|
|
369
|
-
return {
|
|
370
|
-
...DEFAULT_TRACK_DISPOSITION,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
async getFirstTimestamp() {
|
|
374
|
-
return 0;
|
|
375
|
-
}
|
|
376
|
-
async getPacketAtIndex(packetIndex, options) {
|
|
377
|
-
assert(this.demuxer.audioInfo);
|
|
378
|
-
const startOffset = packetIndex * PACKET_SIZE_IN_FRAMES * this.demuxer.audioInfo.blockSizeInBytes;
|
|
379
|
-
if (startOffset >= this.demuxer.dataSize) {
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
const sizeInBytes = Math.min(PACKET_SIZE_IN_FRAMES * this.demuxer.audioInfo.blockSizeInBytes, this.demuxer.dataSize - startOffset);
|
|
383
|
-
if (this.demuxer.reader.fileSize === null) {
|
|
384
|
-
// If the file size is unknown, we weren't able to cap the dataSize in the init logic and we instead have to
|
|
385
|
-
// rely on the headers telling us how large the file is. But, these might be wrong, so let's check if the
|
|
386
|
-
// requested slice actually exists.
|
|
387
|
-
let slice = this.demuxer.reader.requestSlice(this.demuxer.dataStart + startOffset, sizeInBytes);
|
|
388
|
-
if (slice instanceof Promise)
|
|
389
|
-
slice = await slice;
|
|
390
|
-
if (!slice) {
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
let data;
|
|
395
|
-
if (options.metadataOnly) {
|
|
396
|
-
data = PLACEHOLDER_DATA;
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
let slice = this.demuxer.reader.requestSlice(this.demuxer.dataStart + startOffset, sizeInBytes);
|
|
400
|
-
if (slice instanceof Promise)
|
|
401
|
-
slice = await slice;
|
|
402
|
-
assert(slice);
|
|
403
|
-
data = readBytes(slice, sizeInBytes);
|
|
404
|
-
}
|
|
405
|
-
const timestamp = packetIndex * PACKET_SIZE_IN_FRAMES / this.demuxer.audioInfo.sampleRate;
|
|
406
|
-
const duration = sizeInBytes / this.demuxer.audioInfo.blockSizeInBytes / this.demuxer.audioInfo.sampleRate;
|
|
407
|
-
this.demuxer.lastKnownPacketIndex = Math.max(packetIndex, timestamp);
|
|
408
|
-
return new EncodedPacket(data, 'key', timestamp, duration, packetIndex, sizeInBytes);
|
|
409
|
-
}
|
|
410
|
-
getFirstPacket(options) {
|
|
411
|
-
return this.getPacketAtIndex(0, options);
|
|
412
|
-
}
|
|
413
|
-
async getPacket(timestamp, options) {
|
|
414
|
-
assert(this.demuxer.audioInfo);
|
|
415
|
-
const packetIndex = Math.floor(Math.min(timestamp * this.demuxer.audioInfo.sampleRate / PACKET_SIZE_IN_FRAMES, (this.demuxer.dataSize - 1) / (PACKET_SIZE_IN_FRAMES * this.demuxer.audioInfo.blockSizeInBytes)));
|
|
416
|
-
const packet = await this.getPacketAtIndex(packetIndex, options);
|
|
417
|
-
if (packet) {
|
|
418
|
-
return packet;
|
|
419
|
-
}
|
|
420
|
-
if (packetIndex === 0) {
|
|
421
|
-
return null; // Empty data chunk
|
|
422
|
-
}
|
|
423
|
-
assert(this.demuxer.reader.fileSize === null);
|
|
424
|
-
// The file is shorter than we thought, meaning the packet we were looking for doesn't exist. So, let's find
|
|
425
|
-
// the last packet by doing a sequential scan, instead.
|
|
426
|
-
let currentPacket = await this.getPacketAtIndex(this.demuxer.lastKnownPacketIndex, options);
|
|
427
|
-
while (currentPacket) {
|
|
428
|
-
const nextPacket = await this.getNextPacket(currentPacket, options);
|
|
429
|
-
if (!nextPacket) {
|
|
430
|
-
break;
|
|
431
|
-
}
|
|
432
|
-
currentPacket = nextPacket;
|
|
433
|
-
}
|
|
434
|
-
return currentPacket;
|
|
435
|
-
}
|
|
436
|
-
getNextPacket(packet, options) {
|
|
437
|
-
assert(this.demuxer.audioInfo);
|
|
438
|
-
const packetIndex = Math.round(packet.timestamp * this.demuxer.audioInfo.sampleRate / PACKET_SIZE_IN_FRAMES);
|
|
439
|
-
return this.getPacketAtIndex(packetIndex + 1, options);
|
|
440
|
-
}
|
|
441
|
-
getKeyPacket(timestamp, options) {
|
|
442
|
-
return this.getPacket(timestamp, options);
|
|
443
|
-
}
|
|
444
|
-
getNextKeyPacket(packet, options) {
|
|
445
|
-
return this.getNextPacket(packet, options);
|
|
446
|
-
}
|
|
447
|
-
}
|