@remotion/media-parser 4.0.230 → 4.0.232
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/add-avc-profile-to-track.d.ts +3 -0
- package/dist/add-avc-profile-to-track.js +35 -0
- package/dist/add-new-matroska-tracks.d.ts +6 -1
- package/dist/add-new-matroska-tracks.js +16 -1
- package/dist/boxes/avc/parse-avc.d.ts +18 -0
- package/dist/boxes/avc/parse-avc.js +96 -0
- package/dist/boxes/iso-base-media/make-track.js +3 -3
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -2
- package/dist/boxes/iso-base-media/mdat/mdat.js +5 -2
- package/dist/boxes/iso-base-media/moov/moov.js +2 -2
- package/dist/boxes/iso-base-media/process-box.d.ts +5 -5
- package/dist/boxes/iso-base-media/process-box.js +38 -37
- package/dist/boxes/iso-base-media/stsd/mebx.js +2 -2
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +2 -2
- package/dist/boxes/iso-base-media/stsd/samples.js +9 -9
- package/dist/boxes/iso-base-media/trak/trak.js +2 -2
- package/dist/boxes/iso-base-media/traversal.d.ts +1 -1
- package/dist/boxes/riff/expect-riff-box.d.ts +16 -0
- package/dist/boxes/riff/expect-riff-box.js +49 -0
- package/dist/boxes/riff/get-tracks-from-avi.d.ts +21 -0
- package/dist/boxes/riff/get-tracks-from-avi.js +108 -0
- package/dist/boxes/riff/is-movi.d.ts +2 -0
- package/dist/boxes/riff/is-movi.js +12 -0
- package/dist/boxes/riff/parse-avih.d.ts +6 -0
- package/dist/boxes/riff/parse-avih.js +32 -0
- package/dist/boxes/riff/parse-box.d.ts +13 -0
- package/dist/boxes/riff/parse-box.js +113 -0
- package/dist/boxes/riff/parse-fmt-box.d.ts +7 -0
- package/dist/boxes/riff/parse-fmt-box.js +33 -0
- package/dist/boxes/riff/parse-list-box.d.ts +8 -0
- package/dist/boxes/riff/parse-list-box.js +30 -0
- package/dist/boxes/riff/parse-movi.d.ts +17 -0
- package/dist/boxes/riff/parse-movi.js +122 -0
- package/dist/boxes/riff/parse-riff-box.d.ts +10 -0
- package/dist/boxes/riff/parse-riff-box.js +33 -0
- package/dist/boxes/riff/parse-strf.d.ts +7 -0
- package/dist/boxes/riff/parse-strf.js +67 -0
- package/dist/boxes/riff/parse-strh.d.ts +6 -0
- package/dist/boxes/riff/parse-strh.js +46 -0
- package/dist/boxes/riff/riff-box.d.ts +81 -0
- package/dist/boxes/riff/riff-box.js +2 -0
- package/dist/boxes/riff/strf.d.ts +7 -0
- package/dist/boxes/riff/strf.js +67 -0
- package/dist/boxes/riff/timescale.d.ts +1 -0
- package/dist/boxes/riff/timescale.js +4 -0
- package/dist/boxes/riff/traversal.d.ts +8 -0
- package/dist/boxes/riff/traversal.js +36 -0
- package/dist/boxes/webm/parse-ebml.js +2 -2
- package/dist/boxes/webm/parse-webm-header.d.ts +2 -2
- package/dist/boxes/webm/parse-webm-header.js +23 -4
- package/dist/boxes/webm/segments/parse-children.d.ts +12 -7
- package/dist/boxes/webm/segments/parse-children.js +67 -57
- package/dist/boxes/webm/segments.d.ts +8 -3
- package/dist/boxes/webm/segments.js +70 -39
- package/dist/boxes/webm/traversal.d.ts +2 -2
- package/dist/buffer-iterator.d.ts +6 -1
- package/dist/buffer-iterator.js +24 -5
- package/dist/create/iso-base-media/create-iso-base-media.d.ts +1 -1
- package/dist/create/iso-base-media/create-iso-base-media.js +4 -9
- package/dist/create/matroska/cluster.d.ts +7 -1
- package/dist/create/matroska/cluster.js +8 -5
- package/dist/create/matroska/create-matroska-media.d.ts +1 -1
- package/dist/create/matroska/create-matroska-media.js +27 -14
- package/dist/create/media-fn.d.ts +1 -1
- package/dist/create/mp3/create-mp3.d.ts +2 -0
- package/dist/create/mp3/create-mp3.js +49 -0
- package/dist/create/wav/create-wav.d.ts +2 -0
- package/dist/create/wav/create-wav.js +108 -0
- package/dist/emit-available-info.d.ts +2 -2
- package/dist/emit-available-info.js +28 -13
- package/dist/esm/buffer.mjs +2 -2
- package/dist/esm/from-node.mjs +2 -1
- package/dist/esm/index.mjs +1513 -331
- package/dist/esm/web-fs.mjs +2 -2
- package/dist/get-audio-codec.d.ts +3 -3
- package/dist/get-audio-codec.js +1 -6
- package/dist/get-container.d.ts +3 -3
- package/dist/get-container.js +9 -7
- package/dist/get-dimensions.d.ts +3 -3
- package/dist/get-duration.d.ts +8 -3
- package/dist/get-duration.js +37 -15
- package/dist/get-fps.d.ts +3 -3
- package/dist/get-fps.js +36 -2
- package/dist/get-tracks.d.ts +4 -7
- package/dist/get-tracks.js +55 -27
- package/dist/get-video-codec.d.ts +5 -4
- package/dist/get-video-codec.js +39 -15
- package/dist/has-all-info.d.ts +2 -2
- package/dist/has-all-info.js +9 -9
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -1
- package/dist/options.d.ts +17 -10
- package/dist/parse-media.js +43 -14
- package/dist/parse-result.d.ts +35 -6
- package/dist/parse-video.d.ts +3 -3
- package/dist/parse-video.js +8 -16
- package/dist/parser-context.d.ts +1 -0
- package/dist/parser-state.d.ts +11 -0
- package/dist/parser-state.js +30 -0
- package/dist/readers/from-node.js +2 -1
- package/dist/readers/reader.d.ts +2 -2
- package/dist/register-track.d.ts +13 -0
- package/dist/register-track.js +25 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/dist/writers/buffer-implementation/writer.d.ts +2 -2
- package/dist/writers/buffer-implementation/writer.js +2 -2
- package/dist/writers/web-fs.js +2 -3
- package/dist/writers/writer.d.ts +5 -3
- package/package.json +3 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseStrf = void 0;
|
|
4
|
+
const parseStrfAudio = ({ iterator, size, }) => {
|
|
5
|
+
const box = iterator.startBox(size);
|
|
6
|
+
const formatTag = iterator.getUint16Le();
|
|
7
|
+
const numberOfChannels = iterator.getUint16Le();
|
|
8
|
+
const samplesPerSec = iterator.getUint32Le();
|
|
9
|
+
const avgBytesPerSec = iterator.getUint32Le();
|
|
10
|
+
const blockAlign = iterator.getUint16Le();
|
|
11
|
+
const bitsPerSample = iterator.getUint16Le();
|
|
12
|
+
const cbSize = iterator.getUint16Le();
|
|
13
|
+
box.expectNoMoreBytes();
|
|
14
|
+
return {
|
|
15
|
+
type: 'strf-box-audio',
|
|
16
|
+
avgBytesPerSecond: avgBytesPerSec,
|
|
17
|
+
bitsPerSample,
|
|
18
|
+
blockAlign,
|
|
19
|
+
cbSize,
|
|
20
|
+
formatTag,
|
|
21
|
+
numberOfChannels,
|
|
22
|
+
sampleRate: samplesPerSec,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const parseStrfVideo = ({ iterator, size, }) => {
|
|
26
|
+
const box = iterator.startBox(size);
|
|
27
|
+
const biSize = iterator.getUint32Le();
|
|
28
|
+
const width = iterator.getInt32Le();
|
|
29
|
+
const height = iterator.getInt32Le();
|
|
30
|
+
const planes = iterator.getUint16Le();
|
|
31
|
+
const bitCount = iterator.getUint16Le();
|
|
32
|
+
const compression = iterator.getByteString(4);
|
|
33
|
+
const sizeImage = iterator.getUint32Le();
|
|
34
|
+
const xPelsPerMeter = iterator.getInt32Le();
|
|
35
|
+
const yPelsPerMeter = iterator.getInt32Le();
|
|
36
|
+
const clrUsed = iterator.getUint32Le();
|
|
37
|
+
const clrImportant = iterator.getUint32Le();
|
|
38
|
+
box.expectNoMoreBytes();
|
|
39
|
+
return {
|
|
40
|
+
type: 'strf-box-video',
|
|
41
|
+
biSize,
|
|
42
|
+
bitCount,
|
|
43
|
+
clrImportant,
|
|
44
|
+
clrUsed,
|
|
45
|
+
compression,
|
|
46
|
+
height,
|
|
47
|
+
planes,
|
|
48
|
+
sizeImage,
|
|
49
|
+
width,
|
|
50
|
+
xPelsPerMeter,
|
|
51
|
+
yPelsPerMeter,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const parseStrf = ({ iterator, size, boxes, }) => {
|
|
55
|
+
const strh = boxes.find((b) => b.type === 'strh-box');
|
|
56
|
+
if (!strh) {
|
|
57
|
+
throw new Error('strh box not found');
|
|
58
|
+
}
|
|
59
|
+
if (strh.fccType === 'vids') {
|
|
60
|
+
return parseStrfVideo({ iterator, size });
|
|
61
|
+
}
|
|
62
|
+
if (strh.fccType === 'auds') {
|
|
63
|
+
return parseStrfAudio({ iterator, size });
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Unsupported fccType: ${strh.fccType}`);
|
|
66
|
+
};
|
|
67
|
+
exports.parseStrf = parseStrf;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseStrh = void 0;
|
|
4
|
+
const parseStrh = ({ iterator, size, }) => {
|
|
5
|
+
const box = iterator.startBox(size);
|
|
6
|
+
const fccType = iterator.getByteString(4);
|
|
7
|
+
if (fccType !== 'vids' && fccType !== 'auds') {
|
|
8
|
+
throw new Error('Expected AVI handler to be vids / auds');
|
|
9
|
+
}
|
|
10
|
+
const handler = fccType === 'vids' ? iterator.getByteString(4) : iterator.getUint32Le();
|
|
11
|
+
if (typeof handler === 'string' && handler !== 'H264') {
|
|
12
|
+
throw new Error(`Only H264 is supported as a stream type in .avi, got ${handler}`);
|
|
13
|
+
}
|
|
14
|
+
if (fccType === 'auds' && handler !== 1) {
|
|
15
|
+
throw new Error(`Only "1" is supported as a stream type in .avi, got ${handler}`);
|
|
16
|
+
}
|
|
17
|
+
const flags = iterator.getUint32Le();
|
|
18
|
+
const priority = iterator.getUint16Le();
|
|
19
|
+
const language = iterator.getUint16Le();
|
|
20
|
+
const initialFrames = iterator.getUint32Le();
|
|
21
|
+
const scale = iterator.getUint32Le();
|
|
22
|
+
const rate = iterator.getUint32Le();
|
|
23
|
+
const start = iterator.getUint32Le();
|
|
24
|
+
const length = iterator.getUint32Le();
|
|
25
|
+
const suggestedBufferSize = iterator.getUint32Le();
|
|
26
|
+
const quality = iterator.getUint32Le();
|
|
27
|
+
const sampleSize = iterator.getUint32Le();
|
|
28
|
+
box.discardRest();
|
|
29
|
+
return {
|
|
30
|
+
type: 'strh-box',
|
|
31
|
+
fccType,
|
|
32
|
+
handler,
|
|
33
|
+
flags,
|
|
34
|
+
priority,
|
|
35
|
+
initialFrames,
|
|
36
|
+
length,
|
|
37
|
+
quality,
|
|
38
|
+
rate,
|
|
39
|
+
sampleSize,
|
|
40
|
+
scale,
|
|
41
|
+
start,
|
|
42
|
+
suggestedBufferSize,
|
|
43
|
+
language,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.parseStrh = parseStrh;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type WaveFormatBox = {
|
|
2
|
+
type: 'wave-format-box';
|
|
3
|
+
formatTag: 1;
|
|
4
|
+
numberOfChannels: number;
|
|
5
|
+
sampleRate: number;
|
|
6
|
+
blockAlign: number;
|
|
7
|
+
byteRate: number;
|
|
8
|
+
bitsPerSample: number;
|
|
9
|
+
};
|
|
10
|
+
export type ListBox = {
|
|
11
|
+
type: 'list-box';
|
|
12
|
+
listType: string;
|
|
13
|
+
children: RiffBox[];
|
|
14
|
+
};
|
|
15
|
+
export type RiffRegularBox = {
|
|
16
|
+
type: 'riff-box';
|
|
17
|
+
size: number;
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
export type AvihBox = {
|
|
21
|
+
type: 'avih-box';
|
|
22
|
+
microSecPerFrame: number;
|
|
23
|
+
maxBytesPerSecond: number;
|
|
24
|
+
paddingGranularity: number;
|
|
25
|
+
flags: number;
|
|
26
|
+
totalFrames: number;
|
|
27
|
+
initialFrames: number;
|
|
28
|
+
streams: number;
|
|
29
|
+
suggestedBufferSize: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
export type StrhBox = {
|
|
34
|
+
type: 'strh-box';
|
|
35
|
+
fccType: 'vids' | 'auds';
|
|
36
|
+
handler: 'H264' | number;
|
|
37
|
+
flags: number;
|
|
38
|
+
priority: number;
|
|
39
|
+
initialFrames: number;
|
|
40
|
+
scale: number;
|
|
41
|
+
rate: number;
|
|
42
|
+
start: number;
|
|
43
|
+
length: number;
|
|
44
|
+
suggestedBufferSize: number;
|
|
45
|
+
quality: number;
|
|
46
|
+
sampleSize: number;
|
|
47
|
+
language: number;
|
|
48
|
+
};
|
|
49
|
+
export type StrfBoxVideo = {
|
|
50
|
+
type: 'strf-box-video';
|
|
51
|
+
biSize: number;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
planes: number;
|
|
55
|
+
bitCount: number;
|
|
56
|
+
compression: string;
|
|
57
|
+
sizeImage: number;
|
|
58
|
+
xPelsPerMeter: number;
|
|
59
|
+
yPelsPerMeter: number;
|
|
60
|
+
clrUsed: number;
|
|
61
|
+
clrImportant: number;
|
|
62
|
+
};
|
|
63
|
+
export type StrfBoxAudio = {
|
|
64
|
+
type: 'strf-box-audio';
|
|
65
|
+
formatTag: number;
|
|
66
|
+
numberOfChannels: number;
|
|
67
|
+
sampleRate: number;
|
|
68
|
+
avgBytesPerSecond: number;
|
|
69
|
+
blockAlign: number;
|
|
70
|
+
bitsPerSample: number;
|
|
71
|
+
cbSize: number;
|
|
72
|
+
};
|
|
73
|
+
export type RiffHeader = {
|
|
74
|
+
type: 'riff-header';
|
|
75
|
+
fileSize: number;
|
|
76
|
+
fileType: string;
|
|
77
|
+
};
|
|
78
|
+
export type MoviBox = {
|
|
79
|
+
type: 'movi-box';
|
|
80
|
+
};
|
|
81
|
+
export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox | AvihBox | StrhBox | StrfBoxVideo | StrfBoxAudio | MoviBox;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseStrf = void 0;
|
|
4
|
+
const parseStrfAudio = ({ iterator, size, }) => {
|
|
5
|
+
const box = iterator.startBox(size);
|
|
6
|
+
const formatTag = iterator.getUint16Le();
|
|
7
|
+
const numberOfChannels = iterator.getUint16Le();
|
|
8
|
+
const samplesPerSec = iterator.getUint32Le();
|
|
9
|
+
const avgBytesPerSec = iterator.getUint32Le();
|
|
10
|
+
const blockAlign = iterator.getUint16Le();
|
|
11
|
+
const bitsPerSample = iterator.getUint16Le();
|
|
12
|
+
const cbSize = iterator.getUint16Le();
|
|
13
|
+
box.expectNoMoreBytes();
|
|
14
|
+
return {
|
|
15
|
+
type: 'strf-box-audio',
|
|
16
|
+
avgBytesPerSecond: avgBytesPerSec,
|
|
17
|
+
bitsPerSample,
|
|
18
|
+
blockAlign,
|
|
19
|
+
cbSize,
|
|
20
|
+
formatTag,
|
|
21
|
+
numberOfChannels,
|
|
22
|
+
sampleRate: samplesPerSec,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const parseStrfVideo = ({ iterator, size, }) => {
|
|
26
|
+
const box = iterator.startBox(size);
|
|
27
|
+
const biSize = iterator.getUint32Le();
|
|
28
|
+
const width = iterator.getInt32Le();
|
|
29
|
+
const height = iterator.getInt32Le();
|
|
30
|
+
const planes = iterator.getUint16Le();
|
|
31
|
+
const bitCount = iterator.getUint16Le();
|
|
32
|
+
const compression = iterator.getByteString(4);
|
|
33
|
+
const sizeImage = iterator.getUint32Le();
|
|
34
|
+
const xPelsPerMeter = iterator.getInt32Le();
|
|
35
|
+
const yPelsPerMeter = iterator.getInt32Le();
|
|
36
|
+
const clrUsed = iterator.getUint32Le();
|
|
37
|
+
const clrImportant = iterator.getUint32Le();
|
|
38
|
+
box.expectNoMoreBytes();
|
|
39
|
+
return {
|
|
40
|
+
type: 'strf-box-video',
|
|
41
|
+
biSize,
|
|
42
|
+
bitCount,
|
|
43
|
+
clrImportant,
|
|
44
|
+
clrUsed,
|
|
45
|
+
compression,
|
|
46
|
+
height,
|
|
47
|
+
planes,
|
|
48
|
+
sizeImage,
|
|
49
|
+
width,
|
|
50
|
+
xPelsPerMeter,
|
|
51
|
+
yPelsPerMeter,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const parseStrf = ({ iterator, size, boxes, }) => {
|
|
55
|
+
const strh = boxes.find((b) => b.type === 'strh-box');
|
|
56
|
+
if (!strh) {
|
|
57
|
+
throw new Error('strh box not found');
|
|
58
|
+
}
|
|
59
|
+
if (strh.fccType === 'vids') {
|
|
60
|
+
return parseStrfVideo({ iterator, size });
|
|
61
|
+
}
|
|
62
|
+
if (strh.fccType === 'auds') {
|
|
63
|
+
return parseStrfAudio({ iterator, size });
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Unsupported fccType: ${strh.fccType}`);
|
|
66
|
+
};
|
|
67
|
+
exports.parseStrf = parseStrf;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MEDIA_PARSER_RIFF_TIMESCALE = 1000000;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RiffStructure } from '../../parse-result';
|
|
2
|
+
import type { AvihBox, ListBox, RiffBox, StrfBoxAudio, StrfBoxVideo, StrhBox } from './riff-box';
|
|
3
|
+
export declare const isRiffAvi: (structure: RiffStructure) => boolean;
|
|
4
|
+
export declare const getHdlrBox: (structure: RiffStructure) => ListBox | null;
|
|
5
|
+
export declare const getAvihBox: (structure: RiffStructure) => AvihBox | null;
|
|
6
|
+
export declare const getStrlBoxes: (structure: RiffStructure) => ListBox[];
|
|
7
|
+
export declare const getStrhBox: (strlBoxChildren: RiffBox[]) => StrhBox | null;
|
|
8
|
+
export declare const getStrfBox: (strlBoxChildren: RiffBox[]) => StrfBoxAudio | StrfBoxVideo | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStrfBox = exports.getStrhBox = exports.getStrlBoxes = exports.getAvihBox = exports.getHdlrBox = exports.isRiffAvi = void 0;
|
|
4
|
+
const isRiffAvi = (structure) => {
|
|
5
|
+
return structure.boxes.some((box) => box.type === 'riff-header' && box.fileType === 'AVI');
|
|
6
|
+
};
|
|
7
|
+
exports.isRiffAvi = isRiffAvi;
|
|
8
|
+
const getHdlrBox = (structure) => {
|
|
9
|
+
return structure.boxes.find((box) => box.type === 'list-box' && box.listType === 'hdrl');
|
|
10
|
+
};
|
|
11
|
+
exports.getHdlrBox = getHdlrBox;
|
|
12
|
+
const getAvihBox = (structure) => {
|
|
13
|
+
const hdlrBox = (0, exports.getHdlrBox)(structure);
|
|
14
|
+
if (!hdlrBox) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return hdlrBox.children.find((box) => box.type === 'avih-box');
|
|
18
|
+
};
|
|
19
|
+
exports.getAvihBox = getAvihBox;
|
|
20
|
+
const getStrlBoxes = (structure) => {
|
|
21
|
+
const hdlrBox = (0, exports.getHdlrBox)(structure);
|
|
22
|
+
if (!hdlrBox) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return hdlrBox.children.filter((box) => box.type === 'list-box' && box.listType === 'strl');
|
|
26
|
+
};
|
|
27
|
+
exports.getStrlBoxes = getStrlBoxes;
|
|
28
|
+
const getStrhBox = (strlBoxChildren) => {
|
|
29
|
+
return strlBoxChildren.find((box) => box.type === 'strh-box');
|
|
30
|
+
};
|
|
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.postprocessEbml = exports.parseEbml = void 0;
|
|
4
|
-
const
|
|
4
|
+
const register_track_1 = require("../../register-track");
|
|
5
5
|
const get_sample_from_block_1 = require("./get-sample-from-block");
|
|
6
6
|
const make_track_1 = require("./make-track");
|
|
7
7
|
const all_segments_1 = require("./segments/all-segments");
|
|
@@ -115,7 +115,7 @@ const postprocessEbml = async ({ offset, ebml, parserContext, }) => {
|
|
|
115
115
|
timescale: parserContext.parserState.getTimescale(),
|
|
116
116
|
});
|
|
117
117
|
if (track) {
|
|
118
|
-
await (0,
|
|
118
|
+
await (0, register_track_1.registerTrack)({
|
|
119
119
|
state: parserContext.parserState,
|
|
120
120
|
options: parserContext,
|
|
121
121
|
track,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { ParseResult } from '../../parse-result';
|
|
2
|
+
import type { MatroskaStructure, ParseResult } from '../../parse-result';
|
|
3
3
|
import type { ParserContext } from '../../parser-context';
|
|
4
|
-
export declare const parseWebm: (counter: BufferIterator, parserContext: ParserContext) => Promise<ParseResult
|
|
4
|
+
export declare const parseWebm: (counter: BufferIterator, parserContext: ParserContext) => Promise<ParseResult<MatroskaStructure>>;
|
|
@@ -2,14 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseWebm = void 0;
|
|
4
4
|
const parse_children_1 = require("./segments/parse-children");
|
|
5
|
+
const continueAfterMatroskaResult = (result, structure) => {
|
|
6
|
+
if (result.status === 'done') {
|
|
7
|
+
return {
|
|
8
|
+
status: 'done',
|
|
9
|
+
segments: structure,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
status: 'incomplete',
|
|
14
|
+
segments: structure,
|
|
15
|
+
continueParsing: async () => {
|
|
16
|
+
const newResult = await result.continueParsing();
|
|
17
|
+
return continueAfterMatroskaResult(newResult, structure);
|
|
18
|
+
},
|
|
19
|
+
skipTo: null,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
5
22
|
// Parsing according to https://darkcoding.net/software/reading-mediarecorders-webm-opus-output/
|
|
6
|
-
const parseWebm = (counter, parserContext) => {
|
|
7
|
-
|
|
23
|
+
const parseWebm = async (counter, parserContext) => {
|
|
24
|
+
const structure = { type: 'matroska', boxes: [] };
|
|
25
|
+
const results = await (0, parse_children_1.expectChildren)({
|
|
8
26
|
iterator: counter,
|
|
9
27
|
length: Infinity,
|
|
10
|
-
|
|
11
|
-
wrap: null,
|
|
28
|
+
children: structure.boxes,
|
|
12
29
|
parserContext,
|
|
30
|
+
startOffset: counter.counter.getOffset(),
|
|
13
31
|
});
|
|
32
|
+
return continueAfterMatroskaResult(results, structure);
|
|
14
33
|
};
|
|
15
34
|
exports.parseWebm = parseWebm;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExpectSegmentParseResult, MatroskaParseResult } from '../../../parse-result';
|
|
3
3
|
import type { ParserContext } from '../../../parser-context';
|
|
4
4
|
import type { MatroskaSegment } from '../segments';
|
|
5
|
-
type
|
|
6
|
-
export declare const
|
|
5
|
+
import type { PossibleEbml } from './all-segments';
|
|
6
|
+
export declare const expectAndProcessSegment: ({ iterator, parserContext, offset, children, }: {
|
|
7
|
+
iterator: BufferIterator;
|
|
8
|
+
parserContext: ParserContext;
|
|
9
|
+
offset: number;
|
|
10
|
+
children: PossibleEbml[];
|
|
11
|
+
}) => Promise<ExpectSegmentParseResult>;
|
|
12
|
+
export declare const expectChildren: ({ iterator, length, children, parserContext, startOffset, }: {
|
|
7
13
|
iterator: BufferIterator;
|
|
8
14
|
length: number;
|
|
9
|
-
|
|
10
|
-
wrap: WrapChildren | null;
|
|
15
|
+
children: MatroskaSegment[];
|
|
11
16
|
parserContext: ParserContext;
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
startOffset: number;
|
|
18
|
+
}) => Promise<MatroskaParseResult>;
|
|
@@ -1,100 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expectChildren = void 0;
|
|
3
|
+
exports.expectChildren = exports.expectAndProcessSegment = void 0;
|
|
4
4
|
const segments_1 = require("../segments");
|
|
5
|
-
const processParseResult = ({ parseResult, children,
|
|
5
|
+
const processParseResult = ({ parseResult, children, }) => {
|
|
6
|
+
if (parseResult.segment && !children.includes(parseResult.segment)) {
|
|
7
|
+
children.push(parseResult.segment);
|
|
8
|
+
}
|
|
6
9
|
if (parseResult.status === 'incomplete') {
|
|
7
10
|
// No need to decrement because expectSegment already does it
|
|
8
11
|
return {
|
|
9
12
|
status: 'incomplete',
|
|
10
|
-
|
|
13
|
+
segment: parseResult.segment,
|
|
11
14
|
continueParsing: async () => {
|
|
12
15
|
const newParseResult = await parseResult.continueParsing();
|
|
13
16
|
return processParseResult({
|
|
14
17
|
children,
|
|
15
18
|
parseResult: newParseResult,
|
|
16
|
-
wrap,
|
|
17
19
|
});
|
|
18
20
|
},
|
|
19
|
-
skipTo: null,
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
|
-
for (const segment of parseResult.segments) {
|
|
23
|
-
children.push(segment);
|
|
24
|
-
}
|
|
25
23
|
return {
|
|
26
24
|
status: 'done',
|
|
27
|
-
|
|
25
|
+
segment: parseResult.segment,
|
|
28
26
|
};
|
|
29
27
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const expectAndProcessSegment = async ({ iterator, parserContext, offset, children, }) => {
|
|
29
|
+
const segment = await (0, segments_1.expectSegment)({
|
|
30
|
+
iterator,
|
|
31
|
+
parserContext,
|
|
32
|
+
offset,
|
|
33
|
+
children,
|
|
34
|
+
});
|
|
35
|
+
return processParseResult({
|
|
36
|
+
children,
|
|
37
|
+
parseResult: segment,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
exports.expectAndProcessSegment = expectAndProcessSegment;
|
|
41
|
+
const continueAfterSegmentResult = async ({ result, length, children, parserContext, iterator, startOffset, }) => {
|
|
42
|
+
if (result.status === 'done') {
|
|
43
|
+
throw new Error('Should not continue after done');
|
|
33
44
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
if (continued.status === 'incomplete') {
|
|
37
|
-
if (!parserContext.supportsContentRange) {
|
|
38
|
-
throw new Error('Content-Range header is not supported by the reader, but was asked to seek');
|
|
39
|
-
}
|
|
45
|
+
const segmentResult = await result.continueParsing();
|
|
46
|
+
if (segmentResult.status === 'done') {
|
|
40
47
|
return {
|
|
41
48
|
status: 'incomplete',
|
|
42
|
-
continueParsing:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
continueParsing: () => {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
51
|
+
return (0, exports.expectChildren)({
|
|
52
|
+
children,
|
|
53
|
+
iterator,
|
|
54
|
+
length,
|
|
55
|
+
parserContext,
|
|
56
|
+
startOffset,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
skipTo: null,
|
|
52
60
|
};
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
return {
|
|
63
|
+
status: 'incomplete',
|
|
64
|
+
continueParsing: () => {
|
|
65
|
+
return continueAfterSegmentResult({
|
|
66
|
+
result: segmentResult,
|
|
67
|
+
children,
|
|
68
|
+
iterator,
|
|
69
|
+
length,
|
|
70
|
+
parserContext,
|
|
71
|
+
startOffset,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
skipTo: null,
|
|
75
|
+
};
|
|
62
76
|
};
|
|
63
|
-
const expectChildren = async ({ iterator, length,
|
|
64
|
-
const children = [...initialChildren];
|
|
65
|
-
const startOffset = iterator.counter.getOffset();
|
|
77
|
+
const expectChildren = async ({ iterator, length, children, parserContext, startOffset, }) => {
|
|
66
78
|
while (iterator.counter.getOffset() < startOffset + length) {
|
|
67
79
|
if (iterator.bytesRemaining() === 0) {
|
|
68
80
|
break;
|
|
69
81
|
}
|
|
70
|
-
const
|
|
71
|
-
const child =
|
|
82
|
+
const currentOffset = iterator.counter.getOffset();
|
|
83
|
+
const child = await (0, exports.expectAndProcessSegment)({
|
|
84
|
+
iterator,
|
|
85
|
+
parserContext,
|
|
86
|
+
offset: currentOffset,
|
|
72
87
|
children,
|
|
73
|
-
parseResult,
|
|
74
|
-
wrap,
|
|
75
88
|
});
|
|
76
89
|
if (child.status === 'incomplete') {
|
|
77
|
-
if (!parserContext.supportsContentRange) {
|
|
78
|
-
throw new Error('Content-Range header is not supported by the reader, but was asked to seek');
|
|
79
|
-
}
|
|
80
90
|
return {
|
|
81
91
|
status: 'incomplete',
|
|
82
|
-
continueParsing:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
continueParsing: () => {
|
|
93
|
+
return continueAfterSegmentResult({
|
|
94
|
+
result: child,
|
|
95
|
+
children,
|
|
96
|
+
iterator,
|
|
97
|
+
length: length - (currentOffset - startOffset),
|
|
98
|
+
parserContext,
|
|
99
|
+
startOffset: currentOffset,
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
skipTo: null,
|
|
92
103
|
};
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
return {
|
|
96
107
|
status: 'done',
|
|
97
|
-
segments: wrap ? [wrap(children)] : children,
|
|
98
108
|
};
|
|
99
109
|
};
|
|
100
110
|
exports.expectChildren = expectChildren;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExpectSegmentParseResult } from '../../parse-result';
|
|
3
3
|
import type { ParserContext } from '../../parser-context';
|
|
4
|
-
import type
|
|
4
|
+
import { type PossibleEbml, type TrackEntry } from './segments/all-segments';
|
|
5
5
|
export type MatroskaSegment = PossibleEbml;
|
|
6
6
|
export type OnTrackEntrySegment = (trackEntry: TrackEntry) => void;
|
|
7
|
-
export declare const expectSegment: (iterator
|
|
7
|
+
export declare const expectSegment: ({ iterator, parserContext, offset, children, }: {
|
|
8
|
+
iterator: BufferIterator;
|
|
9
|
+
parserContext: ParserContext;
|
|
10
|
+
offset: number;
|
|
11
|
+
children: PossibleEbml[];
|
|
12
|
+
}) => Promise<ExpectSegmentParseResult>;
|