@remotion/media-parser 4.0.248 → 4.0.250
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/boxes/avc/key.d.ts +1 -1
- package/dist/boxes/iso-base-media/continue-mdat-routine.d.ts +14 -0
- package/dist/boxes/iso-base-media/continue-mdat-routine.js +74 -0
- package/dist/boxes/iso-base-media/get-children.d.ts +8 -0
- package/dist/boxes/iso-base-media/get-children.js +23 -0
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -22
- package/dist/boxes/iso-base-media/mdat/mdat.js +80 -121
- package/dist/boxes/iso-base-media/moov/moov.d.ts +1 -6
- package/dist/boxes/iso-base-media/moov/moov.js +5 -15
- package/dist/boxes/iso-base-media/parse-all-children.d.ts +8 -0
- package/dist/boxes/iso-base-media/parse-all-children.js +20 -0
- package/dist/boxes/iso-base-media/parse-boxes.d.ts +7 -0
- package/dist/boxes/iso-base-media/parse-boxes.js +46 -0
- package/dist/boxes/iso-base-media/parse-mdat-partially.d.ts +9 -0
- package/dist/boxes/iso-base-media/parse-mdat-partially.js +24 -0
- package/dist/boxes/iso-base-media/process-box.d.ts +2 -29
- package/dist/boxes/iso-base-media/process-box.js +56 -367
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +1 -4
- package/dist/boxes/iso-base-media/stsd/mebx.js +5 -15
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -12
- package/dist/boxes/iso-base-media/stsd/samples.js +24 -70
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +1 -4
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -5
- package/dist/boxes/iso-base-media/trak/trak.d.ts +1 -6
- package/dist/boxes/iso-base-media/trak/trak.js +5 -15
- package/dist/boxes/iso-base-media/traversal.d.ts +0 -2
- package/dist/boxes/iso-base-media/traversal.js +1 -12
- package/dist/boxes/mp3/get-duration.d.ts +2 -0
- package/dist/boxes/mp3/get-duration.js +30 -0
- package/dist/boxes/mp3/get-frame-length.d.ts +13 -0
- package/dist/boxes/mp3/get-frame-length.js +33 -0
- package/dist/boxes/mp3/get-metadata-from-mp3.d.ts +3 -0
- package/dist/boxes/mp3/get-metadata-from-mp3.js +8 -0
- package/dist/boxes/mp3/get-tracks-from-mp3.d.ts +4 -0
- package/dist/boxes/mp3/get-tracks-from-mp3.js +25 -0
- package/dist/boxes/mp3/id3-v1.d.ts +2 -0
- package/dist/boxes/mp3/id3-v1.js +12 -0
- package/dist/boxes/mp3/id3-v2.d.ts +0 -0
- package/dist/boxes/mp3/id3-v2.js +1 -0
- package/dist/boxes/mp3/id3.d.ts +6 -0
- package/dist/boxes/mp3/id3.js +80 -0
- package/dist/boxes/mp3/parse-mp3.d.ts +7 -0
- package/dist/boxes/mp3/parse-mp3.js +41 -0
- package/dist/boxes/mp3/parse-mpeg-header.d.ts +6 -0
- package/dist/boxes/mp3/parse-mpeg-header.js +274 -0
- package/dist/boxes/mp3/samples-per-mpeg-file.d.ts +4 -0
- package/dist/boxes/mp3/samples-per-mpeg-file.js +26 -0
- package/dist/boxes/riff/continue-after-riff-result.d.ts +13 -0
- package/dist/boxes/riff/continue-after-riff-result.js +34 -0
- package/dist/boxes/riff/expect-riff-box.d.ts +1 -7
- package/dist/boxes/riff/expect-riff-box.js +47 -24
- package/dist/boxes/riff/get-tracks-from-avi.d.ts +1 -1
- package/dist/boxes/riff/get-tracks-from-avi.js +6 -10
- package/dist/boxes/riff/parse-box.d.ts +1 -7
- package/dist/boxes/riff/parse-box.js +4 -120
- package/dist/boxes/riff/parse-fmt-box.d.ts +3 -2
- package/dist/boxes/riff/parse-fmt-box.js +7 -5
- package/dist/boxes/riff/parse-list-box.js +15 -14
- package/dist/boxes/riff/parse-movi.d.ts +2 -5
- package/dist/boxes/riff/parse-movi.js +34 -56
- package/dist/boxes/riff/parse-riff-body.d.ts +7 -0
- package/dist/boxes/riff/parse-riff-body.js +25 -0
- package/dist/boxes/riff/parse-riff-box.d.ts +1 -2
- package/dist/boxes/riff/parse-riff-box.js +2 -6
- package/dist/boxes/riff/parse-riff-header.d.ts +7 -0
- package/dist/boxes/riff/parse-riff-header.js +23 -0
- package/dist/boxes/riff/parse-riff.d.ts +7 -0
- package/dist/boxes/riff/parse-riff.js +15 -0
- package/dist/boxes/riff/parse-strf.d.ts +4 -4
- package/dist/boxes/riff/parse-strf.js +4 -8
- package/dist/boxes/riff/parse-strh.js +11 -0
- package/dist/boxes/riff/parse-video-section.d.ts +6 -0
- package/dist/boxes/riff/parse-video-section.js +20 -0
- package/dist/boxes/riff/riff-box.d.ts +4 -5
- package/dist/boxes/riff/traversal.d.ts +1 -2
- package/dist/boxes/riff/traversal.js +1 -6
- package/dist/boxes/transport-stream/get-tracks.d.ts +2 -3
- package/dist/boxes/transport-stream/get-tracks.js +4 -3
- package/dist/boxes/transport-stream/parse-packet.d.ts +1 -7
- package/dist/boxes/transport-stream/parse-packet.js +3 -4
- package/dist/boxes/transport-stream/parse-stream-packet.d.ts +1 -5
- package/dist/boxes/transport-stream/parse-stream-packet.js +10 -12
- package/dist/boxes/transport-stream/parse-transport-stream.d.ts +1 -7
- package/dist/boxes/transport-stream/parse-transport-stream.js +19 -49
- package/dist/boxes/transport-stream/process-stream-buffers.d.ts +1 -2
- package/dist/boxes/transport-stream/process-stream-buffers.js +3 -3
- package/dist/boxes/webm/parse-ebml.js +3 -0
- package/dist/boxes/webm/parse-webm-header.d.ts +2 -4
- package/dist/boxes/webm/parse-webm-header.js +41 -25
- package/dist/boxes/webm/segments/parse-children.d.ts +2 -16
- package/dist/boxes/webm/segments/parse-children.js +7 -130
- package/dist/boxes/webm/segments.d.ts +4 -8
- package/dist/boxes/webm/segments.js +41 -123
- package/dist/buffer-iterator.d.ts +6 -3
- package/dist/buffer-iterator.js +27 -16
- package/dist/bun-reader.d.ts +1 -0
- package/dist/bun-reader.js +17 -0
- package/dist/continue-mdat-routine.d.ts +17 -0
- package/dist/continue-mdat-routine.js +92 -0
- package/dist/emit-available-info.js +42 -28
- package/dist/esm/from-node.mjs +8 -9
- package/dist/esm/index.mjs +5133 -5085
- package/dist/file-types/detect-file-type.js +6 -2
- package/dist/get-audio-codec.d.ts +1 -1
- package/dist/get-audio-codec.js +3 -3
- package/dist/get-container.js +5 -1
- package/dist/get-dimensions.d.ts +1 -1
- package/dist/get-dimensions.js +4 -1
- package/dist/get-duration.js +6 -2
- package/dist/get-fields-from-callbacks.js +1 -0
- package/dist/get-fps.js +3 -0
- package/dist/get-is-hdr.d.ts +1 -1
- package/dist/get-is-hdr.js +3 -3
- package/dist/get-keyframes.js +1 -1
- package/dist/get-tracks.d.ts +2 -2
- package/dist/get-tracks.js +23 -15
- package/dist/get-video-codec.d.ts +1 -1
- package/dist/get-video-codec.js +3 -3
- package/dist/has-all-info.js +4 -3
- package/dist/index.d.ts +65 -21
- package/dist/index.js +1 -1
- package/dist/may-skip-video-data/may-skip-video-data.js +6 -2
- package/dist/may-skip-video-data/need-samples-for-fields.js +1 -0
- package/dist/metadata/get-metadata.d.ts +1 -0
- package/dist/metadata/get-metadata.js +16 -1
- package/dist/options.d.ts +12 -5
- package/dist/parse-media.js +88 -68
- package/dist/parse-result.d.ts +17 -19
- package/dist/parse-video.d.ts +3 -17
- package/dist/parse-video.js +52 -40
- package/dist/readers/from-node.js +7 -8
- package/dist/state/can-skip-tracks.d.ts +8 -1
- package/dist/state/can-skip-tracks.js +38 -26
- package/dist/state/emitted-fields.js +1 -0
- package/dist/state/images.d.ts +9 -0
- package/dist/state/images.js +14 -0
- package/dist/state/iso-base-media/cached-sample-positions.d.ts +15 -0
- package/dist/state/iso-base-media/cached-sample-positions.js +42 -0
- package/dist/state/iso-base-media/iso-state.d.ts +8 -0
- package/dist/state/iso-base-media/iso-state.js +15 -0
- package/dist/state/iso-state.d.ts +4 -0
- package/dist/state/iso-state.js +13 -0
- package/dist/state/mp3.d.ts +11 -0
- package/dist/state/mp3.js +13 -0
- package/dist/state/parser-state.d.ts +57 -11
- package/dist/state/parser-state.js +17 -2
- package/dist/state/sample-callbacks.d.ts +5 -1
- package/dist/state/sample-callbacks.js +8 -2
- package/dist/state/slow-duration-fps.d.ts +2 -1
- package/dist/state/slow-duration-fps.js +52 -18
- package/dist/state/transport-stream.d.ts +8 -0
- package/dist/state/transport-stream.js +11 -0
- package/dist/state/video-section.d.ts +16 -0
- package/dist/state/video-section.js +37 -0
- package/dist/state/webm.d.ts +15 -0
- package/dist/state/webm.js +32 -0
- package/dist/throttled-progress.d.ts +14 -0
- package/dist/throttled-progress.js +44 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/test.json +663 -0
|
@@ -1,125 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRiff =
|
|
4
|
-
const get_tracks_1 = require("../../get-tracks");
|
|
3
|
+
exports.parseRiff = void 0;
|
|
5
4
|
const has_all_info_1 = require("../../has-all-info");
|
|
6
|
-
const
|
|
7
|
-
const expect_riff_box_1 = require("./expect-riff-box");
|
|
8
|
-
const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
|
|
9
|
-
const traversal_1 = require("./traversal");
|
|
10
|
-
const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, state: options, }) => {
|
|
11
|
-
if (result.type === 'incomplete') {
|
|
12
|
-
return Promise.resolve({
|
|
13
|
-
status: 'incomplete',
|
|
14
|
-
async continueParsing() {
|
|
15
|
-
return Promise.resolve(continueAfterRiffBoxResult({
|
|
16
|
-
result: await result.continueParsing(),
|
|
17
|
-
structure,
|
|
18
|
-
iterator,
|
|
19
|
-
maxOffset,
|
|
20
|
-
state: options,
|
|
21
|
-
}));
|
|
22
|
-
},
|
|
23
|
-
segments: structure,
|
|
24
|
-
skipTo: null,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (result.type === 'complete' && result.box) {
|
|
28
|
-
structure.boxes.push(result.box);
|
|
29
|
-
}
|
|
30
|
-
return (0, exports.parseRiffBody)({ iterator, maxOffset, state: options, structure });
|
|
31
|
-
};
|
|
32
|
-
const parseRiffBody = async ({ iterator, structure, maxOffset, state, }) => {
|
|
33
|
-
while (iterator.bytesRemaining() > 0 &&
|
|
34
|
-
iterator.counter.getOffset() < maxOffset) {
|
|
35
|
-
const result = await (0, expect_riff_box_1.expectRiffBox)({
|
|
36
|
-
iterator,
|
|
37
|
-
state,
|
|
38
|
-
structure,
|
|
39
|
-
});
|
|
40
|
-
if (result.type === 'complete' && result.skipTo !== null) {
|
|
41
|
-
return {
|
|
42
|
-
status: 'incomplete',
|
|
43
|
-
skipTo: result.skipTo,
|
|
44
|
-
continueParsing() {
|
|
45
|
-
return Promise.resolve(continueAfterRiffBoxResult({
|
|
46
|
-
iterator,
|
|
47
|
-
maxOffset,
|
|
48
|
-
state,
|
|
49
|
-
result,
|
|
50
|
-
structure,
|
|
51
|
-
}));
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (result.type === 'incomplete') {
|
|
56
|
-
return {
|
|
57
|
-
status: 'incomplete',
|
|
58
|
-
async continueParsing() {
|
|
59
|
-
return Promise.resolve(continueAfterRiffBoxResult({
|
|
60
|
-
iterator,
|
|
61
|
-
maxOffset,
|
|
62
|
-
state,
|
|
63
|
-
result: await result.continueParsing(),
|
|
64
|
-
structure,
|
|
65
|
-
}));
|
|
66
|
-
},
|
|
67
|
-
skipTo: null,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (result.box === null) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
structure.boxes.push(result.box);
|
|
74
|
-
// When parsing an AVI
|
|
75
|
-
if (result.box.type === 'list-box' && result.box.listType === 'hdrl') {
|
|
76
|
-
const tracks = (0, get_tracks_1.getTracks)(structure, state);
|
|
77
|
-
if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
|
|
78
|
-
state.callbacks.tracks.setIsDone();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// When parsing a WAV
|
|
82
|
-
if (result.box.type === 'wave-format-box') {
|
|
83
|
-
state.callbacks.tracks.setIsDone();
|
|
84
|
-
}
|
|
85
|
-
if (result.box.type === 'strf-box-video' ||
|
|
86
|
-
result.box.type === 'strf-box-audio') {
|
|
87
|
-
const strh = (0, traversal_1.getStrhBox)(structure.boxes);
|
|
88
|
-
const strf = (0, traversal_1.getStrfBox)(structure.boxes);
|
|
89
|
-
if (!strh || !strf) {
|
|
90
|
-
throw new Error('strh or strf box missing');
|
|
91
|
-
}
|
|
92
|
-
if (strf.type === 'strf-box-audio' && state.onAudioTrack) {
|
|
93
|
-
const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
|
|
94
|
-
index: state.riff.getNextTrackIndex(),
|
|
95
|
-
strf,
|
|
96
|
-
});
|
|
97
|
-
await (0, register_track_1.registerTrack)({
|
|
98
|
-
state,
|
|
99
|
-
track: audioTrack,
|
|
100
|
-
container: 'avi',
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (state.onVideoTrack && strf.type === 'strf-box-video') {
|
|
104
|
-
const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
|
|
105
|
-
strh,
|
|
106
|
-
index: state.riff.getNextTrackIndex(),
|
|
107
|
-
strf,
|
|
108
|
-
});
|
|
109
|
-
(0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
|
|
110
|
-
state,
|
|
111
|
-
track: videoTrack,
|
|
112
|
-
container: 'avi',
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
state.riff.incrementNextTrackIndex();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
status: 'done',
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
exports.parseRiffBody = parseRiffBody;
|
|
5
|
+
const parse_riff_body_1 = require("./parse-riff-body");
|
|
123
6
|
const parseRiff = ({ iterator, state, fields, }) => {
|
|
124
7
|
const riff = iterator.getByteString(4, false);
|
|
125
8
|
if (riff !== 'RIFF') {
|
|
@@ -141,11 +24,12 @@ const parseRiff = ({ iterator, state, fields, }) => {
|
|
|
141
24
|
segments: structure,
|
|
142
25
|
});
|
|
143
26
|
}
|
|
144
|
-
return (0,
|
|
27
|
+
return (0, parse_riff_body_1.parseRiffBody)({
|
|
145
28
|
iterator,
|
|
146
29
|
maxOffset: Infinity,
|
|
147
30
|
state,
|
|
148
31
|
structure,
|
|
32
|
+
fields,
|
|
149
33
|
});
|
|
150
34
|
};
|
|
151
35
|
exports.parseRiff = parseRiff;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParserState } from '../../state/parser-state';
|
|
2
3
|
import type { RiffBox } from './riff-box';
|
|
3
|
-
export declare const parseFmtBox: ({ iterator,
|
|
4
|
+
export declare const parseFmtBox: ({ iterator, size, state, }: {
|
|
4
5
|
iterator: BufferIterator;
|
|
5
|
-
boxes: RiffBox[];
|
|
6
6
|
size: number;
|
|
7
|
+
state: ParserState;
|
|
7
8
|
}) => RiffBox;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseFmtBox = void 0;
|
|
4
|
-
const parseFmtBox = ({ iterator,
|
|
4
|
+
const parseFmtBox = ({ iterator, size, state, }) => {
|
|
5
5
|
const box = iterator.startBox(size);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const structure = state.structure.getStructure();
|
|
7
|
+
const riffHeader = structure.boxes.find((b) => b.type === 'riff-header');
|
|
8
|
+
if (!riffHeader) {
|
|
9
|
+
throw new Error('Expected RIFF header to be parsed before fmt');
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
// TODO: Can we delete this?
|
|
12
|
+
if (riffHeader.fileType !== 'WAVE') {
|
|
11
13
|
throw new Error('Only supporting WAVE type');
|
|
12
14
|
}
|
|
13
15
|
const wFormatTag = iterator.getUint16Le();
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseListBox = void 0;
|
|
4
|
-
const
|
|
4
|
+
const expect_riff_box_1 = require("./expect-riff-box");
|
|
5
5
|
const parseListBox = async ({ iterator, size, state, }) => {
|
|
6
6
|
const counter = iterator.counter.getOffset();
|
|
7
7
|
const listType = iterator.getByteString(4, false);
|
|
8
8
|
if (listType === 'movi') {
|
|
9
9
|
throw new Error('should not be handled here');
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
const boxes = [];
|
|
12
|
+
const maxOffset = counter + size;
|
|
13
|
+
while (iterator.counter.getOffset() < maxOffset) {
|
|
14
|
+
const result = await (0, expect_riff_box_1.expectRiffBox)({
|
|
15
|
+
iterator,
|
|
16
|
+
state,
|
|
17
|
+
});
|
|
18
|
+
if (result.box !== null) {
|
|
19
|
+
boxes.push(result.box);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new Error('Unexpected result');
|
|
23
|
+
}
|
|
23
24
|
}
|
|
24
25
|
return {
|
|
25
26
|
type: 'list-box',
|
|
26
27
|
listType,
|
|
27
|
-
children:
|
|
28
|
+
children: boxes,
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
31
|
exports.parseListBox = parseListBox;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { RiffStructure } from '../../parse-result';
|
|
3
2
|
import type { ParserState } from '../../state/parser-state';
|
|
4
3
|
import type { RiffResult } from './expect-riff-box';
|
|
5
|
-
export declare const handleChunk: ({ iterator, state,
|
|
4
|
+
export declare const handleChunk: ({ iterator, state, ckId, ckSize, }: {
|
|
6
5
|
iterator: BufferIterator;
|
|
7
6
|
state: ParserState;
|
|
8
|
-
structure: RiffStructure;
|
|
9
7
|
ckId: string;
|
|
10
8
|
ckSize: number;
|
|
11
9
|
}) => Promise<void>;
|
|
12
|
-
export declare const parseMovi: ({ iterator, maxOffset, state,
|
|
10
|
+
export declare const parseMovi: ({ iterator, maxOffset, state, }: {
|
|
13
11
|
iterator: BufferIterator;
|
|
14
12
|
maxOffset: number;
|
|
15
13
|
state: ParserState;
|
|
16
|
-
structure: RiffStructure;
|
|
17
14
|
}) => Promise<RiffResult>;
|
|
@@ -18,12 +18,12 @@ const getStrhForIndex = (structure, trackId) => {
|
|
|
18
18
|
}
|
|
19
19
|
return strh;
|
|
20
20
|
};
|
|
21
|
-
const handleChunk = async ({ iterator, state,
|
|
21
|
+
const handleChunk = async ({ iterator, state, ckId, ckSize, }) => {
|
|
22
22
|
const offset = iterator.counter.getOffset();
|
|
23
23
|
const videoChunk = ckId.match(/^([0-9]{2})dc$/);
|
|
24
24
|
if (videoChunk) {
|
|
25
25
|
const trackId = parseInt(videoChunk[1], 10);
|
|
26
|
-
const strh = getStrhForIndex(structure, trackId);
|
|
26
|
+
const strh = getStrhForIndex(state.structure.getStructure(), trackId);
|
|
27
27
|
const samplesPerSecond = strh.rate / strh.scale;
|
|
28
28
|
const nthSample = state.callbacks.getSamplesForTrack(trackId);
|
|
29
29
|
const timeInSec = nthSample / samplesPerSecond;
|
|
@@ -56,7 +56,7 @@ const handleChunk = async ({ iterator, state, structure, ckId, ckSize, }) => {
|
|
|
56
56
|
const audioChunk = ckId.match(/^([0-9]{2})wb$/);
|
|
57
57
|
if (audioChunk) {
|
|
58
58
|
const trackId = parseInt(audioChunk[1], 10);
|
|
59
|
-
const strh = getStrhForIndex(structure, trackId);
|
|
59
|
+
const strh = getStrhForIndex(state.structure.getStructure(), trackId);
|
|
60
60
|
const samplesPerSecond = strh.rate / strh.scale;
|
|
61
61
|
const nthSample = state.callbacks.getSamplesForTrack(trackId);
|
|
62
62
|
const timeInSec = nthSample / samplesPerSecond;
|
|
@@ -81,66 +81,44 @@ const handleChunk = async ({ iterator, state, structure, ckId, ckSize, }) => {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
exports.handleChunk = handleChunk;
|
|
84
|
-
const parseMovi = async ({ iterator, maxOffset, state,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
const ckId = iterator.getByteString(4, false);
|
|
95
|
-
const ckSize = iterator.getUint32Le();
|
|
96
|
-
if ((0, may_skip_video_data_1.maySkipVideoData)({
|
|
97
|
-
state,
|
|
98
|
-
}) &&
|
|
99
|
-
state.riff.getAvcProfile()) {
|
|
100
|
-
return {
|
|
101
|
-
type: 'complete',
|
|
102
|
-
box: {
|
|
103
|
-
type: 'movi-box',
|
|
104
|
-
},
|
|
105
|
-
skipTo: maxOffset,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
if (iterator.bytesRemaining() < ckSize) {
|
|
109
|
-
iterator.counter.decrement(8);
|
|
110
|
-
return {
|
|
111
|
-
type: 'incomplete',
|
|
112
|
-
continueParsing: () => {
|
|
113
|
-
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
await (0, exports.handleChunk)({ iterator, state, structure, ckId, ckSize });
|
|
118
|
-
// Discard added zeroes
|
|
119
|
-
while (iterator.counter.getOffset() < maxOffset &&
|
|
120
|
-
iterator.bytesRemaining() > 0) {
|
|
121
|
-
if (iterator.getUint8() !== 0) {
|
|
122
|
-
iterator.counter.decrement(1);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
84
|
+
const parseMovi = async ({ iterator, maxOffset, state, }) => {
|
|
85
|
+
if ((0, may_skip_video_data_1.maySkipVideoData)({
|
|
86
|
+
state,
|
|
87
|
+
}) &&
|
|
88
|
+
state.riff.getAvcProfile()) {
|
|
89
|
+
return {
|
|
90
|
+
box: null,
|
|
91
|
+
skipTo: maxOffset,
|
|
92
|
+
};
|
|
126
93
|
}
|
|
127
|
-
if (iterator.
|
|
94
|
+
if (iterator.bytesRemaining() < 8) {
|
|
128
95
|
return {
|
|
129
|
-
|
|
130
|
-
box: {
|
|
131
|
-
type: 'movi-box',
|
|
132
|
-
},
|
|
96
|
+
box: null,
|
|
133
97
|
skipTo: null,
|
|
134
98
|
};
|
|
135
99
|
}
|
|
136
|
-
|
|
137
|
-
|
|
100
|
+
const checkpoint = iterator.startCheckpoint();
|
|
101
|
+
const ckId = iterator.getByteString(4, false);
|
|
102
|
+
const ckSize = iterator.getUint32Le();
|
|
103
|
+
if (iterator.bytesRemaining() < ckSize) {
|
|
104
|
+
checkpoint.returnToCheckpoint();
|
|
105
|
+
return {
|
|
106
|
+
box: null,
|
|
107
|
+
skipTo: null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
await (0, exports.handleChunk)({ iterator, state, ckId, ckSize });
|
|
111
|
+
// Discard added zeroes
|
|
112
|
+
while (iterator.counter.getOffset() < maxOffset &&
|
|
113
|
+
iterator.bytesRemaining() > 0) {
|
|
114
|
+
if (iterator.getUint8() !== 0) {
|
|
115
|
+
iterator.counter.decrement(1);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
138
118
|
}
|
|
139
119
|
return {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
|
|
143
|
-
},
|
|
120
|
+
box: null,
|
|
121
|
+
skipTo: null,
|
|
144
122
|
};
|
|
145
123
|
};
|
|
146
124
|
exports.parseMovi = parseMovi;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParseResult } from '../../parse-result';
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
|
+
export declare const parseRiffBody: ({ iterator, state, }: {
|
|
5
|
+
iterator: BufferIterator;
|
|
6
|
+
state: ParserState;
|
|
7
|
+
}) => Promise<ParseResult>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRiffBody = void 0;
|
|
4
|
+
const expect_riff_box_1 = require("./expect-riff-box");
|
|
5
|
+
const parse_video_section_1 = require("./parse-video-section");
|
|
6
|
+
const parseRiffBody = async ({ iterator, state, }) => {
|
|
7
|
+
if (state.videoSection.isInVideoSectionState(iterator) === 'in-section') {
|
|
8
|
+
const videoSec = await (0, parse_video_section_1.parseVideoSection)({ state, iterator });
|
|
9
|
+
return {
|
|
10
|
+
skipTo: videoSec.skipTo,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const result = await (0, expect_riff_box_1.expectRiffBox)({
|
|
14
|
+
iterator,
|
|
15
|
+
state,
|
|
16
|
+
});
|
|
17
|
+
if (result.box !== null) {
|
|
18
|
+
const structure = state.structure.getStructure();
|
|
19
|
+
structure.boxes.push(result.box);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
skipTo: result.skipTo,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.parseRiffBody = parseRiffBody;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { ParserState } from '../../state/parser-state';
|
|
3
3
|
import type { RiffBox } from './riff-box';
|
|
4
|
-
export declare const parseRiffBox: ({ iterator, size, id,
|
|
4
|
+
export declare const parseRiffBox: ({ iterator, size, id, state, }: {
|
|
5
5
|
iterator: BufferIterator;
|
|
6
6
|
size: number;
|
|
7
7
|
id: string;
|
|
8
|
-
boxes: RiffBox[];
|
|
9
8
|
state: ParserState;
|
|
10
9
|
}) => Promise<RiffBox>;
|
|
@@ -5,11 +5,10 @@ const parse_avih_1 = require("./parse-avih");
|
|
|
5
5
|
const parse_fmt_box_1 = require("./parse-fmt-box");
|
|
6
6
|
const parse_isft_1 = require("./parse-isft");
|
|
7
7
|
const parse_list_box_1 = require("./parse-list-box");
|
|
8
|
-
const parse_strf_1 = require("./parse-strf");
|
|
9
8
|
const parse_strh_1 = require("./parse-strh");
|
|
10
|
-
const parseRiffBox = ({ iterator, size, id,
|
|
9
|
+
const parseRiffBox = ({ iterator, size, id, state, }) => {
|
|
11
10
|
if (id === 'fmt') {
|
|
12
|
-
return Promise.resolve((0, parse_fmt_box_1.parseFmtBox)({ iterator,
|
|
11
|
+
return Promise.resolve((0, parse_fmt_box_1.parseFmtBox)({ iterator, size, state }));
|
|
13
12
|
}
|
|
14
13
|
if (id === 'LIST') {
|
|
15
14
|
return (0, parse_list_box_1.parseListBox)({ iterator, size, state });
|
|
@@ -23,9 +22,6 @@ const parseRiffBox = ({ iterator, size, id, boxes, state, }) => {
|
|
|
23
22
|
if (id === 'strh') {
|
|
24
23
|
return Promise.resolve((0, parse_strh_1.parseStrh)({ iterator, size }));
|
|
25
24
|
}
|
|
26
|
-
if (id === 'strf') {
|
|
27
|
-
return Promise.resolve((0, parse_strf_1.parseStrf)({ iterator, size, boxes }));
|
|
28
|
-
}
|
|
29
25
|
iterator.discard(size);
|
|
30
26
|
const box = {
|
|
31
27
|
type: 'riff-box',
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParseResult } from '../../parse-result';
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
|
+
export declare const parseRiffHeader: ({ iterator, state, }: {
|
|
5
|
+
iterator: BufferIterator;
|
|
6
|
+
state: ParserState;
|
|
7
|
+
}) => ParseResult;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRiffHeader = void 0;
|
|
4
|
+
const parseRiffHeader = ({ iterator, state, }) => {
|
|
5
|
+
const riff = iterator.getByteString(4, false);
|
|
6
|
+
if (riff !== 'RIFF') {
|
|
7
|
+
throw new Error('Not a RIFF file');
|
|
8
|
+
}
|
|
9
|
+
const structure = state.structure.getStructure();
|
|
10
|
+
if (structure.type !== 'riff') {
|
|
11
|
+
throw new Error('Structure is not a RIFF structure');
|
|
12
|
+
}
|
|
13
|
+
const size = iterator.getUint32Le();
|
|
14
|
+
const fileType = iterator.getByteString(4, false);
|
|
15
|
+
if (fileType !== 'WAVE' && fileType !== 'AVI') {
|
|
16
|
+
throw new Error(`File type ${fileType} not supported`);
|
|
17
|
+
}
|
|
18
|
+
structure.boxes.push({ type: 'riff-header', fileSize: size, fileType });
|
|
19
|
+
return {
|
|
20
|
+
skipTo: null,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.parseRiffHeader = parseRiffHeader;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParseResult } from '../../parse-result';
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
|
+
export declare const parseRiff: ({ iterator, state, }: {
|
|
5
|
+
iterator: BufferIterator;
|
|
6
|
+
state: ParserState;
|
|
7
|
+
}) => Promise<ParseResult>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRiff = void 0;
|
|
4
|
+
const parse_riff_body_1 = require("./parse-riff-body");
|
|
5
|
+
const parse_riff_header_1 = require("./parse-riff-header");
|
|
6
|
+
const parseRiff = ({ iterator, state, }) => {
|
|
7
|
+
if (iterator.counter.getOffset() === 0) {
|
|
8
|
+
return Promise.resolve((0, parse_riff_header_1.parseRiffHeader)({ iterator, state }));
|
|
9
|
+
}
|
|
10
|
+
return (0, parse_riff_body_1.parseRiffBody)({
|
|
11
|
+
iterator,
|
|
12
|
+
state,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.parseRiff = parseRiff;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const parseStrf: ({ iterator, size,
|
|
2
|
+
import type { FccType, StrfBoxAudio, StrfBoxVideo } from './riff-box';
|
|
3
|
+
export declare const parseStrf: ({ iterator, size, fccType, }: {
|
|
4
4
|
iterator: BufferIterator;
|
|
5
5
|
size: number;
|
|
6
|
-
|
|
7
|
-
}) =>
|
|
6
|
+
fccType: FccType;
|
|
7
|
+
}) => StrfBoxAudio | StrfBoxVideo;
|
|
@@ -51,17 +51,13 @@ const parseStrfVideo = ({ iterator, size, }) => {
|
|
|
51
51
|
yPelsPerMeter,
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
|
-
const parseStrf = ({ iterator, size,
|
|
55
|
-
|
|
56
|
-
if (!strh) {
|
|
57
|
-
throw new Error('strh box not found');
|
|
58
|
-
}
|
|
59
|
-
if (strh.fccType === 'vids') {
|
|
54
|
+
const parseStrf = ({ iterator, size, fccType, }) => {
|
|
55
|
+
if (fccType === 'vids') {
|
|
60
56
|
return parseStrfVideo({ iterator, size });
|
|
61
57
|
}
|
|
62
|
-
if (
|
|
58
|
+
if (fccType === 'auds') {
|
|
63
59
|
return parseStrfAudio({ iterator, size });
|
|
64
60
|
}
|
|
65
|
-
throw new Error(`Unsupported fccType: ${
|
|
61
|
+
throw new Error(`Unsupported fccType: ${fccType}`);
|
|
66
62
|
};
|
|
67
63
|
exports.parseStrf = parseStrf;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseStrh = void 0;
|
|
4
|
+
const parse_strf_1 = require("./parse-strf");
|
|
4
5
|
const parseStrh = ({ iterator, size, }) => {
|
|
5
6
|
const box = iterator.startBox(size);
|
|
6
7
|
const fccType = iterator.getByteString(4, false);
|
|
@@ -28,6 +29,15 @@ const parseStrh = ({ iterator, size, }) => {
|
|
|
28
29
|
const quality = iterator.getUint32Le();
|
|
29
30
|
const sampleSize = iterator.getUint32Le();
|
|
30
31
|
box.discardRest();
|
|
32
|
+
const ckId = iterator.getByteString(4, false);
|
|
33
|
+
const ckSize = iterator.getUint32Le();
|
|
34
|
+
if (ckId !== 'strf') {
|
|
35
|
+
throw new Error(`Expected strf, got ${JSON.stringify(ckId)}`);
|
|
36
|
+
}
|
|
37
|
+
if (iterator.bytesRemaining() < ckSize) {
|
|
38
|
+
throw new Error('Expected strf to be complete');
|
|
39
|
+
}
|
|
40
|
+
const strf = (0, parse_strf_1.parseStrf)({ iterator, size: ckSize, fccType });
|
|
31
41
|
return {
|
|
32
42
|
type: 'strh-box',
|
|
33
43
|
fccType,
|
|
@@ -43,6 +53,7 @@ const parseStrh = ({ iterator, size, }) => {
|
|
|
43
53
|
start,
|
|
44
54
|
suggestedBufferSize,
|
|
45
55
|
language,
|
|
56
|
+
strf,
|
|
46
57
|
};
|
|
47
58
|
};
|
|
48
59
|
exports.parseStrh = parseStrh;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParserState } from '../../state/parser-state';
|
|
3
|
+
export declare const parseVideoSection: ({ state, iterator, }: {
|
|
4
|
+
state: ParserState;
|
|
5
|
+
iterator: BufferIterator;
|
|
6
|
+
}) => Promise<import("./expect-riff-box").RiffResult>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseVideoSection = void 0;
|
|
4
|
+
const get_tracks_1 = require("../../get-tracks");
|
|
5
|
+
const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
|
|
6
|
+
const parse_movi_1 = require("./parse-movi");
|
|
7
|
+
const parseVideoSection = ({ state, iterator, }) => {
|
|
8
|
+
const videoSection = state.videoSection.getVideoSection();
|
|
9
|
+
const movi = (0, parse_movi_1.parseMovi)({
|
|
10
|
+
iterator,
|
|
11
|
+
maxOffset: videoSection.start + videoSection.size,
|
|
12
|
+
state,
|
|
13
|
+
});
|
|
14
|
+
const tracks = (0, get_tracks_1.getTracks)(state);
|
|
15
|
+
if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
|
|
16
|
+
state.callbacks.tracks.setIsDone();
|
|
17
|
+
}
|
|
18
|
+
return movi;
|
|
19
|
+
};
|
|
20
|
+
exports.parseVideoSection = parseVideoSection;
|
|
@@ -30,9 +30,10 @@ export type AvihBox = {
|
|
|
30
30
|
width: number;
|
|
31
31
|
height: number;
|
|
32
32
|
};
|
|
33
|
+
export type FccType = 'vids' | 'auds';
|
|
33
34
|
export type StrhBox = {
|
|
34
35
|
type: 'strh-box';
|
|
35
|
-
fccType:
|
|
36
|
+
fccType: FccType;
|
|
36
37
|
handler: 'H264' | number;
|
|
37
38
|
flags: number;
|
|
38
39
|
priority: number;
|
|
@@ -45,6 +46,7 @@ export type StrhBox = {
|
|
|
45
46
|
quality: number;
|
|
46
47
|
sampleSize: number;
|
|
47
48
|
language: number;
|
|
49
|
+
strf: StrfBoxVideo | StrfBoxAudio;
|
|
48
50
|
};
|
|
49
51
|
export type StrfBoxVideo = {
|
|
50
52
|
type: 'strf-box-video';
|
|
@@ -75,11 +77,8 @@ export type RiffHeader = {
|
|
|
75
77
|
fileSize: number;
|
|
76
78
|
fileType: string;
|
|
77
79
|
};
|
|
78
|
-
export type MoviBox = {
|
|
79
|
-
type: 'movi-box';
|
|
80
|
-
};
|
|
81
80
|
export type IsftBox = {
|
|
82
81
|
type: 'isft-box';
|
|
83
82
|
software: string;
|
|
84
83
|
};
|
|
85
|
-
export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox | AvihBox | StrhBox | StrfBoxVideo | StrfBoxAudio |
|
|
84
|
+
export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox | AvihBox | StrhBox | StrfBoxVideo | StrfBoxAudio | IsftBox;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { RiffStructure } from '../../parse-result';
|
|
2
|
-
import type { AvihBox, ListBox, RiffBox,
|
|
2
|
+
import type { AvihBox, ListBox, RiffBox, StrhBox } from './riff-box';
|
|
3
3
|
export declare const isRiffAvi: (structure: RiffStructure) => boolean;
|
|
4
4
|
export declare const getHdlrBox: (structure: RiffStructure) => ListBox | null;
|
|
5
5
|
export declare const getAvihBox: (structure: RiffStructure) => AvihBox | null;
|
|
6
6
|
export declare const getStrlBoxes: (structure: RiffStructure) => ListBox[];
|
|
7
7
|
export declare const getStrhBox: (strlBoxChildren: RiffBox[]) => StrhBox | null;
|
|
8
|
-
export declare const getStrfBox: (strlBoxChildren: RiffBox[]) => StrfBoxAudio | StrfBoxVideo | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getStrhBox = exports.getStrlBoxes = exports.getAvihBox = exports.getHdlrBox = exports.isRiffAvi = void 0;
|
|
4
4
|
const isRiffAvi = (structure) => {
|
|
5
5
|
return structure.boxes.some((box) => box.type === 'riff-header' && box.fileType === 'AVI');
|
|
6
6
|
};
|
|
@@ -29,8 +29,3 @@ const getStrhBox = (strlBoxChildren) => {
|
|
|
29
29
|
return strlBoxChildren.find((box) => box.type === 'strh-box');
|
|
30
30
|
};
|
|
31
31
|
exports.getStrhBox = getStrhBox;
|
|
32
|
-
const getStrfBox = (strlBoxChildren) => {
|
|
33
|
-
var _a;
|
|
34
|
-
return ((_a = strlBoxChildren.find((box) => box.type === 'strf-box-audio' || box.type === 'strf-box-video')) !== null && _a !== void 0 ? _a : null);
|
|
35
|
-
};
|
|
36
|
-
exports.getStrfBox = getStrfBox;
|