@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
|
@@ -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;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { TransportStreamStructure } from '../../parse-result';
|
|
2
1
|
import type { ParserState } from '../../state/parser-state';
|
|
3
2
|
import type { AllTracks } from '../riff/get-tracks-from-avi';
|
|
4
|
-
export declare const getTracksFromTransportStream: (
|
|
5
|
-
export declare const hasAllTracksFromTransportStream: (
|
|
3
|
+
export declare const getTracksFromTransportStream: (parserState: ParserState) => AllTracks;
|
|
4
|
+
export declare const hasAllTracksFromTransportStream: (parserState: ParserState) => boolean;
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.hasAllTracksFromTransportStream = exports.getTracksFromTransportStream = void 0;
|
|
4
4
|
const truthy_1 = require("../../truthy");
|
|
5
5
|
const traversal_1 = require("./traversal");
|
|
6
|
-
const getTracksFromTransportStream = (
|
|
6
|
+
const getTracksFromTransportStream = (parserState) => {
|
|
7
|
+
const structure = parserState.structure.getStructure();
|
|
7
8
|
const programMapTable = (0, traversal_1.findProgramMapTableOrThrow)(structure);
|
|
8
9
|
const parserTracks = parserState.callbacks.tracks.getTracks();
|
|
9
10
|
const mapped = programMapTable.streams
|
|
@@ -21,9 +22,9 @@ const getTracksFromTransportStream = (structure, parserState) => {
|
|
|
21
22
|
};
|
|
22
23
|
};
|
|
23
24
|
exports.getTracksFromTransportStream = getTracksFromTransportStream;
|
|
24
|
-
const hasAllTracksFromTransportStream = (
|
|
25
|
+
const hasAllTracksFromTransportStream = (parserState) => {
|
|
25
26
|
try {
|
|
26
|
-
(0, exports.getTracksFromTransportStream)(
|
|
27
|
+
(0, exports.getTracksFromTransportStream)(parserState);
|
|
27
28
|
return true;
|
|
28
29
|
}
|
|
29
30
|
catch (_a) {
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { TransportStreamStructure } from '../../parse-result';
|
|
3
2
|
import type { ParserState } from '../../state/parser-state';
|
|
4
3
|
import type { TransportStreamBox } from './boxes';
|
|
5
|
-
|
|
6
|
-
import { type StreamBufferMap } from './process-stream-buffers';
|
|
7
|
-
export declare const parsePacket: ({ iterator, structure, streamBuffers, parserState, nextPesHeaderStore, }: {
|
|
4
|
+
export declare const parsePacket: ({ iterator, parserState, }: {
|
|
8
5
|
iterator: BufferIterator;
|
|
9
|
-
structure: TransportStreamStructure;
|
|
10
|
-
streamBuffers: StreamBufferMap;
|
|
11
6
|
parserState: ParserState;
|
|
12
|
-
nextPesHeaderStore: NextPesHeaderStore;
|
|
13
7
|
}) => Promise<TransportStreamBox | null>;
|
|
@@ -6,7 +6,7 @@ const parse_pes_1 = require("./parse-pes");
|
|
|
6
6
|
const parse_pmt_1 = require("./parse-pmt");
|
|
7
7
|
const parse_stream_packet_1 = require("./parse-stream-packet");
|
|
8
8
|
const traversal_1 = require("./traversal");
|
|
9
|
-
const parsePacket = async ({ iterator,
|
|
9
|
+
const parsePacket = async ({ iterator, parserState, }) => {
|
|
10
10
|
const offset = iterator.counter.getOffset();
|
|
11
11
|
const syncByte = iterator.getUint8();
|
|
12
12
|
if (syncByte !== 0x47) {
|
|
@@ -45,11 +45,12 @@ const parsePacket = async ({ iterator, structure, streamBuffers, parserState, ne
|
|
|
45
45
|
if (read === 188) {
|
|
46
46
|
return Promise.resolve(null);
|
|
47
47
|
}
|
|
48
|
+
const structure = parserState.structure.getStructure();
|
|
48
49
|
const pat = structure.boxes.find((b) => b.type === 'transport-stream-pmt-box');
|
|
49
50
|
const isPes = payloadUnitStartIndicator && (pat === null || pat === void 0 ? void 0 : pat.streams.find((e) => e.pid === programId));
|
|
50
51
|
if (isPes) {
|
|
51
52
|
const packetPes = (0, parse_pes_1.parsePes)(iterator);
|
|
52
|
-
nextPesHeaderStore.setNextPesHeader(packetPes);
|
|
53
|
+
parserState.transportStream.nextPesHeaderStore.setNextPesHeader(packetPes);
|
|
53
54
|
}
|
|
54
55
|
else if (payloadUnitStartIndicator === 1) {
|
|
55
56
|
iterator.getUint8(); // pointerField
|
|
@@ -67,8 +68,6 @@ const parsePacket = async ({ iterator, structure, streamBuffers, parserState, ne
|
|
|
67
68
|
await (0, parse_stream_packet_1.parseStream)({
|
|
68
69
|
iterator,
|
|
69
70
|
transportStreamEntry: stream,
|
|
70
|
-
streamBuffers,
|
|
71
|
-
nextPesHeader: nextPesHeaderStore.getNextPesHeader(),
|
|
72
71
|
state: parserState,
|
|
73
72
|
programId,
|
|
74
73
|
structure,
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { TransportStreamStructure } from '../../parse-result';
|
|
3
3
|
import type { ParserState } from '../../state/parser-state';
|
|
4
|
-
import type { PacketPes } from './parse-pes';
|
|
5
4
|
import type { TransportStreamEntry } from './parse-pmt';
|
|
6
|
-
|
|
7
|
-
export declare const parseStream: ({ iterator, transportStreamEntry, streamBuffers, state, programId, structure, nextPesHeader, }: {
|
|
5
|
+
export declare const parseStream: ({ iterator, transportStreamEntry, state, programId, structure, }: {
|
|
8
6
|
iterator: BufferIterator;
|
|
9
7
|
transportStreamEntry: TransportStreamEntry;
|
|
10
|
-
streamBuffers: StreamBufferMap;
|
|
11
8
|
state: ParserState;
|
|
12
9
|
programId: number;
|
|
13
10
|
structure: TransportStreamStructure;
|
|
14
|
-
nextPesHeader: PacketPes;
|
|
15
11
|
}) => Promise<void>;
|
|
@@ -6,13 +6,14 @@ const adts_header_1 = require("./adts-header");
|
|
|
6
6
|
const discard_rest_of_packet_1 = require("./discard-rest-of-packet");
|
|
7
7
|
const find_separator_1 = require("./find-separator");
|
|
8
8
|
const process_stream_buffers_1 = require("./process-stream-buffers");
|
|
9
|
-
const parseAdtsStream = async ({ restOfPacket, transportStreamEntry,
|
|
9
|
+
const parseAdtsStream = async ({ restOfPacket, transportStreamEntry, state, structure, offset, }) => {
|
|
10
10
|
var _a, _b;
|
|
11
|
+
const { streamBuffers, nextPesHeaderStore: nextPesHeader } = state.transportStream;
|
|
11
12
|
const streamBuffer = streamBuffers.get(transportStreamEntry.pid);
|
|
12
13
|
if (!streamBuffer) {
|
|
13
14
|
streamBuffers.set(transportStreamEntry.pid, {
|
|
14
15
|
buffer: restOfPacket,
|
|
15
|
-
pesHeader: nextPesHeader,
|
|
16
|
+
pesHeader: nextPesHeader.getNextPesHeader(),
|
|
16
17
|
offset,
|
|
17
18
|
});
|
|
18
19
|
return;
|
|
@@ -35,13 +36,14 @@ const parseAdtsStream = async ({ restOfPacket, transportStreamEntry, streamBuffe
|
|
|
35
36
|
const rest = restOfPacket.slice(bytesToTake);
|
|
36
37
|
streamBuffers.set(transportStreamEntry.pid, {
|
|
37
38
|
buffer: rest,
|
|
38
|
-
pesHeader: nextPesHeader,
|
|
39
|
+
pesHeader: nextPesHeader.getNextPesHeader(),
|
|
39
40
|
offset,
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
|
-
const parseAvcStream = async ({ restOfPacket, transportStreamEntry,
|
|
44
|
+
const parseAvcStream = async ({ restOfPacket, transportStreamEntry, programId, state, structure, offset, }) => {
|
|
44
45
|
const indexOfSeparator = (0, find_separator_1.findNextSeparator)(restOfPacket, transportStreamEntry);
|
|
46
|
+
const { streamBuffers, nextPesHeaderStore: nextPesHeader } = state.transportStream;
|
|
45
47
|
const streamBuffer = streamBuffers.get(transportStreamEntry.pid);
|
|
46
48
|
if (indexOfSeparator === -1) {
|
|
47
49
|
if (streamBuffer) {
|
|
@@ -52,7 +54,7 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
56
|
streamBuffers.set(programId, {
|
|
55
|
-
pesHeader: nextPesHeader,
|
|
57
|
+
pesHeader: nextPesHeader.getNextPesHeader(),
|
|
56
58
|
buffer: restOfPacket,
|
|
57
59
|
offset,
|
|
58
60
|
});
|
|
@@ -69,7 +71,7 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
69
71
|
});
|
|
70
72
|
const rest = restOfPacket.slice(indexOfSeparator);
|
|
71
73
|
streamBuffers.set(programId, {
|
|
72
|
-
pesHeader: nextPesHeader,
|
|
74
|
+
pesHeader: nextPesHeader.getNextPesHeader(),
|
|
73
75
|
buffer: rest,
|
|
74
76
|
offset,
|
|
75
77
|
});
|
|
@@ -79,19 +81,17 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
79
81
|
throw new Error('No stream buffer found but new separator is not at the beginning');
|
|
80
82
|
}
|
|
81
83
|
streamBuffers.set(programId, {
|
|
82
|
-
pesHeader: nextPesHeader,
|
|
84
|
+
pesHeader: nextPesHeader.getNextPesHeader(),
|
|
83
85
|
buffer: restOfPacket.slice(indexOfSeparator),
|
|
84
86
|
offset,
|
|
85
87
|
});
|
|
86
88
|
};
|
|
87
|
-
const parseStream = ({ iterator, transportStreamEntry,
|
|
89
|
+
const parseStream = ({ iterator, transportStreamEntry, state, programId, structure, }) => {
|
|
88
90
|
const restOfPacket = (0, discard_rest_of_packet_1.getRestOfPacket)(iterator);
|
|
89
91
|
if (transportStreamEntry.streamType === 27) {
|
|
90
92
|
return parseAvcStream({
|
|
91
93
|
restOfPacket,
|
|
92
94
|
transportStreamEntry,
|
|
93
|
-
streamBuffers,
|
|
94
|
-
nextPesHeader,
|
|
95
95
|
state,
|
|
96
96
|
programId,
|
|
97
97
|
structure,
|
|
@@ -102,8 +102,6 @@ const parseStream = ({ iterator, transportStreamEntry, streamBuffers, state, pro
|
|
|
102
102
|
return parseAdtsStream({
|
|
103
103
|
restOfPacket,
|
|
104
104
|
transportStreamEntry,
|
|
105
|
-
streamBuffers,
|
|
106
|
-
nextPesHeader,
|
|
107
105
|
state,
|
|
108
106
|
structure,
|
|
109
107
|
offset: iterator.counter.getOffset(),
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../options';
|
|
3
2
|
import type { ParseResult } from '../../parse-result';
|
|
4
3
|
import type { ParserState } from '../../state/parser-state';
|
|
5
|
-
|
|
6
|
-
import { type StreamBufferMap } from './process-stream-buffers';
|
|
7
|
-
export declare const parseTransportStream: ({ iterator, state, streamBuffers, fields, nextPesHeaderStore, }: {
|
|
4
|
+
export declare const parseTransportStream: ({ iterator, state, }: {
|
|
8
5
|
iterator: BufferIterator;
|
|
9
6
|
state: ParserState;
|
|
10
|
-
streamBuffers: StreamBufferMap;
|
|
11
|
-
fields: Options<ParseMediaFields>;
|
|
12
|
-
nextPesHeaderStore: NextPesHeaderStore;
|
|
13
7
|
}) => Promise<ParseResult>;
|
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTransportStream = void 0;
|
|
4
|
-
const has_all_info_1 = require("../../has-all-info");
|
|
5
4
|
const parse_packet_1 = require("./parse-packet");
|
|
6
5
|
const process_stream_buffers_1 = require("./process-stream-buffers");
|
|
7
|
-
const parseTransportStream = async ({ iterator, state,
|
|
6
|
+
const parseTransportStream = async ({ iterator, state, }) => {
|
|
8
7
|
const structure = state.structure.getStructure();
|
|
9
8
|
if (structure.type !== 'transport-stream') {
|
|
10
9
|
throw new Error('Invalid structure type');
|
|
11
10
|
}
|
|
12
|
-
if (iterator.bytesRemaining() === 0) {
|
|
13
|
-
await (0, process_stream_buffers_1.processFinalStreamBuffers)({
|
|
14
|
-
streamBufferMap: streamBuffers,
|
|
15
|
-
state,
|
|
16
|
-
structure,
|
|
17
|
-
});
|
|
18
|
-
return Promise.resolve({
|
|
19
|
-
status: 'done',
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
11
|
const continueParsing = () => {
|
|
23
12
|
return (0, exports.parseTransportStream)({
|
|
24
13
|
iterator,
|
|
25
14
|
state,
|
|
26
|
-
streamBuffers,
|
|
27
|
-
fields,
|
|
28
|
-
nextPesHeaderStore,
|
|
29
15
|
});
|
|
30
16
|
};
|
|
31
|
-
if ((0, has_all_info_1.hasAllInfo)({
|
|
32
|
-
fields,
|
|
33
|
-
state,
|
|
34
|
-
})) {
|
|
35
|
-
return Promise.resolve({
|
|
36
|
-
status: 'done',
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
17
|
if (iterator.bytesRemaining() < 188) {
|
|
40
18
|
return Promise.resolve({
|
|
41
19
|
status: 'incomplete',
|
|
@@ -45,14 +23,17 @@ const parseTransportStream = async ({ iterator, state, streamBuffers, fields, ne
|
|
|
45
23
|
}
|
|
46
24
|
const packet = await (0, parse_packet_1.parsePacket)({
|
|
47
25
|
iterator,
|
|
48
|
-
structure,
|
|
49
|
-
streamBuffers,
|
|
50
26
|
parserState: state,
|
|
51
|
-
nextPesHeaderStore,
|
|
52
27
|
});
|
|
53
28
|
if (packet) {
|
|
54
29
|
structure.boxes.push(packet);
|
|
55
30
|
}
|
|
31
|
+
if (iterator.bytesRemaining() === 0) {
|
|
32
|
+
await (0, process_stream_buffers_1.processFinalStreamBuffers)({
|
|
33
|
+
state,
|
|
34
|
+
structure,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
56
37
|
return Promise.resolve({
|
|
57
38
|
status: 'incomplete',
|
|
58
39
|
continueParsing,
|
|
@@ -13,8 +13,7 @@ export declare const processStreamBuffer: ({ streamBuffer, state, programId, str
|
|
|
13
13
|
programId: number;
|
|
14
14
|
structure: TransportStreamStructure;
|
|
15
15
|
}) => Promise<void>;
|
|
16
|
-
export declare const processFinalStreamBuffers: ({
|
|
17
|
-
streamBufferMap: StreamBufferMap;
|
|
16
|
+
export declare const processFinalStreamBuffers: ({ state, structure, }: {
|
|
18
17
|
state: ParserState;
|
|
19
18
|
structure: TransportStreamStructure;
|
|
20
19
|
}) => Promise<void>;
|
|
@@ -36,8 +36,8 @@ const processStreamBuffer = async ({ streamBuffer, state, programId, structure,
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
exports.processStreamBuffer = processStreamBuffer;
|
|
39
|
-
const processFinalStreamBuffers = async ({
|
|
40
|
-
for (const [programId, buffer] of
|
|
39
|
+
const processFinalStreamBuffers = async ({ state, structure, }) => {
|
|
40
|
+
for (const [programId, buffer] of state.transportStream.streamBuffers) {
|
|
41
41
|
if (buffer.buffer.byteLength > 0) {
|
|
42
42
|
await (0, exports.processStreamBuffer)({
|
|
43
43
|
streamBuffer: buffer,
|
|
@@ -45,7 +45,7 @@ const processFinalStreamBuffers = async ({ streamBufferMap, state, structure, })
|
|
|
45
45
|
programId,
|
|
46
46
|
structure,
|
|
47
47
|
});
|
|
48
|
-
|
|
48
|
+
state.transportStream.streamBuffers.delete(programId);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
};
|
|
@@ -109,6 +109,9 @@ const postprocessEbml = async ({ offset, ebml, state, }) => {
|
|
|
109
109
|
if (ebml.type === 'TimestampScale') {
|
|
110
110
|
state.webm.setTimescale(ebml.value.value);
|
|
111
111
|
}
|
|
112
|
+
if (ebml.type === 'Tracks') {
|
|
113
|
+
state.callbacks.tracks.setIsDone();
|
|
114
|
+
}
|
|
112
115
|
if (ebml.type === 'TrackEntry') {
|
|
113
116
|
state.webm.onTrackEntrySegment(ebml);
|
|
114
117
|
const track = (0, make_track_1.getTrack)({
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../options';
|
|
3
2
|
import type { ParseResult } from '../../parse-result';
|
|
4
3
|
import type { ParserState } from '../../state/parser-state';
|
|
5
|
-
export declare const parseWebm: ({
|
|
6
|
-
|
|
4
|
+
export declare const parseWebm: ({ iterator, state, }: {
|
|
5
|
+
iterator: BufferIterator;
|
|
7
6
|
state: ParserState;
|
|
8
|
-
fields: Options<ParseMediaFields>;
|
|
9
7
|
}) => Promise<ParseResult>;
|
|
@@ -1,37 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseWebm = void 0;
|
|
4
|
-
const
|
|
5
|
-
const continueAfterMatroskaResult = (result, structure) => {
|
|
6
|
-
if (result.status === 'done') {
|
|
7
|
-
return {
|
|
8
|
-
status: 'done',
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
status: 'incomplete',
|
|
13
|
-
continueParsing: async () => {
|
|
14
|
-
const newResult = await result.continueParsing();
|
|
15
|
-
return continueAfterMatroskaResult(newResult, structure);
|
|
16
|
-
},
|
|
17
|
-
skipTo: null,
|
|
18
|
-
};
|
|
19
|
-
};
|
|
4
|
+
const segments_1 = require("./segments");
|
|
20
5
|
// Parsing according to https://darkcoding.net/software/reading-mediarecorders-webm-opus-output/
|
|
21
|
-
const parseWebm = async ({
|
|
6
|
+
const parseWebm = async ({ iterator, state, }) => {
|
|
22
7
|
const structure = state.structure.getStructure();
|
|
23
8
|
if (structure.type !== 'matroska') {
|
|
24
9
|
throw new Error('Invalid structure type');
|
|
25
10
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
const isInsideSegment = state.webm.isInsideSegment(iterator);
|
|
12
|
+
const isInsideCluster = state.webm.isInsideCluster(iterator);
|
|
13
|
+
const results = await (0, segments_1.expectSegment)({
|
|
14
|
+
iterator,
|
|
30
15
|
state,
|
|
31
|
-
|
|
32
|
-
fields,
|
|
33
|
-
topLevelStructure: structure,
|
|
16
|
+
isInsideSegment,
|
|
34
17
|
});
|
|
35
|
-
|
|
18
|
+
if (results === null) {
|
|
19
|
+
return {
|
|
20
|
+
skipTo: null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (isInsideCluster) {
|
|
24
|
+
const segments = structure.boxes.filter((box) => box.type === 'Segment');
|
|
25
|
+
const segment = segments[isInsideCluster.segment];
|
|
26
|
+
if (!segment) {
|
|
27
|
+
throw new Error('Expected segment');
|
|
28
|
+
}
|
|
29
|
+
const clusters = segment.value.find((box) => box.type === 'Cluster');
|
|
30
|
+
if (!clusters) {
|
|
31
|
+
throw new Error('Expected cluster');
|
|
32
|
+
}
|
|
33
|
+
// let's not add it to the cluster
|
|
34
|
+
if (results.type !== 'Block' && results.type !== 'SimpleBlock') {
|
|
35
|
+
clusters.value.push(results);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (isInsideSegment) {
|
|
39
|
+
const segments = structure.boxes.filter((box) => box.type === 'Segment');
|
|
40
|
+
const segment = segments[isInsideSegment.index];
|
|
41
|
+
if (!segment) {
|
|
42
|
+
throw new Error('Expected segment');
|
|
43
|
+
}
|
|
44
|
+
segment.value.push(results);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
structure.boxes.push(results);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
skipTo: null,
|
|
51
|
+
};
|
|
36
52
|
};
|
|
37
53
|
exports.parseWebm = parseWebm;
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../../options';
|
|
3
|
-
import type { ExpectSegmentParseResult, MatroskaParseResult, MatroskaStructure } from '../../../parse-result';
|
|
4
2
|
import type { ParserState } from '../../../state/parser-state';
|
|
5
|
-
import type { MatroskaSegment } from '../segments';
|
|
6
3
|
import type { PossibleEbml } from './all-segments';
|
|
7
|
-
export declare const
|
|
8
|
-
iterator: BufferIterator;
|
|
9
|
-
state: ParserState;
|
|
10
|
-
offset: number;
|
|
11
|
-
children: PossibleEbml[];
|
|
12
|
-
fields: Options<ParseMediaFields>;
|
|
13
|
-
topLevelStructure: MatroskaStructure;
|
|
14
|
-
}) => Promise<ExpectSegmentParseResult>;
|
|
15
|
-
export declare const expectChildren: ({ iterator, length, children, state, startOffset, fields, topLevelStructure, }: {
|
|
4
|
+
export declare const expectChildren: ({ iterator, length, state, startOffset, }: {
|
|
16
5
|
iterator: BufferIterator;
|
|
17
6
|
length: number;
|
|
18
|
-
children: MatroskaSegment[];
|
|
19
7
|
state: ParserState;
|
|
20
8
|
startOffset: number;
|
|
21
|
-
|
|
22
|
-
topLevelStructure: MatroskaStructure;
|
|
23
|
-
}) => Promise<MatroskaParseResult>;
|
|
9
|
+
}) => Promise<PossibleEbml[]>;
|
|
@@ -1,144 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expectChildren =
|
|
4
|
-
const has_all_info_1 = require("../../../has-all-info");
|
|
3
|
+
exports.expectChildren = void 0;
|
|
5
4
|
const segments_1 = require("../segments");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
children.push(parseResult.segment);
|
|
9
|
-
if ((0, has_all_info_1.hasAllInfo)({ fields, state })) {
|
|
10
|
-
return {
|
|
11
|
-
status: 'done',
|
|
12
|
-
segment: parseResult.segment,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
if (parseResult.segment.type === 'Tracks') {
|
|
16
|
-
state.callbacks.tracks.setIsDone();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (parseResult.status === 'incomplete') {
|
|
20
|
-
// No need to decrement because expectSegment already does it
|
|
21
|
-
return {
|
|
22
|
-
status: 'incomplete',
|
|
23
|
-
segment: parseResult.segment,
|
|
24
|
-
continueParsing: async () => {
|
|
25
|
-
const newParseResult = await parseResult.continueParsing();
|
|
26
|
-
return processParseResult({
|
|
27
|
-
children,
|
|
28
|
-
parseResult: newParseResult,
|
|
29
|
-
state,
|
|
30
|
-
fields,
|
|
31
|
-
topLevelStructure,
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
status: 'done',
|
|
38
|
-
segment: parseResult.segment,
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
const expectAndProcessSegment = async ({ iterator, state, offset, children, fields, topLevelStructure, }) => {
|
|
42
|
-
const segment = await (0, segments_1.expectSegment)({
|
|
43
|
-
iterator,
|
|
44
|
-
state,
|
|
45
|
-
offset,
|
|
46
|
-
children,
|
|
47
|
-
fields,
|
|
48
|
-
topLevelStructure,
|
|
49
|
-
});
|
|
50
|
-
return processParseResult({
|
|
51
|
-
children,
|
|
52
|
-
parseResult: segment,
|
|
53
|
-
state,
|
|
54
|
-
fields,
|
|
55
|
-
topLevelStructure,
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
exports.expectAndProcessSegment = expectAndProcessSegment;
|
|
59
|
-
const continueAfterSegmentResult = async ({ result, length, children, state, iterator, startOffset, fields, topLevelStructure, }) => {
|
|
60
|
-
if (result.status === 'done') {
|
|
61
|
-
throw new Error('Should not continue after done');
|
|
62
|
-
}
|
|
63
|
-
const segmentResult = await result.continueParsing();
|
|
64
|
-
if (segmentResult.status === 'done') {
|
|
65
|
-
return {
|
|
66
|
-
status: 'incomplete',
|
|
67
|
-
continueParsing: () => {
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
69
|
-
return (0, exports.expectChildren)({
|
|
70
|
-
children,
|
|
71
|
-
iterator,
|
|
72
|
-
length,
|
|
73
|
-
state,
|
|
74
|
-
startOffset,
|
|
75
|
-
fields,
|
|
76
|
-
topLevelStructure,
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
skipTo: null,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
status: 'incomplete',
|
|
84
|
-
continueParsing: () => {
|
|
85
|
-
return continueAfterSegmentResult({
|
|
86
|
-
result: segmentResult,
|
|
87
|
-
children,
|
|
88
|
-
iterator,
|
|
89
|
-
length,
|
|
90
|
-
state,
|
|
91
|
-
startOffset,
|
|
92
|
-
fields,
|
|
93
|
-
topLevelStructure,
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
skipTo: null,
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
const expectChildren = async ({ iterator, length, children, state, startOffset, fields, topLevelStructure, }) => {
|
|
5
|
+
const expectChildren = async ({ iterator, length, state, startOffset, }) => {
|
|
6
|
+
const children = [];
|
|
100
7
|
while (iterator.counter.getOffset() < startOffset + length) {
|
|
101
8
|
if (iterator.bytesRemaining() === 0) {
|
|
102
9
|
break;
|
|
103
10
|
}
|
|
104
|
-
const
|
|
105
|
-
const child = await (0, exports.expectAndProcessSegment)({
|
|
11
|
+
const child = await (0, segments_1.expectSegment)({
|
|
106
12
|
iterator,
|
|
107
13
|
state,
|
|
108
|
-
offset: currentOffset,
|
|
109
|
-
children,
|
|
110
|
-
fields,
|
|
111
|
-
topLevelStructure,
|
|
112
14
|
});
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
state,
|
|
116
|
-
})) {
|
|
117
|
-
return {
|
|
118
|
-
status: 'done',
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
if (child.status === 'incomplete') {
|
|
122
|
-
return {
|
|
123
|
-
status: 'incomplete',
|
|
124
|
-
continueParsing: () => {
|
|
125
|
-
return continueAfterSegmentResult({
|
|
126
|
-
result: child,
|
|
127
|
-
children,
|
|
128
|
-
iterator,
|
|
129
|
-
length: length - (currentOffset - startOffset),
|
|
130
|
-
state,
|
|
131
|
-
startOffset: currentOffset,
|
|
132
|
-
fields,
|
|
133
|
-
topLevelStructure,
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
skipTo: null,
|
|
137
|
-
};
|
|
15
|
+
if (child) {
|
|
16
|
+
children.push(child);
|
|
138
17
|
}
|
|
139
18
|
}
|
|
140
|
-
return
|
|
141
|
-
status: 'done',
|
|
142
|
-
};
|
|
19
|
+
return children;
|
|
143
20
|
};
|
|
144
21
|
exports.expectChildren = expectChildren;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../options';
|
|
3
|
-
import type { ExpectSegmentParseResult, MatroskaStructure } from '../../parse-result';
|
|
4
2
|
import type { ParserState } from '../../state/parser-state';
|
|
3
|
+
import type { SegmentSection } from '../../state/webm';
|
|
5
4
|
import { type PossibleEbml, type TrackEntry } from './segments/all-segments';
|
|
6
5
|
export type MatroskaSegment = PossibleEbml;
|
|
7
6
|
export type OnTrackEntrySegment = (trackEntry: TrackEntry) => void;
|
|
8
|
-
export declare const expectSegment: ({ iterator, state,
|
|
7
|
+
export declare const expectSegment: ({ iterator, state, isInsideSegment, }: {
|
|
9
8
|
iterator: BufferIterator;
|
|
10
9
|
state: ParserState;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fields: Options<ParseMediaFields>;
|
|
14
|
-
topLevelStructure: MatroskaStructure;
|
|
15
|
-
}) => Promise<ExpectSegmentParseResult>;
|
|
10
|
+
isInsideSegment: SegmentSection | null;
|
|
11
|
+
}) => Promise<MatroskaSegment | null>;
|