@remotion/media-parser 4.0.249 → 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/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 +2 -8
- package/dist/boxes/iso-base-media/get-children.js +14 -30
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -23
- package/dist/boxes/iso-base-media/mdat/mdat.js +80 -130
- package/dist/boxes/iso-base-media/moov/moov.d.ts +1 -6
- package/dist/boxes/iso-base-media/moov/moov.js +5 -14
- 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 +2 -10
- package/dist/boxes/iso-base-media/parse-boxes.js +33 -116
- package/dist/boxes/iso-base-media/parse-mdat-partially.d.ts +1 -4
- package/dist/boxes/iso-base-media/parse-mdat-partially.js +2 -11
- package/dist/boxes/iso-base-media/process-box.d.ts +1 -9
- package/dist/boxes/iso-base-media/process-box.js +49 -143
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +1 -4
- package/dist/boxes/iso-base-media/stsd/mebx.js +5 -14
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -12
- package/dist/boxes/iso-base-media/stsd/samples.js +24 -66
- 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 -14
- 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/id3.d.ts +1 -3
- package/dist/boxes/mp3/id3.js +7 -5
- package/dist/boxes/mp3/parse-mp3.d.ts +2 -3
- package/dist/boxes/mp3/parse-mp3.js +3 -19
- package/dist/boxes/riff/expect-riff-box.d.ts +1 -9
- package/dist/boxes/riff/expect-riff-box.js +47 -25
- 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-fmt-box.d.ts +3 -2
- package/dist/boxes/riff/parse-fmt-box.js +7 -5
- package/dist/boxes/riff/parse-list-box.d.ts +1 -3
- package/dist/boxes/riff/parse-list-box.js +16 -16
- 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 +2 -6
- package/dist/boxes/riff/parse-riff-body.js +15 -95
- package/dist/boxes/riff/parse-riff-box.d.ts +1 -4
- package/dist/boxes/riff/parse-riff-box.js +3 -7
- 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 +7 -26
- 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 +0 -3
- package/dist/buffer-iterator.js +6 -16
- package/dist/bun-reader.d.ts +1 -0
- package/dist/bun-reader.js +17 -0
- package/dist/emit-available-info.js +4 -4
- package/dist/esm/from-node.mjs +8 -9
- package/dist/esm/index.mjs +4224 -4950
- package/dist/file-types/detect-file-type.js +4 -2
- package/dist/get-audio-codec.d.ts +1 -1
- package/dist/get-audio-codec.js +2 -2
- package/dist/get-dimensions.js +1 -1
- package/dist/get-duration.js +1 -1
- package/dist/get-is-hdr.d.ts +1 -1
- package/dist/get-is-hdr.js +2 -2
- package/dist/get-tracks.d.ts +1 -1
- package/dist/get-tracks.js +14 -13
- package/dist/get-video-codec.d.ts +1 -1
- package/dist/get-video-codec.js +2 -2
- package/dist/index.d.ts +50 -24
- package/dist/index.js +1 -1
- package/dist/may-skip-video-data/may-skip-video-data.js +6 -2
- package/dist/parse-media.js +45 -30
- package/dist/parse-result.d.ts +1 -18
- package/dist/parse-video.d.ts +3 -17
- package/dist/parse-video.js +45 -32
- 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 -27
- 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/parser-state.d.ts +49 -14
- package/dist/state/parser-state.js +11 -3
- package/dist/state/sample-callbacks.d.ts +5 -1
- package/dist/state/sample-callbacks.js +4 -1
- 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/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/test.json +663 -0
|
@@ -67,9 +67,6 @@ const makeAviVideoTrack = ({ strh, strf, index, }) => {
|
|
|
67
67
|
};
|
|
68
68
|
exports.makeAviVideoTrack = makeAviVideoTrack;
|
|
69
69
|
const getTracksFromAvi = (structure, state) => {
|
|
70
|
-
if (!(0, traversal_1.isRiffAvi)(structure)) {
|
|
71
|
-
throw new Error('Not an AVI file');
|
|
72
|
-
}
|
|
73
70
|
const videoTracks = [];
|
|
74
71
|
const audioTracks = [];
|
|
75
72
|
const otherTracks = [];
|
|
@@ -77,10 +74,10 @@ const getTracksFromAvi = (structure, state) => {
|
|
|
77
74
|
let i = 0;
|
|
78
75
|
for (const box of boxes) {
|
|
79
76
|
const strh = (0, traversal_1.getStrhBox)(box.children);
|
|
80
|
-
|
|
81
|
-
if (!strh || !strf) {
|
|
77
|
+
if (!strh) {
|
|
82
78
|
continue;
|
|
83
79
|
}
|
|
80
|
+
const { strf } = strh;
|
|
84
81
|
if (strf.type === 'strf-box-video') {
|
|
85
82
|
videoTracks.push((0, add_avc_profile_to_track_1.addAvcProfileToTrack)((0, exports.makeAviVideoTrack)({ strh, strf, index: i }), state.riff.getAvcProfile()));
|
|
86
83
|
}
|
|
@@ -95,17 +92,16 @@ const getTracksFromAvi = (structure, state) => {
|
|
|
95
92
|
return { audioTracks, otherTracks, videoTracks };
|
|
96
93
|
};
|
|
97
94
|
exports.getTracksFromAvi = getTracksFromAvi;
|
|
98
|
-
const hasAllTracksFromAvi = (
|
|
99
|
-
if (!(0, traversal_1.isRiffAvi)(structure)) {
|
|
100
|
-
throw new Error('Not an AVI file');
|
|
101
|
-
}
|
|
95
|
+
const hasAllTracksFromAvi = (state) => {
|
|
102
96
|
try {
|
|
97
|
+
const structure = state.structure.getStructure();
|
|
103
98
|
const numberOfTracks = (0, exports.getNumberOfTracks)(structure);
|
|
104
99
|
const tracks = (0, exports.getTracksFromAvi)(structure, state);
|
|
105
100
|
return (tracks.videoTracks.length +
|
|
106
101
|
tracks.audioTracks.length +
|
|
107
102
|
tracks.otherTracks.length ===
|
|
108
|
-
numberOfTracks
|
|
103
|
+
numberOfTracks &&
|
|
104
|
+
!tracks.videoTracks.find((t) => t.codec === exports.TO_BE_OVERRIDDEN_LATER));
|
|
109
105
|
}
|
|
110
106
|
catch (_a) {
|
|
111
107
|
return false;
|
|
@@ -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,10 +1,8 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../options';
|
|
3
2
|
import type { ParserState } from '../../state/parser-state';
|
|
4
3
|
import type { RiffBox } from './riff-box';
|
|
5
|
-
export declare const parseListBox: ({ iterator, size, state,
|
|
4
|
+
export declare const parseListBox: ({ iterator, size, state, }: {
|
|
6
5
|
iterator: BufferIterator;
|
|
7
6
|
size: number;
|
|
8
7
|
state: ParserState;
|
|
9
|
-
fields: Options<ParseMediaFields>;
|
|
10
8
|
}) => Promise<RiffBox>;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseListBox = void 0;
|
|
4
|
-
const
|
|
5
|
-
const parseListBox = async ({ iterator, size, state,
|
|
4
|
+
const expect_riff_box_1 = require("./expect-riff-box");
|
|
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
|
-
|
|
23
|
-
|
|
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
|
+
}
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
type: 'list-box',
|
|
27
27
|
listType,
|
|
28
|
-
children:
|
|
28
|
+
children: boxes,
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
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;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ParseResult, RiffStructure } from '../../parse-result';
|
|
2
|
+
import type { ParseResult } from '../../parse-result';
|
|
4
3
|
import type { ParserState } from '../../state/parser-state';
|
|
5
|
-
export declare const parseRiffBody: ({ iterator,
|
|
4
|
+
export declare const parseRiffBody: ({ iterator, state, }: {
|
|
6
5
|
iterator: BufferIterator;
|
|
7
|
-
structure: RiffStructure;
|
|
8
|
-
maxOffset: number;
|
|
9
6
|
state: ParserState;
|
|
10
|
-
fields: Options<ParseMediaFields>;
|
|
11
7
|
}) => Promise<ParseResult>;
|
|
@@ -1,105 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseRiffBody = void 0;
|
|
4
|
-
const get_tracks_1 = require("../../get-tracks");
|
|
5
|
-
const has_all_info_1 = require("../../has-all-info");
|
|
6
|
-
const register_track_1 = require("../../register-track");
|
|
7
|
-
const continue_after_riff_result_1 = require("./continue-after-riff-result");
|
|
8
4
|
const expect_riff_box_1 = require("./expect-riff-box");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
status: 'incomplete',
|
|
24
|
-
skipTo: result.skipTo,
|
|
25
|
-
continueParsing() {
|
|
26
|
-
return Promise.resolve((0, continue_after_riff_result_1.continueAfterRiffBoxResult)({
|
|
27
|
-
iterator,
|
|
28
|
-
maxOffset,
|
|
29
|
-
state,
|
|
30
|
-
result,
|
|
31
|
-
structure,
|
|
32
|
-
fields,
|
|
33
|
-
}));
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (result.type === 'incomplete') {
|
|
38
|
-
return {
|
|
39
|
-
status: 'incomplete',
|
|
40
|
-
async continueParsing() {
|
|
41
|
-
return Promise.resolve((0, continue_after_riff_result_1.continueAfterRiffBoxResult)({
|
|
42
|
-
iterator,
|
|
43
|
-
maxOffset,
|
|
44
|
-
state,
|
|
45
|
-
result: await result.continueParsing(),
|
|
46
|
-
structure,
|
|
47
|
-
fields,
|
|
48
|
-
}));
|
|
49
|
-
},
|
|
50
|
-
skipTo: null,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (result.box === null) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
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();
|
|
56
19
|
structure.boxes.push(result.box);
|
|
57
|
-
// When parsing an AVI
|
|
58
|
-
if (result.box.type === 'list-box' && result.box.listType === 'hdrl') {
|
|
59
|
-
const tracks = (0, get_tracks_1.getTracks)(structure, state);
|
|
60
|
-
if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
|
|
61
|
-
state.callbacks.tracks.setIsDone();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// When parsing a WAV
|
|
65
|
-
if (result.box.type === 'wave-format-box') {
|
|
66
|
-
state.callbacks.tracks.setIsDone();
|
|
67
|
-
}
|
|
68
|
-
if (result.box.type === 'strf-box-video' ||
|
|
69
|
-
result.box.type === 'strf-box-audio') {
|
|
70
|
-
const strh = (0, traversal_1.getStrhBox)(structure.boxes);
|
|
71
|
-
const strf = (0, traversal_1.getStrfBox)(structure.boxes);
|
|
72
|
-
if (!strh || !strf) {
|
|
73
|
-
throw new Error('strh or strf box missing');
|
|
74
|
-
}
|
|
75
|
-
if (strf.type === 'strf-box-audio' && state.onAudioTrack) {
|
|
76
|
-
const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
|
|
77
|
-
index: state.riff.getNextTrackIndex(),
|
|
78
|
-
strf,
|
|
79
|
-
});
|
|
80
|
-
await (0, register_track_1.registerTrack)({
|
|
81
|
-
state,
|
|
82
|
-
track: audioTrack,
|
|
83
|
-
container: 'avi',
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (state.onVideoTrack && strf.type === 'strf-box-video') {
|
|
87
|
-
const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
|
|
88
|
-
strh,
|
|
89
|
-
index: state.riff.getNextTrackIndex(),
|
|
90
|
-
strf,
|
|
91
|
-
});
|
|
92
|
-
(0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
|
|
93
|
-
state,
|
|
94
|
-
track: videoTrack,
|
|
95
|
-
container: 'avi',
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
state.riff.incrementNextTrackIndex();
|
|
99
|
-
}
|
|
100
20
|
}
|
|
101
21
|
return {
|
|
102
|
-
|
|
22
|
+
skipTo: result.skipTo,
|
|
103
23
|
};
|
|
104
24
|
};
|
|
105
25
|
exports.parseRiffBody = parseRiffBody;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../options';
|
|
3
2
|
import type { ParserState } from '../../state/parser-state';
|
|
4
3
|
import type { RiffBox } from './riff-box';
|
|
5
|
-
export declare const parseRiffBox: ({ iterator, size, id,
|
|
4
|
+
export declare const parseRiffBox: ({ iterator, size, id, state, }: {
|
|
6
5
|
iterator: BufferIterator;
|
|
7
6
|
size: number;
|
|
8
7
|
id: string;
|
|
9
|
-
boxes: RiffBox[];
|
|
10
8
|
state: ParserState;
|
|
11
|
-
fields: Options<ParseMediaFields>;
|
|
12
9
|
}) => Promise<RiffBox>;
|
|
@@ -5,14 +5,13 @@ 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
|
-
return (0, parse_list_box_1.parseListBox)({ iterator, size, state
|
|
14
|
+
return (0, parse_list_box_1.parseListBox)({ iterator, size, state });
|
|
16
15
|
}
|
|
17
16
|
if (id === 'ISFT') {
|
|
18
17
|
return Promise.resolve((0, parse_isft_1.parseIsft)({ iterator, size }));
|
|
@@ -23,9 +22,6 @@ const parseRiffBox = ({ iterator, size, id, boxes, state, fields, }) => {
|
|
|
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;
|