@remotion/media-parser 4.0.241 → 4.0.243
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.js +2 -2
- package/dist/boxes/avc/codec-private.js +2 -2
- package/dist/boxes/avc/create-sps-pps-data.d.ts +2 -0
- package/dist/boxes/avc/create-sps-pps-data.js +28 -0
- package/dist/boxes/iso-base-media/get-keyframes.d.ts +3 -0
- package/dist/boxes/iso-base-media/get-keyframes.js +30 -0
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -3
- package/dist/boxes/iso-base-media/mdat/mdat.js +9 -5
- package/dist/boxes/iso-base-media/moov/moov.d.ts +3 -3
- package/dist/boxes/iso-base-media/moov/moov.js +5 -4
- package/dist/boxes/iso-base-media/process-box.d.ts +9 -9
- package/dist/boxes/iso-base-media/process-box.js +48 -56
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +3 -3
- package/dist/boxes/iso-base-media/stsd/mebx.js +5 -4
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +5 -5
- package/dist/boxes/iso-base-media/stsd/samples.js +19 -16
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +3 -3
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -2
- package/dist/boxes/iso-base-media/trak/trak.d.ts +3 -3
- package/dist/boxes/iso-base-media/trak/trak.js +7 -6
- package/dist/boxes/riff/expect-riff-box.d.ts +3 -3
- package/dist/boxes/riff/expect-riff-box.js +5 -5
- package/dist/boxes/riff/get-tracks-from-avi.js +1 -1
- package/dist/boxes/riff/parse-box.d.ts +7 -7
- package/dist/boxes/riff/parse-box.js +29 -24
- package/dist/boxes/riff/parse-list-box.d.ts +3 -3
- package/dist/boxes/riff/parse-list-box.js +2 -2
- package/dist/boxes/riff/parse-movi.d.ts +5 -5
- package/dist/boxes/riff/parse-movi.js +35 -20
- package/dist/boxes/riff/parse-riff-box.d.ts +3 -3
- package/dist/boxes/riff/parse-riff-box.js +2 -2
- package/dist/boxes/transport-stream/get-tracks.js +1 -1
- package/dist/boxes/transport-stream/handle-aac-packet.d.ts +4 -3
- package/dist/boxes/transport-stream/handle-aac-packet.js +6 -4
- package/dist/boxes/transport-stream/handle-avc-packet.d.ts +4 -3
- package/dist/boxes/transport-stream/handle-avc-packet.js +8 -6
- package/dist/boxes/transport-stream/parse-packet.d.ts +3 -3
- package/dist/boxes/transport-stream/parse-packet.js +2 -2
- package/dist/boxes/transport-stream/parse-stream-packet.d.ts +3 -3
- package/dist/boxes/transport-stream/parse-stream-packet.js +14 -7
- package/dist/boxes/transport-stream/parse-transport-stream.d.ts +5 -6
- package/dist/boxes/transport-stream/parse-transport-stream.js +10 -9
- package/dist/boxes/transport-stream/process-stream-buffers.d.ts +6 -5
- package/dist/boxes/transport-stream/process-stream-buffers.js +18 -8
- package/dist/boxes/webm/ebml.d.ts +1 -1
- package/dist/boxes/webm/get-sample-from-block.d.ts +2 -2
- package/dist/boxes/webm/get-sample-from-block.js +8 -4
- package/dist/boxes/webm/parse-ebml.d.ts +4 -4
- package/dist/boxes/webm/parse-ebml.js +18 -18
- package/dist/boxes/webm/parse-webm-header.d.ts +5 -5
- package/dist/boxes/webm/parse-webm-header.js +6 -5
- package/dist/boxes/webm/segments/parse-children.d.ts +5 -5
- package/dist/boxes/webm/segments/parse-children.js +12 -13
- package/dist/boxes/webm/segments.d.ts +3 -3
- package/dist/boxes/webm/segments.js +13 -13
- package/dist/convert-audio-or-video-sample.js +5 -2
- package/dist/create/matroska/create-matroska-media.js +2 -0
- package/dist/create/progress-tracker.js +2 -2
- package/dist/emit-available-info.d.ts +4 -5
- package/dist/emit-available-info.js +171 -57
- package/dist/esm/index.mjs +899 -501
- package/dist/file-types/detect-file-type.js +4 -2
- package/dist/get-duration.d.ts +1 -0
- package/dist/get-duration.js +14 -1
- package/dist/get-fields-from-callbacks.js +5 -0
- package/dist/get-fps.d.ts +1 -0
- package/dist/get-fps.js +17 -12
- package/dist/get-keyframes.d.ts +5 -0
- package/dist/get-keyframes.js +20 -0
- package/dist/get-tracks.d.ts +7 -1
- package/dist/get-tracks.js +15 -10
- package/dist/has-all-info.d.ts +2 -5
- package/dist/has-all-info.js +23 -4
- package/dist/index.d.ts +2 -1
- package/dist/may-skip-video-data/may-skip-video-data.d.ts +4 -0
- package/dist/may-skip-video-data/may-skip-video-data.js +14 -0
- package/dist/may-skip-video-data/need-samples-for-fields.d.ts +5 -0
- package/dist/may-skip-video-data/need-samples-for-fields.js +33 -0
- package/dist/options.d.ts +32 -0
- package/dist/parse-media.js +12 -40
- package/dist/parse-result.d.ts +2 -4
- package/dist/parse-video.d.ts +5 -5
- package/dist/parse-video.js +24 -10
- package/dist/register-track.d.ts +5 -5
- package/dist/register-track.js +12 -12
- package/dist/state/can-skip-tracks.js +5 -0
- package/dist/state/emitted-fields.d.ts +2 -0
- package/dist/state/emitted-fields.js +31 -0
- package/dist/state/has-tracks-section.d.ts +1 -0
- package/dist/state/keyframes.d.ts +6 -0
- package/dist/state/keyframes.js +15 -0
- package/dist/state/parser-state.d.ts +60 -29
- package/dist/state/parser-state.js +32 -150
- package/dist/state/riff.d.ts +10 -0
- package/dist/state/riff.js +32 -0
- package/dist/state/sample-callbacks.d.ts +31 -0
- package/dist/state/sample-callbacks.js +101 -0
- package/dist/state/slow-duration-fps.d.ts +8 -0
- package/dist/state/slow-duration-fps.js +36 -0
- package/dist/state/structure.d.ts +7 -0
- package/dist/state/structure.js +21 -0
- package/dist/state/tracks-and-samples.d.ts +0 -0
- package/dist/state/tracks-and-samples.js +1 -0
- package/dist/state/webm.d.ts +11 -0
- package/dist/state/webm.js +67 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webcodec-sample-types.d.ts +2 -0
- package/package.json +3 -3
package/dist/parse-video.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { BufferIterator } from './buffer-iterator';
|
|
2
2
|
import { type LogLevel } from './log';
|
|
3
3
|
import type { Options, ParseMediaFields } from './options';
|
|
4
|
-
import type { IsoBaseMediaBox, ParseResult
|
|
5
|
-
import type {
|
|
4
|
+
import type { IsoBaseMediaBox, ParseResult } from './parse-result';
|
|
5
|
+
import type { ParserState } from './state/parser-state';
|
|
6
6
|
export type PartialMdatBox = {
|
|
7
7
|
type: 'partial-mdat-box';
|
|
8
8
|
boxSize: number;
|
|
@@ -16,13 +16,13 @@ export type BoxAndNext = {
|
|
|
16
16
|
} | {
|
|
17
17
|
type: 'incomplete';
|
|
18
18
|
} | PartialMdatBox;
|
|
19
|
-
export declare const parseVideo: ({ iterator,
|
|
19
|
+
export declare const parseVideo: ({ iterator, state, signal, logLevel, fields, mimeType, contentLength, name, }: {
|
|
20
20
|
iterator: BufferIterator;
|
|
21
|
-
|
|
21
|
+
state: ParserState;
|
|
22
22
|
signal: AbortSignal | null;
|
|
23
23
|
logLevel: LogLevel;
|
|
24
24
|
fields: Options<ParseMediaFields>;
|
|
25
25
|
mimeType: string | null;
|
|
26
26
|
contentLength: number | null;
|
|
27
27
|
name: string | null;
|
|
28
|
-
}) => Promise<ParseResult
|
|
28
|
+
}) => Promise<ParseResult>;
|
package/dist/parse-video.js
CHANGED
|
@@ -8,23 +8,32 @@ const parse_transport_stream_1 = require("./boxes/transport-stream/parse-transpo
|
|
|
8
8
|
const parse_webm_header_1 = require("./boxes/webm/parse-webm-header");
|
|
9
9
|
const errors_1 = require("./errors");
|
|
10
10
|
const log_1 = require("./log");
|
|
11
|
-
const parseVideo = ({ iterator,
|
|
11
|
+
const parseVideo = ({ iterator, state, signal, logLevel, fields, mimeType, contentLength, name, }) => {
|
|
12
12
|
if (iterator.bytesRemaining() === 0) {
|
|
13
13
|
return Promise.reject(new Error('no bytes'));
|
|
14
14
|
}
|
|
15
15
|
const fileType = iterator.detectFileType();
|
|
16
16
|
if (fileType.type === 'riff') {
|
|
17
17
|
log_1.Log.verbose(logLevel, 'Detected RIFF container');
|
|
18
|
-
|
|
18
|
+
state.structure.setStructure({
|
|
19
|
+
type: 'riff',
|
|
20
|
+
boxes: [],
|
|
21
|
+
});
|
|
22
|
+
return Promise.resolve((0, parse_box_1.parseRiff)({ iterator, state, fields }));
|
|
19
23
|
}
|
|
20
24
|
if (fileType.type === 'iso-base-media') {
|
|
21
25
|
log_1.Log.verbose(logLevel, 'Detected ISO Base Media container');
|
|
26
|
+
const initialBoxes = [];
|
|
27
|
+
state.structure.setStructure({
|
|
28
|
+
type: 'iso-base-media',
|
|
29
|
+
boxes: initialBoxes,
|
|
30
|
+
});
|
|
22
31
|
return (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
23
32
|
iterator,
|
|
24
33
|
maxBytes: Infinity,
|
|
25
34
|
allowIncompleteBoxes: true,
|
|
26
|
-
initialBoxes
|
|
27
|
-
|
|
35
|
+
initialBoxes,
|
|
36
|
+
state,
|
|
28
37
|
continueMdat: false,
|
|
29
38
|
signal,
|
|
30
39
|
logLevel,
|
|
@@ -33,16 +42,21 @@ const parseVideo = ({ iterator, options, signal, logLevel, fields, mimeType, con
|
|
|
33
42
|
}
|
|
34
43
|
if (fileType.type === 'webm') {
|
|
35
44
|
log_1.Log.verbose(logLevel, 'Detected Matroska container');
|
|
36
|
-
|
|
45
|
+
state.structure.setStructure({
|
|
46
|
+
boxes: [],
|
|
47
|
+
type: 'matroska',
|
|
48
|
+
});
|
|
49
|
+
return (0, parse_webm_header_1.parseWebm)({ counter: iterator, state, fields });
|
|
37
50
|
}
|
|
38
51
|
if (fileType.type === 'transport-stream') {
|
|
52
|
+
log_1.Log.verbose(logLevel, 'Detected MPEG-2 Transport Stream');
|
|
53
|
+
state.structure.setStructure({
|
|
54
|
+
boxes: [],
|
|
55
|
+
type: 'transport-stream',
|
|
56
|
+
});
|
|
39
57
|
return (0, parse_transport_stream_1.parseTransportStream)({
|
|
40
58
|
iterator,
|
|
41
|
-
|
|
42
|
-
structure: {
|
|
43
|
-
type: 'transport-stream',
|
|
44
|
-
boxes: [],
|
|
45
|
-
},
|
|
59
|
+
state,
|
|
46
60
|
streamBuffers: new Map(),
|
|
47
61
|
fields,
|
|
48
62
|
nextPesHeaderStore: (0, next_pes_header_store_1.makeNextPesHeaderStore)(),
|
package/dist/register-track.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Track, VideoTrack } from './get-tracks';
|
|
2
2
|
import type { ParseMediaContainer } from './options';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const registerTrack: ({
|
|
5
|
-
|
|
3
|
+
import type { ParserState } from './state/parser-state';
|
|
4
|
+
export declare const registerTrack: ({ state, track, container, }: {
|
|
5
|
+
state: ParserState;
|
|
6
6
|
track: Track;
|
|
7
7
|
container: ParseMediaContainer;
|
|
8
8
|
}) => Promise<void>;
|
|
9
|
-
export declare const registerVideoTrackWhenProfileIsAvailable: ({
|
|
10
|
-
|
|
9
|
+
export declare const registerVideoTrackWhenProfileIsAvailable: ({ state, track, container, }: {
|
|
10
|
+
state: ParserState;
|
|
11
11
|
track: VideoTrack;
|
|
12
12
|
container: ParseMediaContainer;
|
|
13
13
|
}) => void;
|
package/dist/register-track.js
CHANGED
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerVideoTrackWhenProfileIsAvailable = exports.registerTrack = void 0;
|
|
4
4
|
const add_avc_profile_to_track_1 = require("./add-avc-profile-to-track");
|
|
5
|
-
const registerTrack = async ({
|
|
5
|
+
const registerTrack = async ({ state, track, container, }) => {
|
|
6
6
|
if (track.type === 'video') {
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
const callback = await
|
|
10
|
-
await
|
|
7
|
+
state.callbacks.tracks.addTrack(track);
|
|
8
|
+
if (state.onVideoTrack) {
|
|
9
|
+
const callback = await state.onVideoTrack({ track, container });
|
|
10
|
+
await state.callbacks.registerVideoSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
if (track.type === 'audio') {
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
const callback = await
|
|
17
|
-
await
|
|
14
|
+
state.callbacks.tracks.addTrack(track);
|
|
15
|
+
if (state.onAudioTrack) {
|
|
16
|
+
const callback = await state.onAudioTrack({ track, container });
|
|
17
|
+
await state.callbacks.registerAudioSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
exports.registerTrack = registerTrack;
|
|
22
|
-
const registerVideoTrackWhenProfileIsAvailable = ({
|
|
23
|
-
|
|
22
|
+
const registerVideoTrackWhenProfileIsAvailable = ({ state, track, container, }) => {
|
|
23
|
+
state.riff.registerOnAvcProfileCallback(async (profile) => {
|
|
24
24
|
await (0, exports.registerTrack)({
|
|
25
|
-
|
|
25
|
+
state,
|
|
26
26
|
track: (0, add_avc_profile_to_track_1.addAvcProfileToTrack)(track, profile),
|
|
27
27
|
container,
|
|
28
28
|
});
|
|
@@ -6,6 +6,8 @@ const needsTracksField = {
|
|
|
6
6
|
container: false,
|
|
7
7
|
dimensions: true,
|
|
8
8
|
durationInSeconds: true,
|
|
9
|
+
slowDurationInSeconds: true,
|
|
10
|
+
slowFps: true,
|
|
9
11
|
fps: true,
|
|
10
12
|
internalStats: false,
|
|
11
13
|
isHdr: true,
|
|
@@ -19,6 +21,9 @@ const needsTracksField = {
|
|
|
19
21
|
metadata: true,
|
|
20
22
|
location: true,
|
|
21
23
|
mimeType: false,
|
|
24
|
+
slowKeyframes: true,
|
|
25
|
+
slowNumberOfFrames: true,
|
|
26
|
+
keyframes: true,
|
|
22
27
|
};
|
|
23
28
|
const makeCanSkipTracksState = ({ hasAudioTrackHandlers, fields, hasVideoTrackHandlers, }) => {
|
|
24
29
|
return {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emittedState = void 0;
|
|
4
|
+
const emittedState = () => {
|
|
5
|
+
const emittedFields = {
|
|
6
|
+
audioCodec: false,
|
|
7
|
+
container: false,
|
|
8
|
+
dimensions: false,
|
|
9
|
+
durationInSeconds: false,
|
|
10
|
+
fps: false,
|
|
11
|
+
internalStats: false,
|
|
12
|
+
isHdr: false,
|
|
13
|
+
location: false,
|
|
14
|
+
metadata: false,
|
|
15
|
+
mimeType: false,
|
|
16
|
+
name: false,
|
|
17
|
+
rotation: false,
|
|
18
|
+
size: false,
|
|
19
|
+
structure: false,
|
|
20
|
+
tracks: false,
|
|
21
|
+
videoCodec: false,
|
|
22
|
+
unrotatedDimensions: false,
|
|
23
|
+
slowDurationInSeconds: false,
|
|
24
|
+
slowFps: false,
|
|
25
|
+
slowKeyframes: false,
|
|
26
|
+
slowNumberOfFrames: false,
|
|
27
|
+
keyframes: false,
|
|
28
|
+
};
|
|
29
|
+
return emittedFields;
|
|
30
|
+
};
|
|
31
|
+
exports.emittedState = emittedState;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MediaParserKeyframe } from '../options';
|
|
2
|
+
export declare const keyframesState: () => {
|
|
3
|
+
addKeyframe: (keyframe: MediaParserKeyframe) => void;
|
|
4
|
+
getKeyframes: () => MediaParserKeyframe[];
|
|
5
|
+
};
|
|
6
|
+
export type KeyframesState = ReturnType<typeof keyframesState>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keyframesState = void 0;
|
|
4
|
+
const keyframesState = () => {
|
|
5
|
+
const keyframes = [];
|
|
6
|
+
return {
|
|
7
|
+
addKeyframe: (keyframe) => {
|
|
8
|
+
keyframes.push(keyframe);
|
|
9
|
+
},
|
|
10
|
+
getKeyframes: () => {
|
|
11
|
+
return keyframes;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.keyframesState = keyframesState;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { AvcPPs, AvcProfileInfo } from '../boxes/avc/parse-avc';
|
|
2
|
-
import type { OnTrackEntrySegment } from '../boxes/webm/segments';
|
|
3
|
-
import type { TrackInfo } from '../boxes/webm/segments/track-entry';
|
|
4
2
|
import type { BufferIterator } from '../buffer-iterator';
|
|
5
3
|
import type { Options, ParseMediaFields } from '../options';
|
|
6
|
-
import type {
|
|
4
|
+
import type { OnAudioTrack, OnVideoTrack } from '../webcodec-sample-types';
|
|
7
5
|
export type InternalStats = {
|
|
8
6
|
skippedBytes: number;
|
|
9
7
|
finalCursorOffset: number;
|
|
@@ -12,42 +10,75 @@ export type SpsAndPps = {
|
|
|
12
10
|
sps: AvcProfileInfo;
|
|
13
11
|
pps: AvcPPs;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
export declare const makeParserState: ({ hasAudioTrackHandlers, hasVideoTrackHandlers, signal, getIterator, fields, }: {
|
|
13
|
+
export declare const makeParserState: ({ hasAudioTrackHandlers, hasVideoTrackHandlers, signal, getIterator, fields, nullifySamples, onAudioTrack, onVideoTrack, supportsContentRange, }: {
|
|
17
14
|
hasAudioTrackHandlers: boolean;
|
|
18
15
|
hasVideoTrackHandlers: boolean;
|
|
19
16
|
signal: AbortSignal | undefined;
|
|
20
17
|
getIterator: () => BufferIterator | null;
|
|
21
18
|
fields: Options<ParseMediaFields>;
|
|
19
|
+
nullifySamples: boolean;
|
|
20
|
+
supportsContentRange: boolean;
|
|
21
|
+
onAudioTrack: OnAudioTrack | null;
|
|
22
|
+
onVideoTrack: OnVideoTrack | null;
|
|
22
23
|
}) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
riff: {
|
|
25
|
+
getAvcProfile: () => SpsAndPps | null;
|
|
26
|
+
onProfile: (profile: SpsAndPps) => Promise<void>;
|
|
27
|
+
registerOnAvcProfileCallback: (callback: (profile: SpsAndPps) => Promise<void>) => void;
|
|
28
|
+
getNextTrackIndex: () => number;
|
|
29
|
+
incrementNextTrackIndex: () => void;
|
|
30
|
+
};
|
|
31
|
+
callbacks: {
|
|
32
|
+
registerVideoSampleCallback: (id: number, callback: import("../webcodec-sample-types").OnVideoSample | null) => Promise<void>;
|
|
33
|
+
onAudioSample: (trackId: number, audioSample: import("../webcodec-sample-types").AudioOrVideoSample) => Promise<void>;
|
|
34
|
+
getSamplesForTrack: (trackId: number) => number;
|
|
35
|
+
onVideoSample: (trackId: number, videoSample: import("../webcodec-sample-types").AudioOrVideoSample) => Promise<void>;
|
|
36
|
+
canSkipTracksState: {
|
|
37
|
+
canSkipTracks: () => boolean;
|
|
38
|
+
};
|
|
39
|
+
registerAudioSampleCallback: (id: number, callback: import("../webcodec-sample-types").OnAudioSample | null) => Promise<void>;
|
|
40
|
+
tracks: {
|
|
41
|
+
hasAllTracks: () => boolean;
|
|
42
|
+
setIsDone: () => void;
|
|
43
|
+
addTrack: (track: import("..").Track) => void;
|
|
44
|
+
getTracks: () => import("..").Track[];
|
|
45
|
+
ensureHasTracksAtEnd: () => void;
|
|
46
|
+
};
|
|
47
|
+
audioSampleCallbacks: Record<number, import("../webcodec-sample-types").OnAudioSample>;
|
|
48
|
+
videoSampleCallbacks: Record<number, import("../webcodec-sample-types").OnVideoSample>;
|
|
49
|
+
};
|
|
37
50
|
getInternalStats: () => InternalStats;
|
|
38
51
|
getSkipBytes: () => number;
|
|
39
52
|
increaseSkippedBytes: (bytes: number) => void;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
keyframes: {
|
|
54
|
+
addKeyframe: (keyframe: import("../options").MediaParserKeyframe) => void;
|
|
55
|
+
getKeyframes: () => import("../options").MediaParserKeyframe[];
|
|
56
|
+
};
|
|
57
|
+
structure: {
|
|
58
|
+
getStructureOrNull: () => import("../parse-result").Structure | null;
|
|
59
|
+
getStructure: () => import("../parse-result").Structure;
|
|
60
|
+
setStructure: (value: import("../parse-result").Structure) => void;
|
|
61
|
+
};
|
|
62
|
+
nullifySamples: boolean;
|
|
63
|
+
onAudioTrack: OnAudioTrack | null;
|
|
64
|
+
onVideoTrack: OnVideoTrack | null;
|
|
65
|
+
supportsContentRange: boolean;
|
|
66
|
+
webm: {
|
|
67
|
+
onTrackEntrySegment: import("../boxes/webm/segments").OnTrackEntrySegment;
|
|
68
|
+
getTrackInfoByNumber: (id: number) => import("../boxes/webm/segments/track-entry").TrackInfo;
|
|
69
|
+
setTimestampOffset: (byteOffset: number, timestamp: number) => void;
|
|
70
|
+
getTimestampOffsetForByteOffset: (byteOffset: number) => number | undefined;
|
|
71
|
+
timescale: null;
|
|
72
|
+
getTimescale: () => number;
|
|
73
|
+
setTimescale: (newTimescale: number) => void;
|
|
47
74
|
};
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
emittedFields: import("../options").AllOptions<ParseMediaFields>;
|
|
76
|
+
fields: Partial<import("../options").AllOptions<ParseMediaFields>>;
|
|
77
|
+
slowDurationAndFps: {
|
|
78
|
+
addSample: (videoSample: import("../webcodec-sample-types").AudioOrVideoSample) => void;
|
|
79
|
+
getSlowDurationInSeconds: () => number;
|
|
80
|
+
getFps: () => number;
|
|
81
|
+
getSlowNumberOfFrames: () => number;
|
|
50
82
|
};
|
|
51
83
|
};
|
|
52
84
|
export type ParserState = ReturnType<typeof makeParserState>;
|
|
53
|
-
export {};
|
|
@@ -1,154 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeParserState = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!trackId) {
|
|
13
|
-
throw new Error('Expected track id');
|
|
14
|
-
}
|
|
15
|
-
if (trackEntries[trackId]) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const codec = (0, traversal_1.getTrackCodec)(trackEntry);
|
|
19
|
-
if (!codec) {
|
|
20
|
-
throw new Error('Expected codec');
|
|
21
|
-
}
|
|
22
|
-
const trackTimescale = (0, traversal_1.getTrackTimestampScale)(trackEntry);
|
|
23
|
-
trackEntries[trackId] = {
|
|
24
|
-
codec: codec.value,
|
|
25
|
-
trackTimescale: (_a = trackTimescale === null || trackTimescale === void 0 ? void 0 : trackTimescale.value) !== null && _a !== void 0 ? _a : null,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const videoSampleCallbacks = {};
|
|
29
|
-
const audioSampleCallbacks = {};
|
|
30
|
-
const queuedAudioSamples = {};
|
|
31
|
-
const queuedVideoSamples = {};
|
|
32
|
-
let timescale = null;
|
|
4
|
+
const emitted_fields_1 = require("./emitted-fields");
|
|
5
|
+
const keyframes_1 = require("./keyframes");
|
|
6
|
+
const riff_1 = require("./riff");
|
|
7
|
+
const sample_callbacks_1 = require("./sample-callbacks");
|
|
8
|
+
const slow_duration_fps_1 = require("./slow-duration-fps");
|
|
9
|
+
const structure_1 = require("./structure");
|
|
10
|
+
const webm_1 = require("./webm");
|
|
11
|
+
const makeParserState = ({ hasAudioTrackHandlers, hasVideoTrackHandlers, signal, getIterator, fields, nullifySamples, onAudioTrack, onVideoTrack, supportsContentRange, }) => {
|
|
33
12
|
let skippedBytes = 0;
|
|
34
|
-
const getTimescale = () => {
|
|
35
|
-
// https://www.matroska.org/technical/notes.html
|
|
36
|
-
// When using the default value of TimestampScale of “1,000,000”, one Segment Tick represents one millisecond.
|
|
37
|
-
if (timescale === null) {
|
|
38
|
-
return 1000000;
|
|
39
|
-
}
|
|
40
|
-
return timescale;
|
|
41
|
-
};
|
|
42
13
|
const increaseSkippedBytes = (bytes) => {
|
|
43
14
|
skippedBytes += bytes;
|
|
44
15
|
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const setTimestampOffset = (byteOffset, timestamp) => {
|
|
50
|
-
timestampMap.set(byteOffset, timestamp);
|
|
51
|
-
};
|
|
52
|
-
const getTimestampOffsetForByteOffset = (byteOffset) => {
|
|
53
|
-
const entries = Array.from(timestampMap.entries());
|
|
54
|
-
const sortedByByteOffset = entries
|
|
55
|
-
.sort((a, b) => {
|
|
56
|
-
return a[0] - b[0];
|
|
57
|
-
})
|
|
58
|
-
.reverse();
|
|
59
|
-
for (const [offset, timestamp] of sortedByByteOffset) {
|
|
60
|
-
if (offset >= byteOffset) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
return timestamp;
|
|
64
|
-
}
|
|
65
|
-
return timestampMap.get(byteOffset);
|
|
66
|
-
};
|
|
67
|
-
const samplesForTrack = {};
|
|
68
|
-
const profileCallbacks = [];
|
|
69
|
-
const registerOnAvcProfileCallback = (callback) => {
|
|
70
|
-
profileCallbacks.push(callback);
|
|
71
|
-
};
|
|
72
|
-
let avcProfile = null;
|
|
73
|
-
const onProfile = async (profile) => {
|
|
74
|
-
avcProfile = profile;
|
|
75
|
-
for (const callback of profileCallbacks) {
|
|
76
|
-
await callback(profile);
|
|
77
|
-
}
|
|
78
|
-
profileCallbacks.length = 0;
|
|
79
|
-
};
|
|
80
|
-
const canSkipTracksState = (0, can_skip_tracks_1.makeCanSkipTracksState)({
|
|
81
|
-
hasAudioTrackHandlers,
|
|
82
|
-
fields,
|
|
83
|
-
hasVideoTrackHandlers,
|
|
84
|
-
});
|
|
85
|
-
const tracksState = (0, has_tracks_section_1.makeTracksSectionState)(canSkipTracksState);
|
|
16
|
+
const structure = (0, structure_1.structureState)();
|
|
17
|
+
const keyframes = (0, keyframes_1.keyframesState)();
|
|
18
|
+
const emittedFields = (0, emitted_fields_1.emittedState)();
|
|
19
|
+
const slowDurationAndFps = (0, slow_duration_fps_1.slowDurationAndFpsState)();
|
|
86
20
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
videoSampleCallbacks[id] = callback;
|
|
98
|
-
for (const queued of (_a = queuedVideoSamples[id]) !== null && _a !== void 0 ? _a : []) {
|
|
99
|
-
await callback(queued);
|
|
100
|
-
}
|
|
101
|
-
queuedVideoSamples[id] = [];
|
|
102
|
-
},
|
|
103
|
-
setTimestampOffset,
|
|
104
|
-
getTimestampOffsetForByteOffset,
|
|
105
|
-
registerAudioSampleCallback: async (id, callback) => {
|
|
106
|
-
var _a;
|
|
107
|
-
if (callback === null) {
|
|
108
|
-
delete audioSampleCallbacks[id];
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
audioSampleCallbacks[id] = callback;
|
|
112
|
-
for (const queued of (_a = queuedAudioSamples[id]) !== null && _a !== void 0 ? _a : []) {
|
|
113
|
-
await callback(queued);
|
|
114
|
-
}
|
|
115
|
-
queuedAudioSamples[id] = [];
|
|
116
|
-
},
|
|
117
|
-
onAudioSample: async (trackId, audioSample) => {
|
|
118
|
-
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
119
|
-
throw new Error('Aborted');
|
|
120
|
-
}
|
|
121
|
-
if (typeof samplesForTrack[trackId] === 'undefined') {
|
|
122
|
-
samplesForTrack[trackId] = 0;
|
|
123
|
-
}
|
|
124
|
-
samplesForTrack[trackId]++;
|
|
125
|
-
const callback = audioSampleCallbacks[trackId];
|
|
126
|
-
if (callback) {
|
|
127
|
-
await callback(audioSample);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
onVideoSample: async (trackId, videoSample) => {
|
|
131
|
-
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
132
|
-
throw new Error('Aborted');
|
|
133
|
-
}
|
|
134
|
-
if (typeof samplesForTrack[trackId] === 'undefined') {
|
|
135
|
-
samplesForTrack[trackId] = 0;
|
|
136
|
-
}
|
|
137
|
-
samplesForTrack[trackId]++;
|
|
138
|
-
const callback = videoSampleCallbacks[trackId];
|
|
139
|
-
if (callback) {
|
|
140
|
-
await callback(videoSample);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
getTimescale,
|
|
144
|
-
setTimescale,
|
|
145
|
-
getSamplesForTrack: (trackId) => {
|
|
146
|
-
var _a;
|
|
147
|
-
return (_a = samplesForTrack[trackId]) !== null && _a !== void 0 ? _a : 0;
|
|
148
|
-
},
|
|
149
|
-
getAvcProfile: () => {
|
|
150
|
-
return avcProfile;
|
|
151
|
-
},
|
|
21
|
+
riff: (0, riff_1.riffSpecificState)(),
|
|
22
|
+
callbacks: (0, sample_callbacks_1.sampleCallback)({
|
|
23
|
+
signal,
|
|
24
|
+
hasAudioTrackHandlers,
|
|
25
|
+
hasVideoTrackHandlers,
|
|
26
|
+
fields,
|
|
27
|
+
keyframes,
|
|
28
|
+
emittedFields,
|
|
29
|
+
slowDurationAndFpsState: slowDurationAndFps,
|
|
30
|
+
}),
|
|
152
31
|
getInternalStats: () => {
|
|
153
32
|
var _a, _b;
|
|
154
33
|
return ({
|
|
@@ -158,13 +37,16 @@ const makeParserState = ({ hasAudioTrackHandlers, hasVideoTrackHandlers, signal,
|
|
|
158
37
|
},
|
|
159
38
|
getSkipBytes: () => skippedBytes,
|
|
160
39
|
increaseSkippedBytes,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
40
|
+
keyframes,
|
|
41
|
+
structure,
|
|
42
|
+
nullifySamples,
|
|
43
|
+
onAudioTrack,
|
|
44
|
+
onVideoTrack,
|
|
45
|
+
supportsContentRange,
|
|
46
|
+
webm: (0, webm_1.webmState)(),
|
|
47
|
+
emittedFields,
|
|
48
|
+
fields,
|
|
49
|
+
slowDurationAndFps,
|
|
168
50
|
};
|
|
169
51
|
};
|
|
170
52
|
exports.makeParserState = makeParserState;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SpsAndPps } from './parser-state';
|
|
2
|
+
type AvcProfileInfoCallback = (profile: SpsAndPps) => Promise<void>;
|
|
3
|
+
export declare const riffSpecificState: () => {
|
|
4
|
+
getAvcProfile: () => SpsAndPps | null;
|
|
5
|
+
onProfile: (profile: SpsAndPps) => Promise<void>;
|
|
6
|
+
registerOnAvcProfileCallback: (callback: AvcProfileInfoCallback) => void;
|
|
7
|
+
getNextTrackIndex: () => number;
|
|
8
|
+
incrementNextTrackIndex: () => void;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.riffSpecificState = void 0;
|
|
4
|
+
const riffSpecificState = () => {
|
|
5
|
+
let avcProfile = null;
|
|
6
|
+
let nextTrackIndex = 0;
|
|
7
|
+
const profileCallbacks = [];
|
|
8
|
+
const registerOnAvcProfileCallback = (callback) => {
|
|
9
|
+
profileCallbacks.push(callback);
|
|
10
|
+
};
|
|
11
|
+
const onProfile = async (profile) => {
|
|
12
|
+
avcProfile = profile;
|
|
13
|
+
for (const callback of profileCallbacks) {
|
|
14
|
+
await callback(profile);
|
|
15
|
+
}
|
|
16
|
+
profileCallbacks.length = 0;
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
getAvcProfile: () => {
|
|
20
|
+
return avcProfile;
|
|
21
|
+
},
|
|
22
|
+
onProfile,
|
|
23
|
+
registerOnAvcProfileCallback,
|
|
24
|
+
getNextTrackIndex: () => {
|
|
25
|
+
return nextTrackIndex;
|
|
26
|
+
},
|
|
27
|
+
incrementNextTrackIndex: () => {
|
|
28
|
+
nextTrackIndex++;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.riffSpecificState = riffSpecificState;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AllOptions, Options, ParseMediaFields } from '../options';
|
|
2
|
+
import type { AudioOrVideoSample, OnAudioSample, OnVideoSample } from '../webcodec-sample-types';
|
|
3
|
+
import { type KeyframesState } from './keyframes';
|
|
4
|
+
import type { SlowDurationAndFpsState } from './slow-duration-fps';
|
|
5
|
+
export declare const sampleCallback: ({ signal, hasAudioTrackHandlers, hasVideoTrackHandlers, fields, keyframes, emittedFields, slowDurationAndFpsState, }: {
|
|
6
|
+
signal: AbortSignal | undefined;
|
|
7
|
+
hasAudioTrackHandlers: boolean;
|
|
8
|
+
hasVideoTrackHandlers: boolean;
|
|
9
|
+
fields: Options<ParseMediaFields>;
|
|
10
|
+
keyframes: KeyframesState;
|
|
11
|
+
emittedFields: AllOptions<ParseMediaFields>;
|
|
12
|
+
slowDurationAndFpsState: SlowDurationAndFpsState;
|
|
13
|
+
}) => {
|
|
14
|
+
registerVideoSampleCallback: (id: number, callback: OnVideoSample | null) => Promise<void>;
|
|
15
|
+
onAudioSample: (trackId: number, audioSample: AudioOrVideoSample) => Promise<void>;
|
|
16
|
+
getSamplesForTrack: (trackId: number) => number;
|
|
17
|
+
onVideoSample: (trackId: number, videoSample: AudioOrVideoSample) => Promise<void>;
|
|
18
|
+
canSkipTracksState: {
|
|
19
|
+
canSkipTracks: () => boolean;
|
|
20
|
+
};
|
|
21
|
+
registerAudioSampleCallback: (id: number, callback: OnAudioSample | null) => Promise<void>;
|
|
22
|
+
tracks: {
|
|
23
|
+
hasAllTracks: () => boolean;
|
|
24
|
+
setIsDone: () => void;
|
|
25
|
+
addTrack: (track: import("..").Track) => void;
|
|
26
|
+
getTracks: () => import("..").Track[];
|
|
27
|
+
ensureHasTracksAtEnd: () => void;
|
|
28
|
+
};
|
|
29
|
+
audioSampleCallbacks: Record<number, OnAudioSample>;
|
|
30
|
+
videoSampleCallbacks: Record<number, OnVideoSample>;
|
|
31
|
+
};
|