@remotion/media-parser 4.0.241 → 4.0.242
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 +2 -0
- package/dist/emit-available-info.d.ts +4 -5
- package/dist/emit-available-info.js +171 -57
- package/dist/esm/index.mjs +881 -490
- 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 +96 -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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMovi = exports.handleChunk = void 0;
|
|
4
4
|
const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sample");
|
|
5
|
+
const may_skip_video_data_1 = require("../../may-skip-video-data/may-skip-video-data");
|
|
5
6
|
const key_1 = require("../avc/key");
|
|
6
7
|
const parse_avc_1 = require("../avc/parse-avc");
|
|
7
8
|
const traversal_1 = require("./traversal");
|
|
@@ -17,33 +18,38 @@ const getStrhForIndex = (structure, trackId) => {
|
|
|
17
18
|
}
|
|
18
19
|
return strh;
|
|
19
20
|
};
|
|
20
|
-
const handleChunk = async ({ iterator,
|
|
21
|
+
const handleChunk = async ({ iterator, state, structure, ckId, ckSize, }) => {
|
|
22
|
+
const offset = iterator.counter.getOffset();
|
|
21
23
|
const videoChunk = ckId.match(/^([0-9]{2})dc$/);
|
|
22
24
|
if (videoChunk) {
|
|
23
25
|
const trackId = parseInt(videoChunk[1], 10);
|
|
24
26
|
const strh = getStrhForIndex(structure, trackId);
|
|
25
27
|
const samplesPerSecond = strh.rate / strh.scale;
|
|
26
|
-
const nthSample =
|
|
28
|
+
const nthSample = state.callbacks.getSamplesForTrack(trackId);
|
|
27
29
|
const timeInSec = nthSample / samplesPerSecond;
|
|
28
|
-
const timestamp =
|
|
29
|
-
const duration = Math.floor(1 / samplesPerSecond);
|
|
30
|
+
const timestamp = timeInSec;
|
|
30
31
|
const data = iterator.getSlice(ckSize);
|
|
31
32
|
const infos = (0, parse_avc_1.parseAvc)(data);
|
|
32
33
|
const keyOrDelta = (0, key_1.getKeyFrameOrDeltaFromAvcInfo)(infos);
|
|
33
34
|
const avcProfile = infos.find((i) => i.type === 'avc-profile');
|
|
34
35
|
const ppsProfile = infos.find((i) => i.type === 'avc-pps');
|
|
35
36
|
if (avcProfile && ppsProfile) {
|
|
36
|
-
await
|
|
37
|
-
|
|
37
|
+
await state.riff.onProfile({ pps: ppsProfile, sps: avcProfile });
|
|
38
|
+
state.callbacks.tracks.setIsDone();
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
// We must also NOT pass a duration because if the the next sample is 0,
|
|
41
|
+
// this sample would be longer. Chrome will pad it with silence.
|
|
42
|
+
// If we'd pass a duration instead, it would shift the audio and we think that audio is not finished
|
|
43
|
+
await state.callbacks.onVideoSample(trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
|
|
40
44
|
cts: timestamp,
|
|
41
45
|
dts: timestamp,
|
|
42
46
|
data,
|
|
43
|
-
duration,
|
|
47
|
+
duration: undefined,
|
|
44
48
|
timestamp,
|
|
45
49
|
trackId,
|
|
46
50
|
type: keyOrDelta,
|
|
51
|
+
offset,
|
|
52
|
+
timescale: samplesPerSecond,
|
|
47
53
|
}, 1));
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
@@ -52,36 +58,45 @@ const handleChunk = async ({ iterator, options, structure, ckId, ckSize, }) => {
|
|
|
52
58
|
const trackId = parseInt(audioChunk[1], 10);
|
|
53
59
|
const strh = getStrhForIndex(structure, trackId);
|
|
54
60
|
const samplesPerSecond = strh.rate / strh.scale;
|
|
55
|
-
const nthSample =
|
|
61
|
+
const nthSample = state.callbacks.getSamplesForTrack(trackId);
|
|
56
62
|
const timeInSec = nthSample / samplesPerSecond;
|
|
57
63
|
const timestamp = timeInSec;
|
|
58
|
-
const
|
|
59
|
-
|
|
64
|
+
const data = iterator.getSlice(ckSize);
|
|
65
|
+
// In example.avi, we have samples with 0 data
|
|
66
|
+
// Chrome fails on these
|
|
67
|
+
// We must also NOT pass a duration because if the the next sample is 0,
|
|
68
|
+
// this sample would be longer. Chrome will pad it with silence.
|
|
69
|
+
// If we'd pass a duration instead, it would shift the audio and we think that audio is not finished
|
|
70
|
+
await state.callbacks.onAudioSample(trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
|
|
60
71
|
cts: timestamp,
|
|
61
72
|
dts: timestamp,
|
|
62
|
-
data
|
|
63
|
-
duration,
|
|
73
|
+
data,
|
|
74
|
+
duration: undefined,
|
|
64
75
|
timestamp,
|
|
65
76
|
trackId,
|
|
66
77
|
type: 'key',
|
|
78
|
+
offset,
|
|
79
|
+
timescale: samplesPerSecond,
|
|
67
80
|
}, 1));
|
|
68
81
|
}
|
|
69
82
|
};
|
|
70
83
|
exports.handleChunk = handleChunk;
|
|
71
|
-
const parseMovi = async ({ iterator, maxOffset,
|
|
84
|
+
const parseMovi = async ({ iterator, maxOffset, state, structure, }) => {
|
|
72
85
|
while (iterator.counter.getOffset() < maxOffset) {
|
|
73
86
|
if (iterator.bytesRemaining() < 8) {
|
|
74
87
|
return {
|
|
75
88
|
type: 'incomplete',
|
|
76
89
|
continueParsing: () => {
|
|
77
|
-
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset,
|
|
90
|
+
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
|
|
78
91
|
},
|
|
79
92
|
};
|
|
80
93
|
}
|
|
81
94
|
const ckId = iterator.getByteString(4);
|
|
82
95
|
const ckSize = iterator.getUint32Le();
|
|
83
|
-
if (
|
|
84
|
-
|
|
96
|
+
if ((0, may_skip_video_data_1.maySkipVideoData)({
|
|
97
|
+
state,
|
|
98
|
+
}) &&
|
|
99
|
+
state.riff.getAvcProfile()) {
|
|
85
100
|
return {
|
|
86
101
|
type: 'complete',
|
|
87
102
|
box: {
|
|
@@ -95,11 +110,11 @@ const parseMovi = async ({ iterator, maxOffset, options, structure, }) => {
|
|
|
95
110
|
return {
|
|
96
111
|
type: 'incomplete',
|
|
97
112
|
continueParsing: () => {
|
|
98
|
-
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset,
|
|
113
|
+
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
|
|
99
114
|
},
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
|
-
await (0, exports.handleChunk)({ iterator,
|
|
117
|
+
await (0, exports.handleChunk)({ iterator, state, structure, ckId, ckSize });
|
|
103
118
|
// Discard added zeroes
|
|
104
119
|
while (iterator.counter.getOffset() < maxOffset &&
|
|
105
120
|
iterator.bytesRemaining() > 0) {
|
|
@@ -124,7 +139,7 @@ const parseMovi = async ({ iterator, maxOffset, options, structure, }) => {
|
|
|
124
139
|
return {
|
|
125
140
|
type: 'incomplete',
|
|
126
141
|
continueParsing: () => {
|
|
127
|
-
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset,
|
|
142
|
+
return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
|
|
128
143
|
},
|
|
129
144
|
};
|
|
130
145
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParserState } from '../../state/parser-state';
|
|
3
3
|
import type { RiffBox } from './riff-box';
|
|
4
|
-
export declare const parseRiffBox: ({ iterator, size, id, boxes,
|
|
4
|
+
export declare const parseRiffBox: ({ iterator, size, id, boxes, state, }: {
|
|
5
5
|
iterator: BufferIterator;
|
|
6
6
|
size: number;
|
|
7
7
|
id: string;
|
|
8
8
|
boxes: RiffBox[];
|
|
9
|
-
|
|
9
|
+
state: ParserState;
|
|
10
10
|
}) => Promise<RiffBox>;
|
|
@@ -7,12 +7,12 @@ const parse_isft_1 = require("./parse-isft");
|
|
|
7
7
|
const parse_list_box_1 = require("./parse-list-box");
|
|
8
8
|
const parse_strf_1 = require("./parse-strf");
|
|
9
9
|
const parse_strh_1 = require("./parse-strh");
|
|
10
|
-
const parseRiffBox = ({ iterator, size, id, boxes,
|
|
10
|
+
const parseRiffBox = ({ iterator, size, id, boxes, state, }) => {
|
|
11
11
|
if (id === 'fmt') {
|
|
12
12
|
return Promise.resolve((0, parse_fmt_box_1.parseFmtBox)({ iterator, boxes, size }));
|
|
13
13
|
}
|
|
14
14
|
if (id === 'LIST') {
|
|
15
|
-
return (0, parse_list_box_1.parseListBox)({ iterator, size,
|
|
15
|
+
return (0, parse_list_box_1.parseListBox)({ iterator, size, state });
|
|
16
16
|
}
|
|
17
17
|
if (id === 'ISFT') {
|
|
18
18
|
return Promise.resolve((0, parse_isft_1.parseIsft)({ iterator, size }));
|
|
@@ -5,7 +5,7 @@ const truthy_1 = require("../../truthy");
|
|
|
5
5
|
const traversal_1 = require("./traversal");
|
|
6
6
|
const getTracksFromTransportStream = (structure, parserState) => {
|
|
7
7
|
const programMapTable = (0, traversal_1.findProgramMapTableOrThrow)(structure);
|
|
8
|
-
const parserTracks = parserState.tracks.getTracks();
|
|
8
|
+
const parserTracks = parserState.callbacks.tracks.getTracks();
|
|
9
9
|
const mapped = programMapTable.streams
|
|
10
10
|
.map((stream) => {
|
|
11
11
|
return parserTracks.find((track) => track.trackId === stream.pid);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParserState } from '../../state/parser-state';
|
|
2
2
|
import type { TransportStreamPacketBuffer } from './process-stream-buffers';
|
|
3
|
-
export declare const handleAacPacket: ({ streamBuffer,
|
|
3
|
+
export declare const handleAacPacket: ({ streamBuffer, state, programId, offset, }: {
|
|
4
4
|
streamBuffer: TransportStreamPacketBuffer;
|
|
5
|
-
|
|
5
|
+
state: ParserState;
|
|
6
6
|
programId: number;
|
|
7
|
+
offset: number;
|
|
7
8
|
}) => Promise<void>;
|
|
@@ -6,14 +6,14 @@ const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sa
|
|
|
6
6
|
const register_track_1 = require("../../register-track");
|
|
7
7
|
const adts_header_1 = require("./adts-header");
|
|
8
8
|
const handle_avc_packet_1 = require("./handle-avc-packet");
|
|
9
|
-
const handleAacPacket = async ({ streamBuffer,
|
|
9
|
+
const handleAacPacket = async ({ streamBuffer, state, programId, offset, }) => {
|
|
10
10
|
var _a;
|
|
11
11
|
const adtsHeader = (0, adts_header_1.readAdtsHeader)(streamBuffer.buffer);
|
|
12
12
|
if (!adtsHeader) {
|
|
13
13
|
throw new Error('Invalid ADTS header - too short');
|
|
14
14
|
}
|
|
15
15
|
const { channelConfiguration, codecPrivate, sampleRate, audioObjectType } = adtsHeader;
|
|
16
|
-
const isTrackRegistered =
|
|
16
|
+
const isTrackRegistered = state.callbacks.tracks.getTracks().find((t) => {
|
|
17
17
|
return t.trackId === programId;
|
|
18
18
|
});
|
|
19
19
|
if (!isTrackRegistered) {
|
|
@@ -32,7 +32,7 @@ const handleAacPacket = async ({ streamBuffer, options, programId, }) => {
|
|
|
32
32
|
};
|
|
33
33
|
await (0, register_track_1.registerTrack)({
|
|
34
34
|
track,
|
|
35
|
-
|
|
35
|
+
state,
|
|
36
36
|
container: 'transport-stream',
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -44,7 +44,9 @@ const handleAacPacket = async ({ streamBuffer, options, programId, }) => {
|
|
|
44
44
|
data: new Uint8Array(streamBuffer.buffer),
|
|
45
45
|
trackId: programId,
|
|
46
46
|
type: 'key',
|
|
47
|
+
offset,
|
|
48
|
+
timescale: handle_avc_packet_1.MPEG_TIMESCALE,
|
|
47
49
|
};
|
|
48
|
-
await
|
|
50
|
+
await state.callbacks.onAudioSample(programId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)(sample, handle_avc_packet_1.MPEG_TIMESCALE));
|
|
49
51
|
};
|
|
50
52
|
exports.handleAacPacket = handleAacPacket;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParserState } from '../../state/parser-state';
|
|
2
2
|
import type { TransportStreamPacketBuffer } from './process-stream-buffers';
|
|
3
3
|
export declare const MPEG_TIMESCALE = 90000;
|
|
4
|
-
export declare const handleAvcPacket: ({ streamBuffer, programId,
|
|
4
|
+
export declare const handleAvcPacket: ({ streamBuffer, programId, state, offset, }: {
|
|
5
5
|
streamBuffer: TransportStreamPacketBuffer;
|
|
6
6
|
programId: number;
|
|
7
|
-
|
|
7
|
+
state: ParserState;
|
|
8
|
+
offset: number;
|
|
8
9
|
}) => Promise<void>;
|
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handleAvcPacket = exports.MPEG_TIMESCALE = void 0;
|
|
4
4
|
const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sample");
|
|
5
5
|
const register_track_1 = require("../../register-track");
|
|
6
|
-
const codec_private_1 = require("../avc/codec-private");
|
|
7
6
|
const codec_string_1 = require("../avc/codec-string");
|
|
7
|
+
const create_sps_pps_data_1 = require("../avc/create-sps-pps-data");
|
|
8
8
|
const interpret_sps_1 = require("../avc/interpret-sps");
|
|
9
9
|
const key_1 = require("../avc/key");
|
|
10
10
|
const parse_avc_1 = require("../avc/parse-avc");
|
|
11
11
|
const sps_and_pps_1 = require("../avc/sps-and-pps");
|
|
12
12
|
exports.MPEG_TIMESCALE = 90000;
|
|
13
|
-
const handleAvcPacket = async ({ streamBuffer, programId,
|
|
13
|
+
const handleAvcPacket = async ({ streamBuffer, programId, state, offset, }) => {
|
|
14
14
|
var _a;
|
|
15
15
|
const avc = (0, parse_avc_1.parseAvc)(streamBuffer.buffer);
|
|
16
|
-
const isTrackRegistered =
|
|
16
|
+
const isTrackRegistered = state.callbacks.tracks.getTracks().find((t) => {
|
|
17
17
|
return t.trackId === programId;
|
|
18
18
|
});
|
|
19
19
|
if (!isTrackRegistered) {
|
|
@@ -26,7 +26,7 @@ const handleAvcPacket = async ({ streamBuffer, programId, options, }) => {
|
|
|
26
26
|
type: 'video',
|
|
27
27
|
timescale: exports.MPEG_TIMESCALE,
|
|
28
28
|
codec: (0, codec_string_1.getCodecStringFromSpsAndPps)(spsAndPps.sps),
|
|
29
|
-
codecPrivate: (0,
|
|
29
|
+
codecPrivate: (0, create_sps_pps_data_1.createSpsPpsData)(spsAndPps),
|
|
30
30
|
fps: null,
|
|
31
31
|
codedWidth: dimensions.width,
|
|
32
32
|
codedHeight: dimensions.height,
|
|
@@ -43,7 +43,7 @@ const handleAvcPacket = async ({ streamBuffer, programId, options, }) => {
|
|
|
43
43
|
},
|
|
44
44
|
color: (0, interpret_sps_1.getVideoColorFromSps)(spsAndPps.sps.spsData),
|
|
45
45
|
};
|
|
46
|
-
await (0, register_track_1.registerTrack)({ track,
|
|
46
|
+
await (0, register_track_1.registerTrack)({ track, state, container: 'transport-stream' });
|
|
47
47
|
}
|
|
48
48
|
// sample for webcodecs needs to be in nano seconds
|
|
49
49
|
const sample = {
|
|
@@ -54,7 +54,9 @@ const handleAvcPacket = async ({ streamBuffer, programId, options, }) => {
|
|
|
54
54
|
data: new Uint8Array(streamBuffer.buffer),
|
|
55
55
|
trackId: programId,
|
|
56
56
|
type: (0, key_1.getKeyFrameOrDeltaFromAvcInfo)(avc),
|
|
57
|
+
offset,
|
|
58
|
+
timescale: exports.MPEG_TIMESCALE,
|
|
57
59
|
};
|
|
58
|
-
await
|
|
60
|
+
await state.callbacks.onVideoSample(programId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)(sample, exports.MPEG_TIMESCALE));
|
|
59
61
|
};
|
|
60
62
|
exports.handleAvcPacket = handleAvcPacket;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { TransportStreamStructure } from '../../parse-result';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
4
|
import type { TransportStreamBox } from './boxes';
|
|
5
5
|
import type { NextPesHeaderStore } from './next-pes-header-store';
|
|
6
6
|
import { type StreamBufferMap } from './process-stream-buffers';
|
|
7
|
-
export declare const parsePacket: ({ iterator, structure, streamBuffers,
|
|
7
|
+
export declare const parsePacket: ({ iterator, structure, streamBuffers, parserState, nextPesHeaderStore, }: {
|
|
8
8
|
iterator: BufferIterator;
|
|
9
9
|
structure: TransportStreamStructure;
|
|
10
10
|
streamBuffers: StreamBufferMap;
|
|
11
|
-
|
|
11
|
+
parserState: ParserState;
|
|
12
12
|
nextPesHeaderStore: NextPesHeaderStore;
|
|
13
13
|
}) => 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, structure, streamBuffers,
|
|
9
|
+
const parsePacket = async ({ iterator, structure, streamBuffers, parserState, nextPesHeaderStore, }) => {
|
|
10
10
|
const offset = iterator.counter.getOffset();
|
|
11
11
|
const syncByte = iterator.getUint8();
|
|
12
12
|
if (syncByte !== 0x47) {
|
|
@@ -69,7 +69,7 @@ const parsePacket = async ({ iterator, structure, streamBuffers, parserContext,
|
|
|
69
69
|
transportStreamEntry: stream,
|
|
70
70
|
streamBuffers,
|
|
71
71
|
nextPesHeader: nextPesHeaderStore.getNextPesHeader(),
|
|
72
|
-
|
|
72
|
+
state: parserState,
|
|
73
73
|
programId,
|
|
74
74
|
structure,
|
|
75
75
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { TransportStreamStructure } from '../../parse-result';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
4
|
import type { PacketPes } from './parse-pes';
|
|
5
5
|
import type { TransportStreamEntry } from './parse-pmt';
|
|
6
6
|
import { type StreamBufferMap } from './process-stream-buffers';
|
|
7
|
-
export declare const parseStream: ({ iterator, transportStreamEntry, streamBuffers,
|
|
7
|
+
export declare const parseStream: ({ iterator, transportStreamEntry, streamBuffers, state, programId, structure, nextPesHeader, }: {
|
|
8
8
|
iterator: BufferIterator;
|
|
9
9
|
transportStreamEntry: TransportStreamEntry;
|
|
10
10
|
streamBuffers: StreamBufferMap;
|
|
11
|
-
|
|
11
|
+
state: ParserState;
|
|
12
12
|
programId: number;
|
|
13
13
|
structure: TransportStreamStructure;
|
|
14
14
|
nextPesHeader: PacketPes;
|
|
@@ -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, streamBuffers, nextPesHeader,
|
|
9
|
+
const parseAdtsStream = async ({ restOfPacket, transportStreamEntry, streamBuffers, nextPesHeader, state, structure, offset, }) => {
|
|
10
10
|
var _a, _b;
|
|
11
11
|
const streamBuffer = streamBuffers.get(transportStreamEntry.pid);
|
|
12
12
|
if (!streamBuffer) {
|
|
13
13
|
streamBuffers.set(transportStreamEntry.pid, {
|
|
14
14
|
buffer: restOfPacket,
|
|
15
15
|
pesHeader: nextPesHeader,
|
|
16
|
+
offset,
|
|
16
17
|
});
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
@@ -28,17 +29,18 @@ const parseAdtsStream = async ({ restOfPacket, transportStreamEntry, streamBuffe
|
|
|
28
29
|
await (0, process_stream_buffers_1.processStreamBuffer)({
|
|
29
30
|
streamBuffer,
|
|
30
31
|
programId: transportStreamEntry.pid,
|
|
31
|
-
|
|
32
|
+
state,
|
|
32
33
|
structure,
|
|
33
34
|
});
|
|
34
35
|
const rest = restOfPacket.slice(bytesToTake);
|
|
35
36
|
streamBuffers.set(transportStreamEntry.pid, {
|
|
36
37
|
buffer: rest,
|
|
37
38
|
pesHeader: nextPesHeader,
|
|
39
|
+
offset,
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
};
|
|
41
|
-
const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffers, nextPesHeader, programId,
|
|
43
|
+
const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffers, nextPesHeader, programId, state, structure, offset, }) => {
|
|
42
44
|
const indexOfSeparator = (0, find_separator_1.findNextSeparator)(restOfPacket, transportStreamEntry);
|
|
43
45
|
const streamBuffer = streamBuffers.get(transportStreamEntry.pid);
|
|
44
46
|
if (indexOfSeparator === -1) {
|
|
@@ -52,6 +54,7 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
52
54
|
streamBuffers.set(programId, {
|
|
53
55
|
pesHeader: nextPesHeader,
|
|
54
56
|
buffer: restOfPacket,
|
|
57
|
+
offset,
|
|
55
58
|
});
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
@@ -59,7 +62,7 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
59
62
|
const packet = restOfPacket.slice(0, indexOfSeparator);
|
|
60
63
|
streamBuffer.buffer = (0, make_header_1.combineUint8Arrays)([streamBuffer.buffer, packet]);
|
|
61
64
|
await (0, process_stream_buffers_1.processStreamBuffer)({
|
|
62
|
-
|
|
65
|
+
state,
|
|
63
66
|
streamBuffer,
|
|
64
67
|
programId,
|
|
65
68
|
structure,
|
|
@@ -68,6 +71,7 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
68
71
|
streamBuffers.set(programId, {
|
|
69
72
|
pesHeader: nextPesHeader,
|
|
70
73
|
buffer: rest,
|
|
74
|
+
offset,
|
|
71
75
|
});
|
|
72
76
|
return;
|
|
73
77
|
}
|
|
@@ -77,9 +81,10 @@ const parseAvcStream = async ({ restOfPacket, transportStreamEntry, streamBuffer
|
|
|
77
81
|
streamBuffers.set(programId, {
|
|
78
82
|
pesHeader: nextPesHeader,
|
|
79
83
|
buffer: restOfPacket.slice(indexOfSeparator),
|
|
84
|
+
offset,
|
|
80
85
|
});
|
|
81
86
|
};
|
|
82
|
-
const parseStream = ({ iterator, transportStreamEntry, streamBuffers,
|
|
87
|
+
const parseStream = ({ iterator, transportStreamEntry, streamBuffers, state, programId, structure, nextPesHeader, }) => {
|
|
83
88
|
const restOfPacket = (0, discard_rest_of_packet_1.getRestOfPacket)(iterator);
|
|
84
89
|
if (transportStreamEntry.streamType === 27) {
|
|
85
90
|
return parseAvcStream({
|
|
@@ -87,9 +92,10 @@ const parseStream = ({ iterator, transportStreamEntry, streamBuffers, parserCont
|
|
|
87
92
|
transportStreamEntry,
|
|
88
93
|
streamBuffers,
|
|
89
94
|
nextPesHeader,
|
|
90
|
-
|
|
95
|
+
state,
|
|
91
96
|
programId,
|
|
92
97
|
structure,
|
|
98
|
+
offset: iterator.counter.getOffset(),
|
|
93
99
|
});
|
|
94
100
|
}
|
|
95
101
|
if (transportStreamEntry.streamType === 15) {
|
|
@@ -98,8 +104,9 @@ const parseStream = ({ iterator, transportStreamEntry, streamBuffers, parserCont
|
|
|
98
104
|
transportStreamEntry,
|
|
99
105
|
streamBuffers,
|
|
100
106
|
nextPesHeader,
|
|
101
|
-
|
|
107
|
+
state,
|
|
102
108
|
structure,
|
|
109
|
+
offset: iterator.counter.getOffset(),
|
|
103
110
|
});
|
|
104
111
|
}
|
|
105
112
|
throw new Error(`Unsupported stream type ${transportStreamEntry.streamType}`);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { Options, ParseMediaFields } from '../../options';
|
|
3
|
-
import type { ParseResult
|
|
4
|
-
import type {
|
|
3
|
+
import type { ParseResult } from '../../parse-result';
|
|
4
|
+
import type { ParserState } from '../../state/parser-state';
|
|
5
5
|
import type { NextPesHeaderStore } from './next-pes-header-store';
|
|
6
6
|
import { type StreamBufferMap } from './process-stream-buffers';
|
|
7
|
-
export declare const parseTransportStream: ({ iterator,
|
|
7
|
+
export declare const parseTransportStream: ({ iterator, state, streamBuffers, fields, nextPesHeaderStore, }: {
|
|
8
8
|
iterator: BufferIterator;
|
|
9
|
-
|
|
10
|
-
structure: TransportStreamStructure;
|
|
9
|
+
state: ParserState;
|
|
11
10
|
streamBuffers: StreamBufferMap;
|
|
12
11
|
fields: Options<ParseMediaFields>;
|
|
13
12
|
nextPesHeaderStore: NextPesHeaderStore;
|
|
14
|
-
}) => Promise<ParseResult
|
|
13
|
+
}) => Promise<ParseResult>;
|
|
@@ -4,11 +4,15 @@ exports.parseTransportStream = void 0;
|
|
|
4
4
|
const has_all_info_1 = require("../../has-all-info");
|
|
5
5
|
const parse_packet_1 = require("./parse-packet");
|
|
6
6
|
const process_stream_buffers_1 = require("./process-stream-buffers");
|
|
7
|
-
const parseTransportStream = async ({ iterator,
|
|
7
|
+
const parseTransportStream = async ({ iterator, state, streamBuffers, fields, nextPesHeaderStore, }) => {
|
|
8
|
+
const structure = state.structure.getStructure();
|
|
9
|
+
if (structure.type !== 'transport-stream') {
|
|
10
|
+
throw new Error('Invalid structure type');
|
|
11
|
+
}
|
|
8
12
|
if (iterator.bytesRemaining() === 0) {
|
|
9
13
|
await (0, process_stream_buffers_1.processFinalStreamBuffers)({
|
|
10
14
|
streamBufferMap: streamBuffers,
|
|
11
|
-
|
|
15
|
+
state,
|
|
12
16
|
structure,
|
|
13
17
|
});
|
|
14
18
|
return Promise.resolve({
|
|
@@ -19,8 +23,7 @@ const parseTransportStream = async ({ iterator, parserContext, structure, stream
|
|
|
19
23
|
while (true) {
|
|
20
24
|
if ((0, has_all_info_1.hasAllInfo)({
|
|
21
25
|
fields,
|
|
22
|
-
state
|
|
23
|
-
structure,
|
|
26
|
+
state,
|
|
24
27
|
})) {
|
|
25
28
|
break;
|
|
26
29
|
}
|
|
@@ -32,8 +35,7 @@ const parseTransportStream = async ({ iterator, parserContext, structure, stream
|
|
|
32
35
|
continueParsing: () => {
|
|
33
36
|
return (0, exports.parseTransportStream)({
|
|
34
37
|
iterator,
|
|
35
|
-
|
|
36
|
-
structure,
|
|
38
|
+
state,
|
|
37
39
|
streamBuffers,
|
|
38
40
|
fields,
|
|
39
41
|
nextPesHeaderStore,
|
|
@@ -45,7 +47,7 @@ const parseTransportStream = async ({ iterator, parserContext, structure, stream
|
|
|
45
47
|
iterator,
|
|
46
48
|
structure,
|
|
47
49
|
streamBuffers,
|
|
48
|
-
|
|
50
|
+
parserState: state,
|
|
49
51
|
nextPesHeaderStore,
|
|
50
52
|
});
|
|
51
53
|
if (packet) {
|
|
@@ -59,8 +61,7 @@ const parseTransportStream = async ({ iterator, parserContext, structure, stream
|
|
|
59
61
|
continueParsing() {
|
|
60
62
|
return (0, exports.parseTransportStream)({
|
|
61
63
|
iterator,
|
|
62
|
-
|
|
63
|
-
structure,
|
|
64
|
+
state,
|
|
64
65
|
streamBuffers,
|
|
65
66
|
fields,
|
|
66
67
|
nextPesHeaderStore,
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { TransportStreamStructure } from '../../parse-result';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParserState } from '../../state/parser-state';
|
|
3
3
|
import type { PacketPes } from './parse-pes';
|
|
4
4
|
export type TransportStreamPacketBuffer = {
|
|
5
5
|
buffer: Uint8Array;
|
|
6
6
|
pesHeader: PacketPes;
|
|
7
|
+
offset: number;
|
|
7
8
|
};
|
|
8
9
|
export type StreamBufferMap = Map<number, TransportStreamPacketBuffer>;
|
|
9
|
-
export declare const processStreamBuffer: ({ streamBuffer,
|
|
10
|
+
export declare const processStreamBuffer: ({ streamBuffer, state, programId, structure, }: {
|
|
10
11
|
streamBuffer: TransportStreamPacketBuffer;
|
|
11
|
-
|
|
12
|
+
state: ParserState;
|
|
12
13
|
programId: number;
|
|
13
14
|
structure: TransportStreamStructure;
|
|
14
15
|
}) => Promise<void>;
|
|
15
|
-
export declare const processFinalStreamBuffers: ({ streamBufferMap,
|
|
16
|
+
export declare const processFinalStreamBuffers: ({ streamBufferMap, state, structure, }: {
|
|
16
17
|
streamBufferMap: StreamBufferMap;
|
|
17
|
-
|
|
18
|
+
state: ParserState;
|
|
18
19
|
structure: TransportStreamStructure;
|
|
19
20
|
}) => Promise<void>;
|
|
@@ -4,34 +4,44 @@ exports.processFinalStreamBuffers = exports.processStreamBuffer = void 0;
|
|
|
4
4
|
const handle_aac_packet_1 = require("./handle-aac-packet");
|
|
5
5
|
const handle_avc_packet_1 = require("./handle-avc-packet");
|
|
6
6
|
const traversal_1 = require("./traversal");
|
|
7
|
-
const processStreamBuffer = async ({ streamBuffer,
|
|
7
|
+
const processStreamBuffer = async ({ streamBuffer, state, programId, structure, }) => {
|
|
8
8
|
const stream = (0, traversal_1.getStreamForId)(structure, programId);
|
|
9
9
|
if (!stream) {
|
|
10
10
|
throw new Error('No stream found');
|
|
11
11
|
}
|
|
12
12
|
// 27 = AVC / H.264 Video
|
|
13
13
|
if (stream.streamType === 27) {
|
|
14
|
-
await (0, handle_avc_packet_1.handleAvcPacket)({
|
|
14
|
+
await (0, handle_avc_packet_1.handleAvcPacket)({
|
|
15
|
+
programId,
|
|
16
|
+
streamBuffer,
|
|
17
|
+
state,
|
|
18
|
+
offset: streamBuffer.offset,
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
21
|
// 15 = AAC / ADTS
|
|
17
22
|
else if (stream.streamType === 15) {
|
|
18
|
-
await (0, handle_aac_packet_1.handleAacPacket)({
|
|
23
|
+
await (0, handle_aac_packet_1.handleAacPacket)({
|
|
24
|
+
streamBuffer,
|
|
25
|
+
state,
|
|
26
|
+
programId,
|
|
27
|
+
offset: streamBuffer.offset,
|
|
28
|
+
});
|
|
19
29
|
}
|
|
20
|
-
if (!
|
|
21
|
-
const tracksRegistered =
|
|
30
|
+
if (!state.callbacks.tracks.hasAllTracks()) {
|
|
31
|
+
const tracksRegistered = state.callbacks.tracks.getTracks().length;
|
|
22
32
|
const { streams } = (0, traversal_1.findProgramMapTableOrThrow)(structure);
|
|
23
33
|
if (streams.length === tracksRegistered) {
|
|
24
|
-
|
|
34
|
+
state.callbacks.tracks.setIsDone();
|
|
25
35
|
}
|
|
26
36
|
}
|
|
27
37
|
};
|
|
28
38
|
exports.processStreamBuffer = processStreamBuffer;
|
|
29
|
-
const processFinalStreamBuffers = async ({ streamBufferMap,
|
|
39
|
+
const processFinalStreamBuffers = async ({ streamBufferMap, state, structure, }) => {
|
|
30
40
|
for (const [programId, buffer] of streamBufferMap) {
|
|
31
41
|
if (buffer.buffer.byteLength > 0) {
|
|
32
42
|
await (0, exports.processStreamBuffer)({
|
|
33
43
|
streamBuffer: buffer,
|
|
34
|
-
|
|
44
|
+
state,
|
|
35
45
|
programId,
|
|
36
46
|
structure,
|
|
37
47
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const measureEBMLVarInt: (value: number) =>
|
|
1
|
+
export declare const measureEBMLVarInt: (value: number) => 1 | 2 | 3 | 4 | 5 | 6;
|
|
2
2
|
export declare const getVariableInt: (value: number, minWidth: number | null) => Uint8Array;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParserState } from '../../state/parser-state';
|
|
2
2
|
import type { AudioOrVideoSample } from '../../webcodec-sample-types';
|
|
3
3
|
import type { BlockSegment, SimpleBlockSegment } from './segments/all-segments';
|
|
4
4
|
type SampleResult = {
|
|
@@ -13,5 +13,5 @@ type SampleResult = {
|
|
|
13
13
|
} | {
|
|
14
14
|
type: 'no-sample';
|
|
15
15
|
};
|
|
16
|
-
export declare const getSampleFromBlock: (ebml: BlockSegment | SimpleBlockSegment,
|
|
16
|
+
export declare const getSampleFromBlock: (ebml: BlockSegment | SimpleBlockSegment, state: ParserState, offset: number) => SampleResult;
|
|
17
17
|
export {};
|