@remotion/media-parser 4.0.251 → 4.0.252
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/dist/aac-codecprivate.d.ts +2 -1
- package/dist/aac-codecprivate.js +28 -7
- package/dist/buffer-iterator.d.ts +5 -1
- package/dist/buffer-iterator.js +5 -5
- package/dist/containers/aac/parse-aac.js +3 -2
- package/dist/containers/flac/get-channel-count.d.ts +1 -1
- package/dist/containers/flac/get-duration-from-flac.js +1 -4
- package/dist/containers/flac/get-sample-rate.js +1 -1
- package/dist/containers/flac/parse-flac-frame.js +3 -9
- package/dist/containers/flac/parse-flac.js +2 -7
- package/dist/containers/flac/parse-header.js +2 -2
- package/dist/containers/flac/parse-metadata.js +2 -2
- package/dist/containers/flac/parse-streaminfo.js +3 -3
- package/dist/containers/flac/parse-unknown-block.js +2 -2
- package/dist/containers/iso-base-media/base-media-box.d.ts +1 -4
- package/dist/containers/iso-base-media/get-actual-number-of-channels.js +1 -1
- package/dist/containers/iso-base-media/get-children.js +2 -2
- package/dist/containers/iso-base-media/get-keyframes.d.ts +2 -2
- package/dist/containers/iso-base-media/get-keyframes.js +3 -2
- package/dist/containers/iso-base-media/get-moov-atom.d.ts +6 -0
- package/dist/containers/iso-base-media/get-moov-atom.js +73 -0
- package/dist/containers/iso-base-media/get-video-codec-from-iso-track.js +1 -1
- package/dist/containers/iso-base-media/mdat/mdat.d.ts +2 -1
- package/dist/containers/iso-base-media/mdat/mdat.js +13 -8
- package/dist/containers/iso-base-media/parse-boxes.js +4 -26
- package/dist/containers/iso-base-media/process-box.js +50 -163
- package/dist/containers/iso-base-media/stsd/samples.js +1 -0
- package/dist/containers/iso-base-media/traversal.d.ts +2 -1
- package/dist/containers/iso-base-media/traversal.js +6 -2
- package/dist/containers/mp3/get-duration.js +0 -3
- package/dist/containers/mp3/id3.js +1 -1
- package/dist/containers/mp3/parse-mp3.js +4 -12
- package/dist/containers/mp3/parse-mpeg-header.js +1 -1
- package/dist/containers/riff/expect-riff-box.d.ts +1 -2
- package/dist/containers/riff/expect-riff-box.js +4 -14
- package/dist/containers/riff/get-tracks-from-avi.js +1 -1
- package/dist/containers/riff/parse-list-box.js +3 -5
- package/dist/containers/riff/parse-movi.d.ts +2 -4
- package/dist/containers/riff/parse-movi.js +9 -27
- package/dist/containers/riff/parse-riff-body.js +17 -11
- package/dist/containers/riff/parse-riff-header.js +2 -7
- package/dist/containers/riff/parse-video-section.d.ts +1 -1
- package/dist/containers/riff/parse-video-section.js +5 -7
- package/dist/containers/transport-stream/adts-header.js +1 -0
- package/dist/containers/transport-stream/get-tracks.js +1 -1
- package/dist/containers/transport-stream/parse-packet.js +1 -1
- package/dist/containers/transport-stream/parse-transport-stream.js +3 -10
- package/dist/containers/transport-stream/process-stream-buffers.js +1 -1
- package/dist/containers/wav/get-duration-from-wav.js +1 -4
- package/dist/containers/wav/parse-data.js +6 -6
- package/dist/containers/wav/parse-fmt.js +2 -2
- package/dist/containers/wav/parse-header.js +2 -2
- package/dist/containers/wav/parse-id3.js +2 -4
- package/dist/containers/wav/parse-list.js +2 -2
- package/dist/containers/wav/parse-video-section.js +2 -5
- package/dist/containers/webm/parse-ebml.js +1 -1
- package/dist/containers/webm/parse-webm-header.js +3 -10
- package/dist/download-and-parse-media.d.ts +2 -0
- package/dist/download-and-parse-media.js +70 -0
- package/dist/emit-available-info.d.ts +2 -3
- package/dist/emit-available-info.js +36 -36
- package/dist/esm/from-fetch.mjs +1 -1
- package/dist/esm/from-node.mjs +1 -1
- package/dist/esm/from-web-file.mjs +7 -7
- package/dist/esm/index.mjs +702 -637
- package/dist/esm/node.mjs +113 -0
- package/dist/get-audio-codec.js +3 -0
- package/dist/get-dimensions.js +2 -2
- package/dist/get-duration.js +3 -6
- package/dist/get-fps.d.ts +4 -4
- package/dist/get-fps.js +13 -11
- package/dist/get-keyframes.d.ts +1 -2
- package/dist/get-keyframes.js +4 -3
- package/dist/get-location.d.ts +2 -2
- package/dist/get-location.js +2 -2
- package/dist/get-tracks.d.ts +3 -5
- package/dist/get-tracks.js +8 -14
- package/dist/has-all-info.js +3 -3
- package/dist/index.d.ts +127 -101
- package/dist/index.js +3 -1
- package/dist/init-video.d.ts +1 -1
- package/dist/init-video.js +8 -8
- package/dist/internal-parse-media.d.ts +2 -0
- package/dist/internal-parse-media.js +221 -0
- package/dist/make-hvc1-codec-strings.js +4 -4
- package/dist/metadata/get-metadata.d.ts +2 -1
- package/dist/metadata/get-metadata.js +3 -2
- package/dist/metadata/metadata-from-iso.d.ts +2 -2
- package/dist/metadata/metadata-from-iso.js +2 -2
- package/dist/options.d.ts +56 -33
- package/dist/parse-and-download-media.d.ts +2 -0
- package/dist/parse-and-download-media.js +57 -0
- package/dist/parse-media.js +5 -201
- package/dist/parse-result.d.ts +2 -6
- package/dist/perform-seek.d.ts +5 -8
- package/dist/perform-seek.js +16 -9
- package/dist/readers/from-fetch.js +1 -1
- package/dist/readers/from-node.js +1 -1
- package/dist/readers/from-web-file.js +9 -9
- package/dist/readers/reader.d.ts +7 -2
- package/dist/register-track.js +5 -0
- package/dist/run-parse-iteration.d.ts +1 -1
- package/dist/run-parse-iteration.js +2 -2
- package/dist/skip.d.ts +5 -0
- package/dist/skip.js +8 -0
- package/dist/state/has-tracks-section.d.ts +3 -1
- package/dist/state/has-tracks-section.js +7 -1
- package/dist/state/iso-base-media/cached-sample-positions.js +1 -1
- package/dist/state/iso-base-media/iso-state.d.ts +4 -2
- package/dist/state/iso-base-media/iso-state.js +2 -5
- package/dist/state/iso-base-media/moov-box.d.ts +5 -0
- package/dist/state/iso-base-media/moov-box.js +13 -0
- package/dist/state/last-eventloop-break.d.ts +4 -0
- package/dist/state/last-eventloop-break.js +18 -0
- package/dist/state/parser-state.d.ts +122 -101
- package/dist/state/parser-state.js +21 -3
- package/dist/state/sample-callbacks.d.ts +2 -1
- package/dist/state/structure.d.ts +7 -0
- package/dist/state/structure.js +56 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/writers/node.d.ts +4 -0
- package/dist/writers/node.js +81 -0
- package/dist/writers/writer.d.ts +17 -0
- package/dist/writers/writer.js +2 -0
- package/package.json +12 -9
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare const getSampleRateFromSampleFrequencyIndex: (samplingFrequencyIndex: number) => 96000 | 88200 | 64000 | 48000 | 44100 | 32000 | 24000 | 22050 | 16000 | 12000 | 11025 | 8000 | 7350;
|
|
2
|
-
export declare const createAacCodecPrivate: ({ audioObjectType, sampleRate, channelConfiguration, }: {
|
|
2
|
+
export declare const createAacCodecPrivate: ({ audioObjectType, sampleRate, channelConfiguration, codecPrivate, }: {
|
|
3
3
|
audioObjectType: number;
|
|
4
4
|
sampleRate: number;
|
|
5
5
|
channelConfiguration: number;
|
|
6
|
+
codecPrivate: Uint8Array | null;
|
|
6
7
|
}) => Uint8Array;
|
|
7
8
|
export declare const parseAacCodecPrivate: (bytes: Uint8Array) => {
|
|
8
9
|
audioObjectType: number;
|
package/dist/aac-codecprivate.js
CHANGED
|
@@ -90,7 +90,13 @@ const getConfigForSampleRate = (sampleRate) => {
|
|
|
90
90
|
}
|
|
91
91
|
throw new Error(`Unexpected sample rate ${sampleRate}`);
|
|
92
92
|
};
|
|
93
|
-
const createAacCodecPrivate = ({ audioObjectType, sampleRate, channelConfiguration, }) => {
|
|
93
|
+
const createAacCodecPrivate = ({ audioObjectType, sampleRate, channelConfiguration, codecPrivate, }) => {
|
|
94
|
+
if (codecPrivate !== null && codecPrivate.length > 2) {
|
|
95
|
+
// Video submitted
|
|
96
|
+
// submitted by Yossi Elkrief
|
|
97
|
+
// TOOD: Check if we are now parsing correctly
|
|
98
|
+
return codecPrivate;
|
|
99
|
+
}
|
|
94
100
|
const bits = `${audioObjectType.toString(2).padStart(5, '0')}${getConfigForSampleRate(sampleRate).toString(2).padStart(4, '0')}${channelConfiguration.toString(2).padStart(4, '0')}000`;
|
|
95
101
|
if (bits.length !== 16) {
|
|
96
102
|
throw new Error('Invalid AAC codec private ' + bits.length);
|
|
@@ -107,13 +113,28 @@ const parseAacCodecPrivate = (bytes) => {
|
|
|
107
113
|
if (bytes.length < 2) {
|
|
108
114
|
throw new Error('Invalid AAC codec private length');
|
|
109
115
|
}
|
|
110
|
-
const bits =
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
const bits = [...bytes].map((b) => b.toString(2).padStart(8, '0')).join('');
|
|
117
|
+
let offset = 0;
|
|
118
|
+
const audioObjectType = parseInt(bits.slice(offset, offset + 5), 2);
|
|
119
|
+
offset += 5;
|
|
120
|
+
const samplingFrequencyIndex = parseInt(bits.slice(offset, offset + 4), 2);
|
|
121
|
+
offset += 4;
|
|
122
|
+
if (samplingFrequencyIndex === 0xf) {
|
|
123
|
+
offset += 24;
|
|
124
|
+
}
|
|
125
|
+
const channelConfiguration = parseInt(bits.slice(offset, offset + 4), 2);
|
|
126
|
+
offset += 4;
|
|
127
|
+
if (audioObjectType === 5) {
|
|
128
|
+
const extensionSamplingFrequencyIndex = parseInt(bits.slice(offset, offset + 4), 2);
|
|
129
|
+
offset += 4;
|
|
130
|
+
const newAudioObjectType = parseInt(bits.slice(offset, offset + 5), 2);
|
|
131
|
+
offset += 5;
|
|
132
|
+
return {
|
|
133
|
+
audioObjectType: newAudioObjectType,
|
|
134
|
+
sampleRate: (0, exports.getSampleRateFromSampleFrequencyIndex)(extensionSamplingFrequencyIndex),
|
|
135
|
+
channelConfiguration,
|
|
136
|
+
};
|
|
113
137
|
}
|
|
114
|
-
const audioObjectType = parseInt(bits.slice(0, 5), 2);
|
|
115
|
-
const samplingFrequencyIndex = parseInt(bits.slice(5, 9), 2);
|
|
116
|
-
const channelConfiguration = parseInt(bits.slice(9, 13), 2);
|
|
117
138
|
const sampleRate = (0, exports.getSampleRateFromSampleFrequencyIndex)(samplingFrequencyIndex);
|
|
118
139
|
return {
|
|
119
140
|
audioObjectType,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ParseMediaMode } from './options';
|
|
1
2
|
export declare class OffsetCounter {
|
|
2
3
|
#private;
|
|
3
4
|
constructor(initial: number);
|
|
@@ -20,7 +21,10 @@ export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes:
|
|
|
20
21
|
getBits: (bits: number) => number;
|
|
21
22
|
bytesRemaining: () => number;
|
|
22
23
|
leb128: () => number;
|
|
23
|
-
removeBytesRead: (force: boolean) =>
|
|
24
|
+
removeBytesRead: (force: boolean, mode: ParseMediaMode) => {
|
|
25
|
+
bytesRemoved: number;
|
|
26
|
+
removedData: Uint8Array | null;
|
|
27
|
+
};
|
|
24
28
|
discard: (length: number) => void;
|
|
25
29
|
getEightByteNumber: (littleEndian?: boolean) => number;
|
|
26
30
|
getFourByteNumber: () => number;
|
package/dist/buffer-iterator.js
CHANGED
|
@@ -207,30 +207,30 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
|
207
207
|
const bytesRemaining = () => {
|
|
208
208
|
return uintArray.byteLength - counter.getDiscardedOffset();
|
|
209
209
|
};
|
|
210
|
-
const removeBytesRead = (force) => {
|
|
210
|
+
const removeBytesRead = (force, mode) => {
|
|
211
211
|
const bytesToRemove = counter.getDiscardedOffset();
|
|
212
212
|
// Only do this operation if it is really worth it 😇
|
|
213
213
|
// let's set the threshold to 3MB
|
|
214
214
|
if (bytesToRemove < 3000000 && !force) {
|
|
215
|
-
return;
|
|
215
|
+
return { bytesRemoved: 0, removedData: null };
|
|
216
216
|
}
|
|
217
217
|
// Don't remove if the data is not even available
|
|
218
218
|
if (view.byteLength < bytesToRemove && !force) {
|
|
219
|
-
return;
|
|
219
|
+
return { bytesRemoved: 0, removedData: null };
|
|
220
220
|
}
|
|
221
221
|
counter.discardBytes(bytesToRemove);
|
|
222
|
+
const removedData = mode === 'download' ? uintArray.slice(0, bytesToRemove) : null;
|
|
222
223
|
const newData = uintArray.slice(bytesToRemove);
|
|
223
224
|
uintArray.set(newData);
|
|
224
225
|
buf.resize(newData.byteLength);
|
|
225
226
|
view = new DataView(uintArray.buffer);
|
|
226
|
-
return bytesToRemove;
|
|
227
|
+
return { bytesRemoved: bytesToRemove, removedData };
|
|
227
228
|
};
|
|
228
229
|
const skipTo = (offset) => {
|
|
229
230
|
const becomesSmaller = offset < counter.getOffset();
|
|
230
231
|
if (!becomesSmaller) {
|
|
231
232
|
const currentOffset = counter.getOffset();
|
|
232
233
|
counter.increment(offset - currentOffset);
|
|
233
|
-
removeBytesRead(true);
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
236
236
|
buf.resize(0);
|
|
@@ -30,6 +30,7 @@ const parseAac = async (state) => {
|
|
|
30
30
|
audioObjectType,
|
|
31
31
|
sampleRate,
|
|
32
32
|
channelConfiguration,
|
|
33
|
+
codecPrivate: null,
|
|
33
34
|
});
|
|
34
35
|
iterator.getBits(1); // originality
|
|
35
36
|
iterator.getBits(1); // home
|
|
@@ -61,7 +62,7 @@ const parseAac = async (state) => {
|
|
|
61
62
|
type: 'audio',
|
|
62
63
|
},
|
|
63
64
|
});
|
|
64
|
-
state.callbacks.tracks.setIsDone();
|
|
65
|
+
state.callbacks.tracks.setIsDone(state.logLevel);
|
|
65
66
|
}
|
|
66
67
|
const duration = 1024 / sampleRate;
|
|
67
68
|
const { index } = state.aac.addSample({ offset: startOffset, size: frameLength });
|
|
@@ -78,6 +79,6 @@ const parseAac = async (state) => {
|
|
|
78
79
|
dts: timestamp,
|
|
79
80
|
timestamp,
|
|
80
81
|
}, 1));
|
|
81
|
-
return Promise.resolve(
|
|
82
|
+
return Promise.resolve(null);
|
|
82
83
|
};
|
|
83
84
|
exports.parseAac = parseAac;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
export declare const getChannelCount: (iterator: BufferIterator) =>
|
|
2
|
+
export declare const getChannelCount: (iterator: BufferIterator) => 5 | 2 | 8 | 1 | 7 | 3 | 4 | 6;
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDurationFromFlac = void 0;
|
|
4
4
|
const getDurationFromFlac = (parserState) => {
|
|
5
|
-
const structure = parserState.
|
|
6
|
-
if (structure.type !== 'flac') {
|
|
7
|
-
throw new Error('Not a FLAC file');
|
|
8
|
-
}
|
|
5
|
+
const structure = parserState.getFlacStructure();
|
|
9
6
|
const streaminfo = structure.boxes.find((b) => b.type === 'flac-streaminfo');
|
|
10
7
|
if (!streaminfo) {
|
|
11
8
|
throw new Error('Streaminfo not found');
|
|
@@ -6,7 +6,7 @@ const getSampleRate = (iterator, state) => {
|
|
|
6
6
|
var _a, _b;
|
|
7
7
|
const mode = iterator.getBits(4);
|
|
8
8
|
if (mode === 0b0000) {
|
|
9
|
-
const structure = state.
|
|
9
|
+
const structure = state.getFlacStructure();
|
|
10
10
|
const sampleRate = (_b = (_a = structure.boxes.find((box) => box.type === 'flac-streaminfo')) === null || _a === void 0 ? void 0 : _a.sampleRate) !== null && _b !== void 0 ? _b : null;
|
|
11
11
|
if (sampleRate === null) {
|
|
12
12
|
throw new Error('Sample rate not found');
|
|
@@ -71,7 +71,7 @@ const emitSample = async ({ state, data, offset, }) => {
|
|
|
71
71
|
}
|
|
72
72
|
const { blockSize, num, sampleRate } = parsed;
|
|
73
73
|
const duration = blockSize / sampleRate;
|
|
74
|
-
const structure = state.
|
|
74
|
+
const structure = state.getFlacStructure();
|
|
75
75
|
const streamInfo = structure.boxes.find((box) => box.type === 'flac-streaminfo');
|
|
76
76
|
if (!streamInfo) {
|
|
77
77
|
throw new Error('Stream info not found');
|
|
@@ -123,10 +123,7 @@ const parseFlacFrame = async ({ state, iterator, }) => {
|
|
|
123
123
|
throw new Error('Blocking bit should be set');
|
|
124
124
|
}
|
|
125
125
|
iterator.stopReadingBits();
|
|
126
|
-
const structure = state.
|
|
127
|
-
if (structure.type !== 'flac') {
|
|
128
|
-
throw new Error('Expected flac-structure');
|
|
129
|
-
}
|
|
126
|
+
const structure = state.getFlacStructure();
|
|
130
127
|
const minimumFrameSize = (_b = (_a = structure.boxes.find((b) => b.type === 'flac-streaminfo')) === null || _a === void 0 ? void 0 : _a.minimumFrameSize) !== null && _b !== void 0 ? _b : null;
|
|
131
128
|
if (minimumFrameSize === null) {
|
|
132
129
|
throw new Error('Expected flac-streaminfo');
|
|
@@ -135,9 +132,6 @@ const parseFlacFrame = async ({ state, iterator, }) => {
|
|
|
135
132
|
iterator.getSlice(minimumFrameSize - 2);
|
|
136
133
|
}
|
|
137
134
|
while (true) {
|
|
138
|
-
if (!state.contentLength) {
|
|
139
|
-
throw new Error('Need content-length for FLAC to parse');
|
|
140
|
-
}
|
|
141
135
|
if (iterator.counter.getOffset() === state.contentLength) {
|
|
142
136
|
const size = iterator.counter.getOffset() - offset;
|
|
143
137
|
returnToCheckpoint();
|
|
@@ -170,6 +164,6 @@ const parseFlacFrame = async ({ state, iterator, }) => {
|
|
|
170
164
|
break;
|
|
171
165
|
}
|
|
172
166
|
}
|
|
173
|
-
return
|
|
167
|
+
return null;
|
|
174
168
|
};
|
|
175
169
|
exports.parseFlacFrame = parseFlacFrame;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseFlac = void 0;
|
|
4
|
+
const skip_1 = require("../../skip");
|
|
4
5
|
const may_skip_video_data_1 = require("../../state/may-skip-video-data");
|
|
5
6
|
const parse_flac_frame_1 = require("./parse-flac-frame");
|
|
6
7
|
const parse_header_1 = require("./parse-header");
|
|
@@ -15,10 +16,7 @@ const parseFlac = ({ iterator, state, }) => {
|
|
|
15
16
|
const videoSectionState = state.videoSection.isInVideoSectionState(iterator);
|
|
16
17
|
if (videoSectionState === 'in-section') {
|
|
17
18
|
if ((0, may_skip_video_data_1.maySkipVideoData)({ state })) {
|
|
18
|
-
|
|
19
|
-
throw new Error('Need content-length for FLAC to parse');
|
|
20
|
-
}
|
|
21
|
-
return Promise.resolve({ skipTo: state.contentLength });
|
|
19
|
+
return Promise.resolve((0, skip_1.makeSkip)(state.contentLength));
|
|
22
20
|
}
|
|
23
21
|
return (0, parse_flac_frame_1.parseFlacFrame)({ state, iterator });
|
|
24
22
|
}
|
|
@@ -35,9 +33,6 @@ const parseFlac = ({ iterator, state, }) => {
|
|
|
35
33
|
iterator.stopReadingBits();
|
|
36
34
|
const size = iterator.getUint24();
|
|
37
35
|
if (isLastMetadata) {
|
|
38
|
-
if (!state.contentLength) {
|
|
39
|
-
throw new Error('Need content-length for FLAC to parse');
|
|
40
|
-
}
|
|
41
36
|
state.videoSection.setVideoSection({
|
|
42
37
|
start: iterator.counter.getOffset() + size,
|
|
43
38
|
size: state.contentLength - iterator.counter.getOffset() - size,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseFlacHeader = void 0;
|
|
4
4
|
const parseFlacHeader = ({ state, }) => {
|
|
5
|
-
state.
|
|
5
|
+
state.getFlacStructure().boxes.push({
|
|
6
6
|
type: 'flac-header',
|
|
7
7
|
});
|
|
8
|
-
return Promise.resolve(
|
|
8
|
+
return Promise.resolve(null);
|
|
9
9
|
};
|
|
10
10
|
exports.parseFlacHeader = parseFlacHeader;
|
|
@@ -17,8 +17,8 @@ const parseVorbisComment = ({ state, iterator, size, }) => {
|
|
|
17
17
|
const [key, value] = field.split('=');
|
|
18
18
|
box.fields.push({ key: key.toLowerCase(), value, trackId: null });
|
|
19
19
|
}
|
|
20
|
-
state.
|
|
20
|
+
state.getFlacStructure().boxes.push(box);
|
|
21
21
|
expectNoMoreBytes();
|
|
22
|
-
return Promise.resolve(
|
|
22
|
+
return Promise.resolve(null);
|
|
23
23
|
};
|
|
24
24
|
exports.parseVorbisComment = parseVorbisComment;
|
|
@@ -30,7 +30,7 @@ const parseStreamInfo = async ({ iterator, state, }) => {
|
|
|
30
30
|
sampleRate,
|
|
31
31
|
totalSamples,
|
|
32
32
|
};
|
|
33
|
-
state.
|
|
33
|
+
state.getFlacStructure().boxes.push(flacStreamInfo);
|
|
34
34
|
await (0, register_track_1.registerTrack)({
|
|
35
35
|
container: 'flac',
|
|
36
36
|
state,
|
|
@@ -47,7 +47,7 @@ const parseStreamInfo = async ({ iterator, state, }) => {
|
|
|
47
47
|
trakBox: null,
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
|
-
state.callbacks.tracks.setIsDone();
|
|
51
|
-
return Promise.resolve(
|
|
50
|
+
state.callbacks.tracks.setIsDone(state.logLevel);
|
|
51
|
+
return Promise.resolve(null);
|
|
52
52
|
};
|
|
53
53
|
exports.parseStreamInfo = parseStreamInfo;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseFlacUnkownBlock = void 0;
|
|
4
4
|
const parseFlacUnkownBlock = ({ iterator, state, size, }) => {
|
|
5
5
|
iterator.discard(size);
|
|
6
|
-
state.
|
|
6
|
+
state.getFlacStructure().boxes.push({
|
|
7
7
|
type: 'flac-header',
|
|
8
8
|
});
|
|
9
|
-
return Promise.resolve(
|
|
9
|
+
return Promise.resolve(null);
|
|
10
10
|
};
|
|
11
11
|
exports.parseFlacUnkownBlock = parseFlacUnkownBlock;
|
|
@@ -33,8 +33,5 @@ export interface RegularBox extends BaseBox {
|
|
|
33
33
|
offset: number;
|
|
34
34
|
type: 'regular-box';
|
|
35
35
|
}
|
|
36
|
-
export type BoxAndNext =
|
|
37
|
-
box: IsoBaseMediaBox | null;
|
|
38
|
-
skipTo: number | null;
|
|
39
|
-
};
|
|
36
|
+
export type BoxAndNext = IsoBaseMediaBox | null;
|
|
40
37
|
export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | IlstBox | EsdsBox | StszBox | StcoBox | StscBox | AvccBox | HvccBox | VoidBox | StssBox | PaspBox | CttsBox | Av1CBox | TrunBox | HdlrBox | ColorParameterBox | TfdtBox | TfhdBox;
|
|
@@ -16,7 +16,7 @@ const getActualDecoderParameters = ({ audioCodec, codecPrivate, numberOfChannels
|
|
|
16
16
|
return {
|
|
17
17
|
numberOfChannels: parsed.channelConfiguration,
|
|
18
18
|
sampleRate: parsed.sampleRate,
|
|
19
|
-
codecPrivate: (0, aac_codecprivate_1.createAacCodecPrivate)(parsed),
|
|
19
|
+
codecPrivate: (0, aac_codecprivate_1.createAacCodecPrivate)({ ...parsed, codecPrivate }),
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
exports.getActualDecoderParameters = getActualDecoderParameters;
|
|
@@ -8,10 +8,10 @@ const getIsoBaseMediaChildren = async ({ state, size, }) => {
|
|
|
8
8
|
const initial = iterator.counter.getOffset();
|
|
9
9
|
while (iterator.counter.getOffset() < size + initial) {
|
|
10
10
|
const parsed = await (0, process_box_1.processBox)(state);
|
|
11
|
-
if (!parsed
|
|
11
|
+
if (!parsed) {
|
|
12
12
|
throw new Error('Expected box');
|
|
13
13
|
}
|
|
14
|
-
boxes.push(parsed
|
|
14
|
+
boxes.push(parsed);
|
|
15
15
|
}
|
|
16
16
|
if (iterator.counter.getOffset() > size + initial) {
|
|
17
17
|
throw new Error(`read too many bytes - size: ${size}, read: ${iterator.counter.getOffset() - initial}. initial offset: ${initial}`);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { MediaParserKeyframe } from '../../options';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const getKeyframesFromIsoBaseMedia: (
|
|
2
|
+
import type { ParserState } from '../../state/parser-state';
|
|
3
|
+
export declare const getKeyframesFromIsoBaseMedia: (state: ParserState) => MediaParserKeyframe[];
|
|
@@ -4,8 +4,9 @@ exports.getKeyframesFromIsoBaseMedia = void 0;
|
|
|
4
4
|
const get_tracks_1 = require("../../get-tracks");
|
|
5
5
|
const get_sample_positions_from_track_1 = require("./get-sample-positions-from-track");
|
|
6
6
|
const traversal_1 = require("./traversal");
|
|
7
|
-
const getKeyframesFromIsoBaseMedia = (
|
|
8
|
-
const { videoTracks } = (0, get_tracks_1.getTracksFromIsoBaseMedia)(
|
|
7
|
+
const getKeyframesFromIsoBaseMedia = (state) => {
|
|
8
|
+
const { videoTracks } = (0, get_tracks_1.getTracksFromIsoBaseMedia)(state);
|
|
9
|
+
const structure = state.getIsoStructure();
|
|
9
10
|
const moofBox = (0, traversal_1.getMoofBox)(structure.boxes);
|
|
10
11
|
const allSamples = videoTracks.map((t) => {
|
|
11
12
|
const { timescale: ts } = t;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMoovAtom = void 0;
|
|
4
|
+
const log_1 = require("../../log");
|
|
5
|
+
const register_track_1 = require("../../register-track");
|
|
6
|
+
const parser_state_1 = require("../../state/parser-state");
|
|
7
|
+
const process_box_1 = require("./process-box");
|
|
8
|
+
const getMoovAtom = async ({ endOfMdat, state, }) => {
|
|
9
|
+
const start = Date.now();
|
|
10
|
+
log_1.Log.verbose(state.logLevel, 'Starting second fetch to get moov atom');
|
|
11
|
+
const { reader } = await state.readerInterface.read({
|
|
12
|
+
src: state.src,
|
|
13
|
+
range: endOfMdat,
|
|
14
|
+
signal: state.signal,
|
|
15
|
+
});
|
|
16
|
+
const childState = (0, parser_state_1.makeParserState)({
|
|
17
|
+
hasAudioTrackHandlers: false,
|
|
18
|
+
hasVideoTrackHandlers: false,
|
|
19
|
+
signal: state.signal,
|
|
20
|
+
fields: {
|
|
21
|
+
structure: true,
|
|
22
|
+
},
|
|
23
|
+
onAudioTrack: state.onAudioTrack
|
|
24
|
+
? async ({ track, container }) => {
|
|
25
|
+
await (0, register_track_1.registerTrack)({ state, track, container });
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
: null,
|
|
29
|
+
onVideoTrack: state.onVideoTrack
|
|
30
|
+
? async ({ track, container }) => {
|
|
31
|
+
await (0, register_track_1.registerTrack)({ state, track, container });
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
: null,
|
|
35
|
+
contentLength: state.contentLength,
|
|
36
|
+
logLevel: state.logLevel,
|
|
37
|
+
mode: 'query',
|
|
38
|
+
readerInterface: state.readerInterface,
|
|
39
|
+
src: state.src,
|
|
40
|
+
onDiscardedData: null,
|
|
41
|
+
});
|
|
42
|
+
while (true) {
|
|
43
|
+
const result = await reader.reader.read();
|
|
44
|
+
if (result.value) {
|
|
45
|
+
childState.iterator.addData(result.value);
|
|
46
|
+
}
|
|
47
|
+
if (result.done) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const boxes = [];
|
|
52
|
+
while (true) {
|
|
53
|
+
const box = await (0, process_box_1.processBox)(childState);
|
|
54
|
+
if (box) {
|
|
55
|
+
boxes.push(box);
|
|
56
|
+
}
|
|
57
|
+
if (childState.iterator.counter.getOffset() + endOfMdat >
|
|
58
|
+
state.contentLength) {
|
|
59
|
+
throw new Error('Read past end of file');
|
|
60
|
+
}
|
|
61
|
+
if (childState.iterator.counter.getOffset() + endOfMdat ===
|
|
62
|
+
state.contentLength) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const moov = boxes.find((b) => b.type === 'moov-box');
|
|
67
|
+
if (!moov) {
|
|
68
|
+
throw new Error('No moov box found');
|
|
69
|
+
}
|
|
70
|
+
log_1.Log.verbose(state.logLevel, `Finished fetching moov atom in ${Date.now() - start}ms`);
|
|
71
|
+
return moov;
|
|
72
|
+
};
|
|
73
|
+
exports.getMoovAtom = getMoovAtom;
|
|
@@ -7,7 +7,7 @@ const getVideoCodecFromIsoTrak = (trakBox) => {
|
|
|
7
7
|
if (stsdBox && stsdBox.type === 'stsd-box') {
|
|
8
8
|
const videoSample = stsdBox.samples.find((s) => s.type === 'video');
|
|
9
9
|
if (videoSample && videoSample.type === 'video') {
|
|
10
|
-
if (videoSample.format === 'hvc1') {
|
|
10
|
+
if (videoSample.format === 'hvc1' || videoSample.format === 'hev1') {
|
|
11
11
|
return 'h265';
|
|
12
12
|
}
|
|
13
13
|
if (videoSample.format === 'avc1') {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { Skip } from '../../../skip';
|
|
1
2
|
import type { ParserState } from '../../../state/parser-state';
|
|
2
|
-
export declare const parseMdatSection: (state: ParserState) => Promise<
|
|
3
|
+
export declare const parseMdatSection: (state: ParserState) => Promise<Skip | null>;
|
|
@@ -3,22 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseMdatSection = void 0;
|
|
4
4
|
const convert_audio_or_video_sample_1 = require("../../../convert-audio-or-video-sample");
|
|
5
5
|
const get_tracks_1 = require("../../../get-tracks");
|
|
6
|
+
const skip_1 = require("../../../skip");
|
|
6
7
|
const cached_sample_positions_1 = require("../../../state/iso-base-media/cached-sample-positions");
|
|
7
8
|
const may_skip_video_data_1 = require("../../../state/may-skip-video-data");
|
|
9
|
+
const get_moov_atom_1 = require("../get-moov-atom");
|
|
8
10
|
const parseMdatSection = async (state) => {
|
|
9
11
|
const videoSection = state.videoSection.getVideoSection();
|
|
12
|
+
const endOfMdat = videoSection.size + videoSection.start;
|
|
10
13
|
// don't need mdat at all, can skip
|
|
11
14
|
if ((0, may_skip_video_data_1.maySkipVideoData)({ state })) {
|
|
12
|
-
return
|
|
15
|
+
return (0, skip_1.makeSkip)(endOfMdat);
|
|
13
16
|
}
|
|
14
17
|
const alreadyHas = (0, get_tracks_1.getHasTracks)(state);
|
|
15
18
|
if (!alreadyHas) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
state
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const moov = await (0, get_moov_atom_1.getMoovAtom)({
|
|
20
|
+
endOfMdat,
|
|
21
|
+
state,
|
|
22
|
+
});
|
|
23
|
+
state.iso.moov.setMoovBox(moov);
|
|
24
|
+
state.callbacks.tracks.setIsDone(state.logLevel);
|
|
25
|
+
state.getIsoStructure().boxes.push(moov);
|
|
26
|
+
return (0, exports.parseMdatSection)(state);
|
|
22
27
|
}
|
|
23
28
|
if (!state.iso.flatSamples.getSamples()) {
|
|
24
29
|
state.iso.flatSamples.setSamples((0, cached_sample_positions_1.calculateFlatSamples)(state));
|
|
@@ -41,7 +46,7 @@ const parseMdatSection = async (state) => {
|
|
|
41
46
|
}
|
|
42
47
|
// guess we reached the end!
|
|
43
48
|
// iphonevideo.mov has extra padding here, so let's make sure to jump ahead
|
|
44
|
-
return
|
|
49
|
+
return (0, skip_1.makeSkip)(endOfMdat);
|
|
45
50
|
}
|
|
46
51
|
if (iterator.bytesRemaining() < samplesWithIndex.samplePosition.size) {
|
|
47
52
|
return null;
|
|
@@ -7,34 +7,12 @@ const parseIsoBaseMedia = async (state) => {
|
|
|
7
7
|
const videoSectionState = state.videoSection.isInVideoSectionState(state.iterator);
|
|
8
8
|
if (videoSectionState === 'in-section') {
|
|
9
9
|
const skipTo = await (0, mdat_1.parseMdatSection)(state);
|
|
10
|
-
return
|
|
11
|
-
skipTo,
|
|
12
|
-
};
|
|
10
|
+
return skipTo;
|
|
13
11
|
}
|
|
14
12
|
const result = await (0, process_box_1.processBox)(state);
|
|
15
|
-
if (result
|
|
16
|
-
state.
|
|
13
|
+
if (result) {
|
|
14
|
+
state.getIsoStructure().boxes.push(result);
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
if (iterator.counter.getOffset() === state.contentLength &&
|
|
20
|
-
state.iso.getShouldReturnToVideoSectionAfterEnd()) {
|
|
21
|
-
state.iso.setShouldReturnToVideoSectionAfterEnd(false);
|
|
22
|
-
return {
|
|
23
|
-
skipTo: state.videoSection.getVideoSection().start,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (result.skipTo !== null) {
|
|
27
|
-
return {
|
|
28
|
-
skipTo: result.skipTo,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
if (iterator.bytesRemaining() < 0) {
|
|
32
|
-
return {
|
|
33
|
-
skipTo: null,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
skipTo: null,
|
|
38
|
-
};
|
|
16
|
+
return null;
|
|
39
17
|
};
|
|
40
18
|
exports.parseIsoBaseMedia = parseIsoBaseMedia;
|