@remotion/media-parser 4.0.270 → 4.0.271
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/aac-codecprivate.js +6 -13
- package/dist/add-avc-profile-to-track.js +5 -9
- package/dist/buffer-iterator.js +8 -13
- package/dist/combine-uint8-arrays.js +1 -5
- package/dist/containers/aac/parse-aac.js +9 -13
- package/dist/containers/aac/types.js +1 -2
- package/dist/containers/avc/codec-string.js +1 -5
- package/dist/containers/avc/color.js +3 -9
- package/dist/containers/avc/create-sps-pps-data.js +5 -9
- package/dist/containers/avc/interpret-sps.js +7 -13
- package/dist/containers/avc/key.js +1 -5
- package/dist/containers/avc/parse-avc.js +3 -7
- package/dist/containers/avc/sps-and-pps.js +1 -5
- package/dist/containers/flac/get-block-size.js +1 -5
- package/dist/containers/flac/get-channel-count.js +1 -5
- package/dist/containers/flac/get-duration-from-flac.js +1 -5
- package/dist/containers/flac/get-metadata-from-flac.js +1 -5
- package/dist/containers/flac/get-sample-rate.js +1 -5
- package/dist/containers/flac/parse-flac-frame.js +14 -19
- package/dist/containers/flac/parse-flac.js +15 -19
- package/dist/containers/flac/parse-header.js +1 -5
- package/dist/containers/flac/parse-metadata.js +1 -5
- package/dist/containers/flac/parse-streaminfo.js +3 -7
- package/dist/containers/flac/parse-unknown-block.js +1 -5
- package/dist/containers/flac/types.d.ts +2 -2
- package/dist/containers/flac/types.js +1 -2
- package/dist/containers/iso-base-media/base-media-box.js +1 -2
- package/dist/containers/iso-base-media/base-type.js +1 -2
- package/dist/containers/iso-base-media/esds/decoder-specific-config.js +1 -5
- package/dist/containers/iso-base-media/esds/esds-descriptors.js +5 -10
- package/dist/containers/iso-base-media/esds/esds.js +3 -7
- package/dist/containers/iso-base-media/ftyp.js +1 -5
- package/dist/containers/iso-base-media/get-actual-number-of-channels.js +4 -8
- package/dist/containers/iso-base-media/get-children.js +3 -7
- package/dist/containers/iso-base-media/get-keyframes.js +7 -11
- package/dist/containers/iso-base-media/get-moov-atom.js +21 -15
- package/dist/containers/iso-base-media/get-sample-positions-from-track.js +20 -24
- package/dist/containers/iso-base-media/get-video-codec-from-iso-track.d.ts +1 -1
- package/dist/containers/iso-base-media/get-video-codec-from-iso-track.js +3 -7
- package/dist/containers/iso-base-media/make-track.js +30 -34
- package/dist/containers/iso-base-media/mdat/mdat.js +16 -20
- package/dist/containers/iso-base-media/mdhd.js +1 -5
- package/dist/containers/iso-base-media/meta/hdlr.js +1 -5
- package/dist/containers/iso-base-media/meta/ilst.js +1 -5
- package/dist/containers/iso-base-media/moov/moov.js +3 -7
- package/dist/containers/iso-base-media/mvhd.js +7 -11
- package/dist/containers/iso-base-media/parse-boxes.js +5 -9
- package/dist/containers/iso-base-media/parse-icc-profile.js +4 -8
- package/dist/containers/iso-base-media/process-box.js +63 -67
- package/dist/containers/iso-base-media/stsd/av1c.js +1 -5
- package/dist/containers/iso-base-media/stsd/avcc.js +1 -5
- package/dist/containers/iso-base-media/stsd/colr.js +3 -7
- package/dist/containers/iso-base-media/stsd/ctts.js +1 -5
- package/dist/containers/iso-base-media/stsd/hvcc.js +3 -7
- package/dist/containers/iso-base-media/stsd/keys.js +1 -5
- package/dist/containers/iso-base-media/stsd/mebx.js +3 -7
- package/dist/containers/iso-base-media/stsd/pasp.js +1 -5
- package/dist/containers/iso-base-media/stsd/samples.js +8 -13
- package/dist/containers/iso-base-media/stsd/stco.js +1 -5
- package/dist/containers/iso-base-media/stsd/stsc.js +1 -5
- package/dist/containers/iso-base-media/stsd/stsd.js +3 -7
- package/dist/containers/iso-base-media/stsd/stss.js +1 -5
- package/dist/containers/iso-base-media/stsd/stsz.js +1 -5
- package/dist/containers/iso-base-media/stsd/stts.js +1 -5
- package/dist/containers/iso-base-media/tfdt.js +1 -5
- package/dist/containers/iso-base-media/tfhd.js +1 -5
- package/dist/containers/iso-base-media/tkhd.js +4 -8
- package/dist/containers/iso-base-media/to-date.js +1 -5
- package/dist/containers/iso-base-media/trak/trak.js +3 -7
- package/dist/containers/iso-base-media/traversal.d.ts +3 -2
- package/dist/containers/iso-base-media/traversal.js +42 -57
- package/dist/containers/iso-base-media/trun.js +2 -6
- package/dist/containers/iso-base-media/void-box.js +1 -2
- package/dist/containers/m3u/after-manifest-fetch.d.ts +5 -3
- package/dist/containers/m3u/after-manifest-fetch.js +13 -17
- package/dist/containers/m3u/fetch-m3u8-stream.d.ts +5 -1
- package/dist/containers/m3u/fetch-m3u8-stream.js +4 -12
- package/dist/containers/m3u/get-chunks.d.ts +1 -0
- package/dist/containers/m3u/get-chunks.js +6 -6
- package/dist/containers/m3u/get-duration-from-m3u.js +4 -8
- package/dist/containers/m3u/get-playlist.js +6 -12
- package/dist/containers/m3u/get-streams.d.ts +11 -5
- package/dist/containers/m3u/get-streams.js +5 -15
- package/dist/containers/m3u/iterate-over-segment-files.d.ts +19 -0
- package/dist/containers/m3u/iterate-over-segment-files.js +106 -0
- package/dist/containers/m3u/parse-directive.js +10 -10
- package/dist/containers/m3u/parse-m3u-manifest.js +3 -7
- package/dist/containers/m3u/parse-m3u-media-directive.d.ts +1 -0
- package/dist/containers/m3u/parse-m3u-media-directive.js +7 -7
- package/dist/containers/m3u/parse-m3u.js +13 -13
- package/dist/containers/m3u/parse-m3u8-text.js +3 -7
- package/dist/containers/m3u/parse-stream-inf.js +2 -7
- package/dist/containers/m3u/return-packets.d.ts +1 -1
- package/dist/containers/m3u/return-packets.js +14 -5
- package/dist/containers/m3u/run-over-m3u.js +10 -13
- package/dist/containers/m3u/sample-sorter.js +4 -8
- package/dist/containers/m3u/select-stream.d.ts +3 -2
- package/dist/containers/m3u/select-stream.js +9 -13
- package/dist/containers/m3u/types.d.ts +1 -1
- package/dist/containers/m3u/types.js +1 -2
- package/dist/containers/mp3/get-duration.js +5 -9
- package/dist/containers/mp3/get-frame-length.js +2 -7
- package/dist/containers/mp3/get-metadata-from-mp3.d.ts +2 -2
- package/dist/containers/mp3/get-metadata-from-mp3.js +1 -5
- package/dist/containers/mp3/id3-v1.js +1 -5
- package/dist/containers/mp3/id3.js +1 -5
- package/dist/containers/mp3/parse-mp3.js +7 -11
- package/dist/containers/mp3/parse-mpeg-header.js +10 -14
- package/dist/containers/mp3/samples-per-mpeg-file.js +1 -5
- package/dist/containers/riff/expect-riff-box.js +11 -15
- package/dist/containers/riff/get-duration.js +7 -12
- package/dist/containers/riff/get-tracks-from-avi.js +20 -28
- package/dist/containers/riff/is-movi.js +1 -5
- package/dist/containers/riff/parse-avih.js +1 -5
- package/dist/containers/riff/parse-isft.js +1 -5
- package/dist/containers/riff/parse-list-box.js +3 -7
- package/dist/containers/riff/parse-movi.js +13 -18
- package/dist/containers/riff/parse-riff-body.js +9 -13
- package/dist/containers/riff/parse-riff-box.js +9 -13
- package/dist/containers/riff/parse-riff-header.js +1 -5
- package/dist/containers/riff/parse-riff.js +5 -9
- package/dist/containers/riff/parse-strf.js +1 -5
- package/dist/containers/riff/parse-strh.js +3 -7
- package/dist/containers/riff/parse-video-section.js +7 -11
- package/dist/containers/riff/riff-box.js +1 -2
- package/dist/containers/riff/timescale.js +1 -4
- package/dist/containers/riff/traversal.js +7 -15
- package/dist/containers/transport-stream/adts-header.js +6 -10
- package/dist/containers/transport-stream/boxes.js +1 -2
- package/dist/containers/transport-stream/discard-rest-of-packet.js +2 -7
- package/dist/containers/transport-stream/find-separator.js +1 -4
- package/dist/containers/transport-stream/get-tracks.js +7 -12
- package/dist/containers/transport-stream/handle-aac-packet.js +12 -16
- package/dist/containers/transport-stream/handle-avc-packet.js +22 -26
- package/dist/containers/transport-stream/next-pes-header-store.js +1 -5
- package/dist/containers/transport-stream/parse-packet.js +13 -17
- package/dist/containers/transport-stream/parse-pat.js +5 -10
- package/dist/containers/transport-stream/parse-pes.js +1 -5
- package/dist/containers/transport-stream/parse-pmt.js +3 -7
- package/dist/containers/transport-stream/parse-stream-packet.js +13 -17
- package/dist/containers/transport-stream/parse-transport-stream.js +5 -9
- package/dist/containers/transport-stream/process-stream-buffers.js +10 -15
- package/dist/containers/transport-stream/traversal.js +4 -10
- package/dist/containers/wav/get-duration-from-wav.js +3 -8
- package/dist/containers/wav/get-metadata-from-wav.d.ts +2 -2
- package/dist/containers/wav/get-metadata-from-wav.js +1 -5
- package/dist/containers/wav/parse-data.js +5 -9
- package/dist/containers/wav/parse-fmt.js +3 -7
- package/dist/containers/wav/parse-header.js +1 -5
- package/dist/containers/wav/parse-id3.js +1 -5
- package/dist/containers/wav/parse-list.js +1 -5
- package/dist/containers/wav/parse-video-section.js +3 -7
- package/dist/containers/wav/parse-wav.js +15 -19
- package/dist/containers/wav/types.d.ts +2 -2
- package/dist/containers/wav/types.js +1 -2
- package/dist/containers/webm/allowed-partial-segments.js +1 -4
- package/dist/containers/webm/av1-codec-private.js +3 -7
- package/dist/containers/webm/color.js +6 -10
- package/dist/containers/webm/description.js +6 -10
- package/dist/containers/webm/get-ready-tracks.js +13 -18
- package/dist/containers/webm/get-sample-from-block.js +12 -16
- package/dist/containers/webm/make-track.js +43 -48
- package/dist/containers/webm/parse-ebml.js +14 -19
- package/dist/containers/webm/parse-webm-header.js +3 -7
- package/dist/containers/webm/segments/all-segments.js +168 -173
- package/dist/containers/webm/segments/block-simple-block-flags.js +4 -8
- package/dist/containers/webm/segments/track-entry.js +1 -5
- package/dist/containers/webm/segments.js +9 -13
- package/dist/containers/webm/traversal.js +37 -67
- package/dist/convert-audio-or-video-sample.js +1 -5
- package/dist/download-and-parse-media.js +44 -47
- package/dist/emit-available-info.js +38 -38
- package/dist/emitter.js +1 -5
- package/dist/errors.d.ts +2 -17
- package/dist/errors.js +10 -30
- package/dist/esm/fetch.mjs +93 -67
- package/dist/esm/index.mjs +679 -175
- package/dist/esm/node.mjs +59 -36
- package/dist/esm/universal.mjs +323 -0
- package/dist/esm/web-file.mjs +55 -43
- package/dist/esm/web.mjs +257 -0
- package/dist/esm/worker-server-entry.mjs +13056 -0
- package/dist/esm/worker-server.mjs +12914 -0
- package/dist/esm/worker-web-entry.mjs +12969 -0
- package/dist/esm/worker.mjs +439 -0
- package/dist/fetch.js +1 -17
- package/dist/file-types/bmp.js +3 -7
- package/dist/file-types/detect-file-type.js +24 -38
- package/dist/file-types/index.js +22 -26
- package/dist/file-types/jpeg.js +4 -9
- package/dist/file-types/pdf.js +3 -7
- package/dist/file-types/png.js +4 -9
- package/dist/file-types/webp.js +3 -7
- package/dist/forward-controller.js +1 -5
- package/dist/get-audio-codec.js +25 -38
- package/dist/get-container.d.ts +3 -3
- package/dist/get-container.js +5 -10
- package/dist/get-dimensions.js +8 -13
- package/dist/get-duration.js +27 -34
- package/dist/get-fields-from-callbacks.js +1 -5
- package/dist/get-fps.js +24 -34
- package/dist/get-is-hdr.js +5 -10
- package/dist/get-keyframes.js +6 -11
- package/dist/get-location.js +4 -9
- package/dist/get-number-of-audio-channels.js +2 -7
- package/dist/get-sample-aspect-ratio.js +17 -30
- package/dist/get-sample-positions-from-lpcm.js +5 -9
- package/dist/get-sample-positions.js +1 -5
- package/dist/get-sample-rate.js +2 -7
- package/dist/get-tracks.d.ts +5 -0
- package/dist/get-tracks.js +37 -44
- package/dist/get-video-codec.js +26 -34
- package/dist/has-all-info.js +33 -38
- package/dist/index.d.ts +15 -11
- package/dist/index.js +34 -48
- package/dist/init-video.d.ts +1 -1
- package/dist/init-video.js +47 -20
- package/dist/internal-parse-media.js +36 -40
- package/dist/is-audio-structure.d.ts +2 -2
- package/dist/is-audio-structure.js +1 -5
- package/dist/log.js +8 -12
- package/dist/make-hvc1-codec-strings.js +1 -5
- package/dist/media-parser-controller.js +7 -11
- package/dist/metadata/get-metadata.d.ts +4 -4
- package/dist/metadata/get-metadata.js +17 -22
- package/dist/metadata/metadata-from-iso.d.ts +3 -3
- package/dist/metadata/metadata-from-iso.js +12 -17
- package/dist/metadata/metadata-from-matroska.d.ts +2 -2
- package/dist/metadata/metadata-from-matroska.js +3 -7
- package/dist/metadata/metadata-from-riff.d.ts +2 -2
- package/dist/metadata/metadata-from-riff.js +3 -7
- package/dist/node-writer.js +1 -17
- package/dist/node.js +1 -17
- package/dist/options.d.ts +30 -24
- package/dist/options.js +1 -2
- package/dist/parse-media-on-browser-worker.d.ts +2 -0
- package/dist/parse-media-on-browser-worker.js +4 -0
- package/dist/parse-media-on-server-worker.d.ts +2 -0
- package/dist/parse-media-on-server-worker.js +4 -0
- package/dist/parse-media-on-web-worker.d.ts +2 -0
- package/dist/parse-media-on-web-worker.js +4 -0
- package/dist/parse-media-on-worker-entry.d.ts +2 -0
- package/dist/parse-media-on-worker-entry.js +269 -0
- package/dist/parse-media-on-worker.d.ts +2 -0
- package/dist/parse-media-on-worker.js +4 -0
- package/dist/parse-media.js +10 -13
- package/dist/parse-result.d.ts +3 -3
- package/dist/parse-result.js +1 -2
- package/dist/pause-signal.js +1 -5
- package/dist/perform-seek.js +6 -10
- package/dist/readers/fetch/get-body-and-reader.js +1 -5
- package/dist/readers/fetch/resolve-url.d.ts +1 -1
- package/dist/readers/fetch/resolve-url.js +1 -5
- package/dist/readers/from-fetch.d.ts +4 -1
- package/dist/readers/from-fetch.js +109 -94
- package/dist/readers/from-node.d.ts +4 -1
- package/dist/readers/from-node.js +58 -41
- package/dist/readers/from-web-file.d.ts +4 -1
- package/dist/readers/from-web-file.js +55 -49
- package/dist/readers/reader.d.ts +5 -1
- package/dist/readers/reader.js +1 -2
- package/dist/readers/universal.d.ts +2 -0
- package/dist/readers/universal.js +35 -0
- package/dist/readers/web.d.ts +2 -0
- package/dist/readers/web.js +22 -0
- package/dist/register-track.js +9 -15
- package/dist/remotion-license-acknowledge.js +4 -8
- package/dist/run-parse-iteration.js +26 -25
- package/dist/samples-from-moof.js +8 -12
- package/dist/skip.js +1 -5
- package/dist/state/aac-state.js +1 -5
- package/dist/state/can-skip-tracks.d.ts +2 -2
- package/dist/state/can-skip-tracks.js +3 -8
- package/dist/state/emitted-fields.js +1 -5
- package/dist/state/flac-state.js +1 -5
- package/dist/state/has-tracks-section.js +3 -7
- package/dist/state/images.js +1 -5
- package/dist/state/iso-base-media/cached-sample-positions.js +8 -13
- package/dist/state/iso-base-media/iso-state.js +5 -9
- package/dist/state/iso-base-media/moov-box.js +1 -5
- package/dist/state/keyframes.js +1 -5
- package/dist/state/last-eventloop-break.js +3 -7
- package/dist/state/m3u-state.d.ts +3 -0
- package/dist/state/m3u-state.js +16 -11
- package/dist/state/may-skip-video-data.js +3 -7
- package/dist/state/mp3.js +1 -5
- package/dist/state/need-samples-for-fields.js +1 -5
- package/dist/state/parser-state.d.ts +12 -10
- package/dist/state/parser-state.js +36 -41
- package/dist/state/riff.js +1 -5
- package/dist/state/sample-callbacks.js +8 -12
- package/dist/state/slow-duration-fps.js +1 -5
- package/dist/state/structure.d.ts +4 -4
- package/dist/state/structure.js +1 -5
- package/dist/state/transport-stream.js +3 -7
- package/dist/state/video-section.js +1 -5
- package/dist/state/webm.js +5 -9
- package/dist/throttled-progress.js +1 -5
- package/dist/truthy.js +1 -4
- package/dist/universal.d.ts +1 -0
- package/dist/universal.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -4
- package/dist/web-file.js +1 -17
- package/dist/web.d.ts +1 -0
- package/dist/web.js +1 -0
- package/dist/webcodec-sample-types.d.ts +6 -4
- package/dist/webcodec-sample-types.js +1 -2
- package/dist/worker/forward-controller.d.ts +3 -0
- package/dist/worker/forward-controller.js +20 -0
- package/dist/worker/serialize-error.d.ts +4 -0
- package/dist/worker/serialize-error.js +95 -0
- package/dist/worker/worker-types.d.ts +243 -0
- package/dist/worker/worker-types.js +1 -0
- package/dist/worker-bun-entry.d.ts +1 -0
- package/dist/worker-bun-entry.js +5 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +5 -0
- package/dist/worker-server-entry.d.ts +1 -0
- package/dist/worker-server-entry.js +5 -0
- package/dist/worker-server.d.ts +2 -0
- package/dist/worker-server.js +381 -0
- package/dist/worker-web-entry.d.ts +1 -0
- package/dist/worker-web-entry.js +5 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +267 -0
- package/dist/writers/node.js +16 -23
- package/dist/writers/writer.js +1 -2
- package/package.json +40 -21
- package/fetch.js +0 -2
- package/test.json +0 -663
- package/web-file.js +0 -2
package/dist/aac-codecprivate.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapAudioObjectTypeToCodecString = exports.parseAacCodecPrivate = exports.createAacCodecPrivate = exports.getSampleRateFromSampleFrequencyIndex = void 0;
|
|
4
|
-
const getSampleRateFromSampleFrequencyIndex = (samplingFrequencyIndex) => {
|
|
1
|
+
export const getSampleRateFromSampleFrequencyIndex = (samplingFrequencyIndex) => {
|
|
5
2
|
switch (samplingFrequencyIndex) {
|
|
6
3
|
case 0:
|
|
7
4
|
return 96000;
|
|
@@ -33,7 +30,6 @@ const getSampleRateFromSampleFrequencyIndex = (samplingFrequencyIndex) => {
|
|
|
33
30
|
throw new Error(`Unexpected sampling frequency index ${samplingFrequencyIndex}`);
|
|
34
31
|
}
|
|
35
32
|
};
|
|
36
|
-
exports.getSampleRateFromSampleFrequencyIndex = getSampleRateFromSampleFrequencyIndex;
|
|
37
33
|
// codec private, for example [17, 144]
|
|
38
34
|
// audioObjectType = 2 = 'AAC LC'
|
|
39
35
|
// samplingFrequencyIndex = 3 = '48000 Hz'
|
|
@@ -90,7 +86,7 @@ const getConfigForSampleRate = (sampleRate) => {
|
|
|
90
86
|
}
|
|
91
87
|
throw new Error(`Unexpected sample rate ${sampleRate}`);
|
|
92
88
|
};
|
|
93
|
-
const createAacCodecPrivate = ({ audioObjectType, sampleRate, channelConfiguration, codecPrivate, }) => {
|
|
89
|
+
export const createAacCodecPrivate = ({ audioObjectType, sampleRate, channelConfiguration, codecPrivate, }) => {
|
|
94
90
|
if (codecPrivate !== null && codecPrivate.length > 2) {
|
|
95
91
|
// Video submitted
|
|
96
92
|
// submitted by Yossi Elkrief
|
|
@@ -108,8 +104,7 @@ const createAacCodecPrivate = ({ audioObjectType, sampleRate, channelConfigurati
|
|
|
108
104
|
const secondByte = parseInt(bits.slice(8, 16), 2);
|
|
109
105
|
return new Uint8Array([firstByte, secondByte]);
|
|
110
106
|
};
|
|
111
|
-
|
|
112
|
-
const parseAacCodecPrivate = (bytes) => {
|
|
107
|
+
export const parseAacCodecPrivate = (bytes) => {
|
|
113
108
|
if (bytes.length < 2) {
|
|
114
109
|
throw new Error('Invalid AAC codec private length');
|
|
115
110
|
}
|
|
@@ -131,19 +126,18 @@ const parseAacCodecPrivate = (bytes) => {
|
|
|
131
126
|
offset += 5;
|
|
132
127
|
return {
|
|
133
128
|
audioObjectType: newAudioObjectType,
|
|
134
|
-
sampleRate:
|
|
129
|
+
sampleRate: getSampleRateFromSampleFrequencyIndex(extensionSamplingFrequencyIndex),
|
|
135
130
|
channelConfiguration,
|
|
136
131
|
};
|
|
137
132
|
}
|
|
138
|
-
const sampleRate =
|
|
133
|
+
const sampleRate = getSampleRateFromSampleFrequencyIndex(samplingFrequencyIndex);
|
|
139
134
|
return {
|
|
140
135
|
audioObjectType,
|
|
141
136
|
sampleRate,
|
|
142
137
|
channelConfiguration,
|
|
143
138
|
};
|
|
144
139
|
};
|
|
145
|
-
|
|
146
|
-
const mapAudioObjectTypeToCodecString = (audioObjectType) => {
|
|
140
|
+
export const mapAudioObjectTypeToCodecString = (audioObjectType) => {
|
|
147
141
|
/**
|
|
148
142
|
* 1. 1 - mp4a.40.2: MPEG-4 AAC LC (Low Complexity)
|
|
149
143
|
2. 2 - mp4a.40.5: MPEG-4 AAC HE (High Efficiency)
|
|
@@ -175,4 +169,3 @@ const mapAudioObjectTypeToCodecString = (audioObjectType) => {
|
|
|
175
169
|
throw new Error(`Unexpected audio object type ${audioObjectType}`);
|
|
176
170
|
}
|
|
177
171
|
};
|
|
178
|
-
exports.mapAudioObjectTypeToCodecString = mapAudioObjectTypeToCodecString;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const codec_string_1 = require("./containers/avc/codec-string");
|
|
5
|
-
const create_sps_pps_data_1 = require("./containers/avc/create-sps-pps-data");
|
|
6
|
-
const addAvcProfileToTrack = (track, avc1Profile) => {
|
|
1
|
+
import { getCodecStringFromSpsAndPps } from './containers/avc/codec-string';
|
|
2
|
+
import { createSpsPpsData } from './containers/avc/create-sps-pps-data';
|
|
3
|
+
export const addAvcProfileToTrack = (track, avc1Profile) => {
|
|
7
4
|
if (avc1Profile === null) {
|
|
8
5
|
return track;
|
|
9
6
|
}
|
|
10
7
|
return {
|
|
11
8
|
...track,
|
|
12
|
-
codec:
|
|
13
|
-
codecPrivate:
|
|
9
|
+
codec: getCodecStringFromSpsAndPps(avc1Profile.sps),
|
|
10
|
+
codecPrivate: createSpsPpsData(avc1Profile),
|
|
14
11
|
};
|
|
15
12
|
};
|
|
16
|
-
exports.addAvcProfileToTrack = addAvcProfileToTrack;
|
package/dist/buffer-iterator.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
2
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
3
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -11,12 +10,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
11
|
};
|
|
13
12
|
var _OffsetCounter_offset, _OffsetCounter_discardedBytes;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getArrayBufferIterator = exports.OffsetCounter = void 0;
|
|
16
13
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class OffsetCounter {
|
|
14
|
+
import { knownIdsWithOneLength, knownIdsWithThreeLength, knownIdsWithTwoLength, } from './containers/webm/segments/all-segments';
|
|
15
|
+
import { detectFileType } from './file-types';
|
|
16
|
+
export class OffsetCounter {
|
|
20
17
|
constructor(initial) {
|
|
21
18
|
_OffsetCounter_offset.set(this, void 0);
|
|
22
19
|
_OffsetCounter_discardedBytes.set(this, void 0);
|
|
@@ -51,12 +48,11 @@ class OffsetCounter {
|
|
|
51
48
|
__classPrivateFieldSet(this, _OffsetCounter_offset, __classPrivateFieldGet(this, _OffsetCounter_offset, "f") - amount, "f");
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
exports.OffsetCounter = OffsetCounter;
|
|
55
51
|
_OffsetCounter_offset = new WeakMap(), _OffsetCounter_discardedBytes = new WeakMap();
|
|
56
52
|
const makeOffsetCounter = () => {
|
|
57
53
|
return new OffsetCounter(0);
|
|
58
54
|
};
|
|
59
|
-
const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
55
|
+
export const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
60
56
|
const buf = new ArrayBuffer(initialData.byteLength, {
|
|
61
57
|
maxByteLength: maxBytes === null
|
|
62
58
|
? initialData.byteLength
|
|
@@ -385,7 +381,7 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
|
385
381
|
return new TextDecoder().decode(atom);
|
|
386
382
|
},
|
|
387
383
|
detectFileType: () => {
|
|
388
|
-
return
|
|
384
|
+
return detectFileType(uintArray);
|
|
389
385
|
},
|
|
390
386
|
getPaddedFourByteNumber,
|
|
391
387
|
getMatroskaSegmentId: () => {
|
|
@@ -400,7 +396,7 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
|
400
396
|
.join('')}`;
|
|
401
397
|
// Catch void block
|
|
402
398
|
// https://www.matroska.org/technical/elements.html
|
|
403
|
-
if (
|
|
399
|
+
if (knownIdsWithOneLength.includes(firstOneString)) {
|
|
404
400
|
return firstOneString;
|
|
405
401
|
}
|
|
406
402
|
if (bytesRemaining() === 0) {
|
|
@@ -412,7 +408,7 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
|
412
408
|
return b.toString(16).padStart(2, '0');
|
|
413
409
|
})
|
|
414
410
|
.join('')}`;
|
|
415
|
-
if (
|
|
411
|
+
if (knownIdsWithTwoLength.includes(firstTwoString)) {
|
|
416
412
|
return firstTwoString;
|
|
417
413
|
}
|
|
418
414
|
if (bytesRemaining() === 0) {
|
|
@@ -424,7 +420,7 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
|
424
420
|
return b.toString(16).padStart(2, '0');
|
|
425
421
|
})
|
|
426
422
|
.join('')}`;
|
|
427
|
-
if (
|
|
423
|
+
if (knownIdsWithThreeLength.includes(firstThreeString)) {
|
|
428
424
|
return firstThreeString;
|
|
429
425
|
}
|
|
430
426
|
if (bytesRemaining() === 0) {
|
|
@@ -585,4 +581,3 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
|
585
581
|
getSyncSafeInt32,
|
|
586
582
|
};
|
|
587
583
|
};
|
|
588
|
-
exports.getArrayBufferIterator = getArrayBufferIterator;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineUint8Arrays = void 0;
|
|
4
|
-
const combineUint8Arrays = (arrays) => {
|
|
1
|
+
export const combineUint8Arrays = (arrays) => {
|
|
5
2
|
if (arrays.length === 0) {
|
|
6
3
|
return new Uint8Array([]);
|
|
7
4
|
}
|
|
@@ -20,4 +17,3 @@ const combineUint8Arrays = (arrays) => {
|
|
|
20
17
|
}
|
|
21
18
|
return result;
|
|
22
19
|
};
|
|
23
|
-
exports.combineUint8Arrays = combineUint8Arrays;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sample");
|
|
6
|
-
const register_track_1 = require("../../register-track");
|
|
7
|
-
const parseAac = async (state) => {
|
|
1
|
+
import { createAacCodecPrivate, getSampleRateFromSampleFrequencyIndex, mapAudioObjectTypeToCodecString, } from '../../aac-codecprivate';
|
|
2
|
+
import { convertAudioOrVideoSampleToWebCodecsTimestamps } from '../../convert-audio-or-video-sample';
|
|
3
|
+
import { registerAudioTrack } from '../../register-track';
|
|
4
|
+
export const parseAac = async (state) => {
|
|
8
5
|
const { iterator } = state;
|
|
9
6
|
const startOffset = iterator.counter.getOffset();
|
|
10
7
|
iterator.startReadingBits();
|
|
@@ -23,10 +20,10 @@ const parseAac = async (state) => {
|
|
|
23
20
|
const protectionAbsent = iterator.getBits(1); // protection absent
|
|
24
21
|
const audioObjectType = iterator.getBits(2); // 1 = 'AAC-LC'
|
|
25
22
|
const samplingFrequencyIndex = iterator.getBits(4);
|
|
26
|
-
const sampleRate =
|
|
23
|
+
const sampleRate = getSampleRateFromSampleFrequencyIndex(samplingFrequencyIndex);
|
|
27
24
|
iterator.getBits(1); // private bit
|
|
28
25
|
const channelConfiguration = iterator.getBits(3);
|
|
29
|
-
const codecPrivate =
|
|
26
|
+
const codecPrivate = createAacCodecPrivate({
|
|
30
27
|
audioObjectType,
|
|
31
28
|
sampleRate,
|
|
32
29
|
channelConfiguration,
|
|
@@ -46,11 +43,11 @@ const parseAac = async (state) => {
|
|
|
46
43
|
iterator.counter.decrement(iterator.counter.getOffset() - startOffset);
|
|
47
44
|
const data = iterator.getSlice(frameLength);
|
|
48
45
|
if (state.callbacks.tracks.getTracks().length === 0) {
|
|
49
|
-
await
|
|
46
|
+
await registerAudioTrack({
|
|
50
47
|
state,
|
|
51
48
|
container: 'aac',
|
|
52
49
|
track: {
|
|
53
|
-
codec:
|
|
50
|
+
codec: mapAudioObjectTypeToCodecString(audioObjectType),
|
|
54
51
|
codecWithoutConfig: 'aac',
|
|
55
52
|
codecPrivate,
|
|
56
53
|
description: codecPrivate,
|
|
@@ -68,7 +65,7 @@ const parseAac = async (state) => {
|
|
|
68
65
|
const { index } = state.aac.addSample({ offset: startOffset, size: frameLength });
|
|
69
66
|
const timestamp = (1024 / sampleRate) * index;
|
|
70
67
|
// One ADTS frame contains 1024 samples
|
|
71
|
-
await state.callbacks.onAudioSample(0,
|
|
68
|
+
await state.callbacks.onAudioSample(0, convertAudioOrVideoSampleToWebCodecsTimestamps({
|
|
72
69
|
duration,
|
|
73
70
|
type: 'key',
|
|
74
71
|
data,
|
|
@@ -81,4 +78,3 @@ const parseAac = async (state) => {
|
|
|
81
78
|
}, 1));
|
|
82
79
|
return Promise.resolve(null);
|
|
83
80
|
};
|
|
84
|
-
exports.parseAac = parseAac;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCodecStringFromSpsAndPps = void 0;
|
|
4
|
-
const getCodecStringFromSpsAndPps = (sps) => {
|
|
1
|
+
export const getCodecStringFromSpsAndPps = (sps) => {
|
|
5
2
|
return `avc1.${sps.spsData.profile.toString(16).padStart(2, '0')}${sps.spsData.compatibility.toString(16).padStart(2, '0')}${sps.spsData.level.toString(16).padStart(2, '0')}`;
|
|
6
3
|
};
|
|
7
|
-
exports.getCodecStringFromSpsAndPps = getCodecStringFromSpsAndPps;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPrimariesFromIndex = exports.getTransferCharacteristicsFromIndex = exports.getMatrixCoefficientsFromIndex = void 0;
|
|
4
|
-
const getMatrixCoefficientsFromIndex = (index) => {
|
|
1
|
+
export const getMatrixCoefficientsFromIndex = (index) => {
|
|
5
2
|
return index === 1
|
|
6
3
|
? 'bt709'
|
|
7
4
|
: index === 5
|
|
@@ -12,8 +9,7 @@ const getMatrixCoefficientsFromIndex = (index) => {
|
|
|
12
9
|
? 'bt2020'
|
|
13
10
|
: null;
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
const getTransferCharacteristicsFromIndex = (index) => {
|
|
12
|
+
export const getTransferCharacteristicsFromIndex = (index) => {
|
|
17
13
|
return index === 1
|
|
18
14
|
? 'bt709'
|
|
19
15
|
: index === 6
|
|
@@ -24,8 +20,7 @@ const getTransferCharacteristicsFromIndex = (index) => {
|
|
|
24
20
|
? 'arib-std-b67'
|
|
25
21
|
: null;
|
|
26
22
|
};
|
|
27
|
-
|
|
28
|
-
const getPrimariesFromIndex = (index) => {
|
|
23
|
+
export const getPrimariesFromIndex = (index) => {
|
|
29
24
|
return index === 1
|
|
30
25
|
? 'bt709'
|
|
31
26
|
: index === 5
|
|
@@ -36,4 +31,3 @@ const getPrimariesFromIndex = (index) => {
|
|
|
36
31
|
? 'bt2020'
|
|
37
32
|
: null;
|
|
38
33
|
};
|
|
39
|
-
exports.getPrimariesFromIndex = getPrimariesFromIndex;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createSpsPpsData = void 0;
|
|
4
|
-
const combine_uint8_arrays_1 = require("../../combine-uint8-arrays");
|
|
5
|
-
const truthy_1 = require("../../truthy");
|
|
1
|
+
import { combineUint8Arrays } from '../../combine-uint8-arrays';
|
|
2
|
+
import { truthy } from '../../truthy';
|
|
6
3
|
function serializeUint16(value) {
|
|
7
4
|
const buffer = new ArrayBuffer(2);
|
|
8
5
|
const view = new DataView(buffer);
|
|
9
6
|
view.setUint16(0, value);
|
|
10
7
|
return new Uint8Array(buffer);
|
|
11
8
|
}
|
|
12
|
-
const createSpsPpsData = (avc1Profile) => {
|
|
13
|
-
return
|
|
9
|
+
export const createSpsPpsData = (avc1Profile) => {
|
|
10
|
+
return combineUint8Arrays([
|
|
14
11
|
new Uint8Array([
|
|
15
12
|
// https://gist.github.com/uupaa/8493378ec15f644a3d2b
|
|
16
13
|
1, // version
|
|
@@ -43,6 +40,5 @@ const createSpsPpsData = (avc1Profile) => {
|
|
|
43
40
|
numOfSequenceParameterSetExt 0
|
|
44
41
|
*/
|
|
45
42
|
new Uint8Array([0xfd, 0xf8, 0xf8, 0]),
|
|
46
|
-
].filter(
|
|
43
|
+
].filter(truthy));
|
|
47
44
|
};
|
|
48
|
-
exports.createSpsPpsData = createSpsPpsData;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getVideoColorFromSps = exports.getSampleAspectRatioFromSps = exports.getDimensionsFromSps = void 0;
|
|
4
|
-
const color_1 = require("./color");
|
|
5
|
-
const getDimensionsFromSps = (sps) => {
|
|
1
|
+
import { getMatrixCoefficientsFromIndex, getPrimariesFromIndex, getTransferCharacteristicsFromIndex, } from './color';
|
|
2
|
+
export const getDimensionsFromSps = (sps) => {
|
|
6
3
|
var _a, _b, _c, _d;
|
|
7
4
|
const height = sps.pic_height_in_map_units_minus1;
|
|
8
5
|
const width = sps.pic_width_in_mbs_minus1;
|
|
@@ -16,8 +13,7 @@ const getDimensionsFromSps = (sps) => {
|
|
|
16
13
|
((_d = sps.frame_crop_left_offset) !== null && _d !== void 0 ? _d : 0) * 2,
|
|
17
14
|
};
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
const getSampleAspectRatioFromSps = (sps) => {
|
|
16
|
+
export const getSampleAspectRatioFromSps = (sps) => {
|
|
21
17
|
var _a;
|
|
22
18
|
if (((_a = sps.vui_parameters) === null || _a === void 0 ? void 0 : _a.sar_height) && sps.vui_parameters.sar_width) {
|
|
23
19
|
return {
|
|
@@ -30,21 +26,19 @@ const getSampleAspectRatioFromSps = (sps) => {
|
|
|
30
26
|
height: 1,
|
|
31
27
|
};
|
|
32
28
|
};
|
|
33
|
-
|
|
34
|
-
const getVideoColorFromSps = (sps) => {
|
|
29
|
+
export const getVideoColorFromSps = (sps) => {
|
|
35
30
|
var _a, _b, _c, _d, _e;
|
|
36
31
|
const matrixCoefficients = (_a = sps.vui_parameters) === null || _a === void 0 ? void 0 : _a.matrix_coefficients;
|
|
37
32
|
const transferCharacteristics = (_b = sps.vui_parameters) === null || _b === void 0 ? void 0 : _b.transfer_characteristics;
|
|
38
33
|
const colorPrimaries = (_c = sps.vui_parameters) === null || _c === void 0 ? void 0 : _c.colour_primaries;
|
|
39
34
|
return {
|
|
40
35
|
matrixCoefficients: matrixCoefficients
|
|
41
|
-
?
|
|
36
|
+
? getMatrixCoefficientsFromIndex(matrixCoefficients)
|
|
42
37
|
: null,
|
|
43
38
|
transferCharacteristics: transferCharacteristics
|
|
44
|
-
?
|
|
39
|
+
? getTransferCharacteristicsFromIndex(transferCharacteristics)
|
|
45
40
|
: null,
|
|
46
|
-
primaries: colorPrimaries ?
|
|
41
|
+
primaries: colorPrimaries ? getPrimariesFromIndex(colorPrimaries) : null,
|
|
47
42
|
fullRange: (_e = (_d = sps.vui_parameters) === null || _d === void 0 ? void 0 : _d.video_full_range_flag) !== null && _e !== void 0 ? _e : null,
|
|
48
43
|
};
|
|
49
44
|
};
|
|
50
|
-
exports.getVideoColorFromSps = getVideoColorFromSps;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getKeyFrameOrDeltaFromAvcInfo = void 0;
|
|
4
|
-
const getKeyFrameOrDeltaFromAvcInfo = (infos) => {
|
|
1
|
+
export const getKeyFrameOrDeltaFromAvcInfo = (infos) => {
|
|
5
2
|
const keyOrDelta = infos.find((i) => i.type === 'keyframe' || i.type === 'delta-frame');
|
|
6
3
|
if (!keyOrDelta) {
|
|
7
4
|
throw new Error('expected avc to contain info about key or delta');
|
|
8
5
|
}
|
|
9
6
|
return keyOrDelta.type === 'keyframe' ? 'key' : 'delta';
|
|
10
7
|
};
|
|
11
|
-
exports.getKeyFrameOrDeltaFromAvcInfo = getKeyFrameOrDeltaFromAvcInfo;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// https://www.itu.int/rec/T-REC-H.264-202408-I/en
|
|
3
2
|
// Page 455
|
|
4
|
-
|
|
5
|
-
exports.parseAvc = void 0;
|
|
6
|
-
const buffer_iterator_1 = require("../../buffer-iterator");
|
|
3
|
+
import { getArrayBufferIterator } from '../../buffer-iterator';
|
|
7
4
|
const Extended_SAR = 255;
|
|
8
5
|
const readVuiParameters = (iterator) => {
|
|
9
6
|
let sar_width = null;
|
|
@@ -186,7 +183,7 @@ const findEnd = (buffer) => {
|
|
|
186
183
|
return null;
|
|
187
184
|
};
|
|
188
185
|
const inspect = (buffer) => {
|
|
189
|
-
const iterator =
|
|
186
|
+
const iterator = getArrayBufferIterator(buffer, buffer.byteLength);
|
|
190
187
|
iterator.startReadingBits();
|
|
191
188
|
iterator.getBits(1);
|
|
192
189
|
iterator.getBits(2);
|
|
@@ -224,7 +221,7 @@ const inspect = (buffer) => {
|
|
|
224
221
|
return null;
|
|
225
222
|
};
|
|
226
223
|
// https://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream
|
|
227
|
-
const parseAvc = (buffer) => {
|
|
224
|
+
export const parseAvc = (buffer) => {
|
|
228
225
|
let zeroesInARow = 0;
|
|
229
226
|
const infos = [];
|
|
230
227
|
for (let i = 0; i < buffer.length; i++) {
|
|
@@ -249,4 +246,3 @@ const parseAvc = (buffer) => {
|
|
|
249
246
|
}
|
|
250
247
|
return infos;
|
|
251
248
|
};
|
|
252
|
-
exports.parseAvc = parseAvc;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpsAndPps = void 0;
|
|
4
|
-
const getSpsAndPps = (infos) => {
|
|
1
|
+
export const getSpsAndPps = (infos) => {
|
|
5
2
|
const avcProfile = infos.find((i) => i.type === 'avc-profile');
|
|
6
3
|
const ppsProfile = infos.find((i) => i.type === 'avc-pps');
|
|
7
4
|
if (!avcProfile || !ppsProfile) {
|
|
@@ -9,4 +6,3 @@ const getSpsAndPps = (infos) => {
|
|
|
9
6
|
}
|
|
10
7
|
return { pps: ppsProfile, sps: avcProfile };
|
|
11
8
|
};
|
|
12
|
-
exports.getSpsAndPps = getSpsAndPps;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBlockSize = void 0;
|
|
4
|
-
const getBlockSize = (iterator) => {
|
|
1
|
+
export const getBlockSize = (iterator) => {
|
|
5
2
|
const bits = iterator.getBits(4);
|
|
6
3
|
if (bits === 0b0000) {
|
|
7
4
|
throw new Error('Reserved block size');
|
|
@@ -23,4 +20,3 @@ const getBlockSize = (iterator) => {
|
|
|
23
20
|
}
|
|
24
21
|
throw new Error('Invalid block size');
|
|
25
22
|
};
|
|
26
|
-
exports.getBlockSize = getBlockSize;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getChannelCount = void 0;
|
|
4
1
|
// https://www.rfc-editor.org/rfc/rfc9639.html#name-channels-bits
|
|
5
|
-
const getChannelCount = (iterator) => {
|
|
2
|
+
export const getChannelCount = (iterator) => {
|
|
6
3
|
const bits = iterator.getBits(4);
|
|
7
4
|
if (bits === 0b0000) {
|
|
8
5
|
return 1;
|
|
@@ -33,4 +30,3 @@ const getChannelCount = (iterator) => {
|
|
|
33
30
|
}
|
|
34
31
|
throw new Error(`Invalid channel count: ${bits.toString(2)}`);
|
|
35
32
|
};
|
|
36
|
-
exports.getChannelCount = getChannelCount;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDurationFromFlac = void 0;
|
|
4
|
-
const getDurationFromFlac = (parserState) => {
|
|
1
|
+
export const getDurationFromFlac = (parserState) => {
|
|
5
2
|
const structure = parserState.getFlacStructure();
|
|
6
3
|
const streaminfo = structure.boxes.find((b) => b.type === 'flac-streaminfo');
|
|
7
4
|
if (!streaminfo) {
|
|
@@ -9,4 +6,3 @@ const getDurationFromFlac = (parserState) => {
|
|
|
9
6
|
}
|
|
10
7
|
return streaminfo.totalSamples / streaminfo.sampleRate;
|
|
11
8
|
};
|
|
12
|
-
exports.getDurationFromFlac = getDurationFromFlac;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMetadataFromFlac = void 0;
|
|
4
|
-
const getMetadataFromFlac = (structure) => {
|
|
1
|
+
export const getMetadataFromFlac = (structure) => {
|
|
5
2
|
const box = structure.boxes.find((b) => b.type === 'flac-vorbis-comment');
|
|
6
3
|
if (!box) {
|
|
7
4
|
return null;
|
|
8
5
|
}
|
|
9
6
|
return box.fields;
|
|
10
7
|
};
|
|
11
|
-
exports.getMetadataFromFlac = getMetadataFromFlac;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSampleRate = void 0;
|
|
4
1
|
// https://www.rfc-editor.org/rfc/rfc9639.html#name-sample-rate-bits
|
|
5
|
-
const getSampleRate = (iterator, state) => {
|
|
2
|
+
export const getSampleRate = (iterator, state) => {
|
|
6
3
|
var _a, _b;
|
|
7
4
|
const mode = iterator.getBits(4);
|
|
8
5
|
if (mode === 0b0000) {
|
|
@@ -57,4 +54,3 @@ const getSampleRate = (iterator, state) => {
|
|
|
57
54
|
}
|
|
58
55
|
throw new Error(`Invalid sample rate mode: ${mode.toString(2)}`);
|
|
59
56
|
};
|
|
60
|
-
exports.getSampleRate = getSampleRate;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const get_block_size_1 = require("./get-block-size");
|
|
7
|
-
const get_channel_count_1 = require("./get-channel-count");
|
|
8
|
-
const get_sample_rate_1 = require("./get-sample-rate");
|
|
1
|
+
import { getArrayBufferIterator, } from '../../buffer-iterator';
|
|
2
|
+
import { convertAudioOrVideoSampleToWebCodecsTimestamps } from '../../convert-audio-or-video-sample';
|
|
3
|
+
import { getBlockSize } from './get-block-size';
|
|
4
|
+
import { getChannelCount } from './get-channel-count';
|
|
5
|
+
import { getSampleRate } from './get-sample-rate';
|
|
9
6
|
// https://www.rfc-editor.org/rfc/rfc9639.html#section-9.1.1
|
|
10
7
|
function calculateCRC8(data) {
|
|
11
8
|
const polynomial = 0x07; // x^8 + x^2 + x^1 + x^0
|
|
@@ -26,16 +23,16 @@ function calculateCRC8(data) {
|
|
|
26
23
|
}
|
|
27
24
|
return crc;
|
|
28
25
|
}
|
|
29
|
-
const parseFrameHeader = ({ iterator, state, }) => {
|
|
26
|
+
export const parseFrameHeader = ({ iterator, state, }) => {
|
|
30
27
|
if (iterator.bytesRemaining() < 10) {
|
|
31
28
|
return null;
|
|
32
29
|
}
|
|
33
30
|
const startOffset = iterator.counter.getOffset();
|
|
34
31
|
iterator.discard(2); // sync code
|
|
35
32
|
iterator.startReadingBits();
|
|
36
|
-
const blockSizeBits =
|
|
37
|
-
const sampleRateBits =
|
|
38
|
-
|
|
33
|
+
const blockSizeBits = getBlockSize(iterator);
|
|
34
|
+
const sampleRateBits = getSampleRate(iterator, state);
|
|
35
|
+
getChannelCount(iterator); // channel count
|
|
39
36
|
iterator.getBits(3); // bit depth
|
|
40
37
|
iterator.getBits(1);
|
|
41
38
|
const num = iterator.getFlacCodecNumber();
|
|
@@ -62,10 +59,9 @@ const parseFrameHeader = ({ iterator, state, }) => {
|
|
|
62
59
|
}
|
|
63
60
|
return { num, blockSize, sampleRate };
|
|
64
61
|
};
|
|
65
|
-
exports.parseFrameHeader = parseFrameHeader;
|
|
66
62
|
const emitSample = async ({ state, data, offset, }) => {
|
|
67
|
-
const iterator =
|
|
68
|
-
const parsed =
|
|
63
|
+
const iterator = getArrayBufferIterator(data, null);
|
|
64
|
+
const parsed = parseFrameHeader({ iterator, state });
|
|
69
65
|
if (!parsed) {
|
|
70
66
|
throw new Error('Invalid CRC');
|
|
71
67
|
}
|
|
@@ -80,7 +76,7 @@ const emitSample = async ({ state, data, offset, }) => {
|
|
|
80
76
|
throw new Error('Cannot determine timestamp');
|
|
81
77
|
}
|
|
82
78
|
const timestamp = (num * streamInfo.maximumBlockSize) / streamInfo.sampleRate;
|
|
83
|
-
await state.callbacks.onAudioSample(0,
|
|
79
|
+
await state.callbacks.onAudioSample(0, convertAudioOrVideoSampleToWebCodecsTimestamps({
|
|
84
80
|
data,
|
|
85
81
|
duration,
|
|
86
82
|
cts: timestamp,
|
|
@@ -93,7 +89,7 @@ const emitSample = async ({ state, data, offset, }) => {
|
|
|
93
89
|
}, 1));
|
|
94
90
|
iterator.destroy();
|
|
95
91
|
};
|
|
96
|
-
const parseFlacFrame = async ({ state, iterator, }) => {
|
|
92
|
+
export const parseFlacFrame = async ({ state, iterator, }) => {
|
|
97
93
|
var _a, _b;
|
|
98
94
|
const blockingBit = state.flac.getBlockingBitStrategy();
|
|
99
95
|
const offset = iterator.counter.getOffset();
|
|
@@ -152,7 +148,7 @@ const parseFlacFrame = async ({ state, iterator, }) => {
|
|
|
152
148
|
continue;
|
|
153
149
|
}
|
|
154
150
|
iterator.counter.decrement(2);
|
|
155
|
-
const nextIsLegit =
|
|
151
|
+
const nextIsLegit = parseFrameHeader({ iterator, state });
|
|
156
152
|
if (!nextIsLegit) {
|
|
157
153
|
iterator.discard(1);
|
|
158
154
|
continue;
|
|
@@ -166,4 +162,3 @@ const parseFlacFrame = async ({ state, iterator, }) => {
|
|
|
166
162
|
}
|
|
167
163
|
return null;
|
|
168
164
|
};
|
|
169
|
-
exports.parseFlacFrame = parseFlacFrame;
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const parse_metadata_1 = require("./parse-metadata");
|
|
9
|
-
const parse_streaminfo_1 = require("./parse-streaminfo");
|
|
10
|
-
const parse_unknown_block_1 = require("./parse-unknown-block");
|
|
1
|
+
import { makeSkip } from '../../skip';
|
|
2
|
+
import { maySkipVideoData } from '../../state/may-skip-video-data';
|
|
3
|
+
import { parseFlacFrame } from './parse-flac-frame';
|
|
4
|
+
import { parseFlacHeader } from './parse-header';
|
|
5
|
+
import { parseVorbisComment } from './parse-metadata';
|
|
6
|
+
import { parseStreamInfo } from './parse-streaminfo';
|
|
7
|
+
import { parseFlacUnkownBlock } from './parse-unknown-block';
|
|
11
8
|
const flacTypes = {
|
|
12
9
|
streaminfo: 0,
|
|
13
10
|
vorbisComment: 4,
|
|
14
11
|
};
|
|
15
|
-
const parseFlac = ({ iterator, state, }) => {
|
|
12
|
+
export const parseFlac = ({ iterator, state, }) => {
|
|
16
13
|
const videoSectionState = state.videoSection.isInVideoSectionState(iterator);
|
|
17
14
|
if (videoSectionState === 'in-section') {
|
|
18
|
-
if (
|
|
19
|
-
return Promise.resolve(
|
|
15
|
+
if (maySkipVideoData({ state })) {
|
|
16
|
+
return Promise.resolve(makeSkip(state.contentLength));
|
|
20
17
|
}
|
|
21
|
-
return
|
|
18
|
+
return parseFlacFrame({ state, iterator });
|
|
22
19
|
}
|
|
23
20
|
const bytes = iterator.getByteString(4, true);
|
|
24
21
|
if (bytes === 'fLaC') {
|
|
25
|
-
return
|
|
22
|
+
return parseFlacHeader({ state, iterator });
|
|
26
23
|
}
|
|
27
24
|
iterator.counter.decrement(4);
|
|
28
25
|
// https://www.rfc-editor.org/rfc/rfc9639.html#name-streaminfo
|
|
@@ -39,11 +36,10 @@ const parseFlac = ({ iterator, state, }) => {
|
|
|
39
36
|
});
|
|
40
37
|
}
|
|
41
38
|
if (metaBlockType === flacTypes.streaminfo) {
|
|
42
|
-
return
|
|
39
|
+
return parseStreamInfo({ iterator, state });
|
|
43
40
|
}
|
|
44
41
|
if (metaBlockType === flacTypes.vorbisComment) {
|
|
45
|
-
return
|
|
42
|
+
return parseVorbisComment({ iterator, state, size });
|
|
46
43
|
}
|
|
47
|
-
return
|
|
44
|
+
return parseFlacUnkownBlock({ iterator, state, size });
|
|
48
45
|
};
|
|
49
|
-
exports.parseFlac = parseFlac;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFlacHeader = void 0;
|
|
4
|
-
const parseFlacHeader = ({ state, }) => {
|
|
1
|
+
export const parseFlacHeader = ({ state, }) => {
|
|
5
2
|
state.getFlacStructure().boxes.push({
|
|
6
3
|
type: 'flac-header',
|
|
7
4
|
});
|
|
8
5
|
return Promise.resolve(null);
|
|
9
6
|
};
|
|
10
|
-
exports.parseFlacHeader = parseFlacHeader;
|