@remotion/media-parser 4.0.287 → 4.0.288

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.
@@ -0,0 +1,6 @@
1
+ import type { FlacSeekingHints } from './seeking-hints';
2
+ export declare const getSeekingByteForFlac: ({ time, seekingHints, endOfFile, }: {
3
+ time: number;
4
+ seekingHints: FlacSeekingHints;
5
+ endOfFile: boolean;
6
+ }) => number | null;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSeekingByteForFlac = void 0;
4
+ const getSeekingByteForFlac = ({ time, seekingHints, endOfFile, }) => {
5
+ let bestAudioSample;
6
+ for (const hint of seekingHints.audioSampleMap) {
7
+ if (hint.timeInSeconds > time) {
8
+ continue;
9
+ }
10
+ if (hint.timeInSeconds + hint.durationInSeconds < time && !endOfFile) {
11
+ continue;
12
+ }
13
+ if (!bestAudioSample) {
14
+ bestAudioSample = hint;
15
+ continue;
16
+ }
17
+ if (bestAudioSample.timeInSeconds < hint.timeInSeconds) {
18
+ bestAudioSample = hint;
19
+ }
20
+ }
21
+ if (bestAudioSample) {
22
+ return bestAudioSample.offset;
23
+ }
24
+ return null;
25
+ };
26
+ exports.getSeekingByteForFlac = getSeekingByteForFlac;
@@ -0,0 +1,6 @@
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
+ import type { ParserState } from '../../state/parser-state';
3
+ export declare const parseMetaBlock: ({ iterator, state, }: {
4
+ iterator: BufferIterator;
5
+ state: ParserState;
6
+ }) => Promise<import("../../parse-result").ParseResult>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMetaBlock = void 0;
4
+ const parse_metadata_1 = require("./parse-metadata");
5
+ const parse_streaminfo_1 = require("./parse-streaminfo");
6
+ const parse_unknown_block_1 = require("./parse-unknown-block");
7
+ const flacTypes = {
8
+ streaminfo: 0,
9
+ vorbisComment: 4,
10
+ };
11
+ const parseMetaBlock = ({ iterator, state, }) => {
12
+ iterator.startReadingBits();
13
+ const isLastMetadata = iterator.getBits(1);
14
+ const metaBlockType = iterator.getBits(7);
15
+ iterator.stopReadingBits();
16
+ const size = iterator.getUint24();
17
+ if (isLastMetadata) {
18
+ state.mediaSection.addMediaSection({
19
+ start: iterator.counter.getOffset() + size,
20
+ size: state.contentLength - iterator.counter.getOffset() - size,
21
+ });
22
+ }
23
+ if (metaBlockType === flacTypes.streaminfo) {
24
+ return (0, parse_streaminfo_1.parseStreamInfo)({ iterator, state });
25
+ }
26
+ if (metaBlockType === flacTypes.vorbisComment) {
27
+ return (0, parse_metadata_1.parseVorbisComment)({ iterator, state, size });
28
+ }
29
+ return (0, parse_unknown_block_1.parseFlacUnkownBlock)({ iterator, state, size });
30
+ };
31
+ exports.parseMetaBlock = parseMetaBlock;
@@ -0,0 +1,15 @@
1
+ import type { AudioSampleOffset } from '../../state/audio-sample-map';
2
+ import type { FlacState } from '../../state/flac-state';
3
+ import type { ParserState } from '../../state/parser-state';
4
+ export type FlacSeekingHints = {
5
+ type: 'flac-seeking-hints';
6
+ audioSampleMap: AudioSampleOffset[];
7
+ blockingBitStrategy: number | null;
8
+ };
9
+ export declare const getSeekingHintsForFlac: ({ flacState, }: {
10
+ flacState: FlacState;
11
+ }) => FlacSeekingHints;
12
+ export declare const setSeekingHintsForFlac: ({ hints, state, }: {
13
+ hints: FlacSeekingHints;
14
+ state: ParserState;
15
+ }) => void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSeekingHintsForFlac = exports.getSeekingHintsForFlac = void 0;
4
+ const getSeekingHintsForFlac = ({ flacState, }) => {
5
+ var _a;
6
+ return {
7
+ type: 'flac-seeking-hints',
8
+ audioSampleMap: flacState.audioSamples.getSamples(),
9
+ blockingBitStrategy: (_a = flacState.getBlockingBitStrategy()) !== null && _a !== void 0 ? _a : null,
10
+ };
11
+ };
12
+ exports.getSeekingHintsForFlac = getSeekingHintsForFlac;
13
+ const setSeekingHintsForFlac = ({ hints, state, }) => {
14
+ if (hints.blockingBitStrategy !== null) {
15
+ state.flac.setBlockingBitStrategy(hints.blockingBitStrategy);
16
+ }
17
+ state.flac.audioSamples.setFromSeekingHints(hints.audioSampleMap);
18
+ };
19
+ exports.setSeekingHintsForFlac = setSeekingHintsForFlac;
@@ -1,17 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.collectSamplePositionsFromTrak = void 0;
4
- const get_audio_codec_1 = require("../../get-audio-codec");
5
4
  const get_fps_1 = require("../../get-fps");
6
5
  const get_sample_positions_1 = require("../../get-sample-positions");
7
6
  const get_sample_positions_from_mp4_1 = require("../../get-sample-positions-from-mp4");
7
+ const should_group_audio_samples_1 = require("./should-group-audio-samples");
8
8
  const traversal_1 = require("./traversal");
9
9
  const collectSamplePositionsFromTrak = (trakBox) => {
10
- const isLpcm = (0, get_audio_codec_1.isLpcmAudioCodec)(trakBox);
10
+ const shouldGroupSamples = (0, should_group_audio_samples_1.shouldGroupAudioSamples)(trakBox);
11
11
  const timescaleAndDuration = (0, get_fps_1.getTimescaleAndDuration)(trakBox);
12
- const isIn24 = (0, get_audio_codec_1.isIn24AudioCodec)(trakBox);
13
- if (isLpcm || isIn24) {
14
- return (0, get_sample_positions_from_mp4_1.getGroupedSamplesPositionsFromMp4)(trakBox);
12
+ if (shouldGroupSamples) {
13
+ return (0, get_sample_positions_from_mp4_1.getGroupedSamplesPositionsFromMp4)({
14
+ trakBox,
15
+ bigEndian: shouldGroupSamples.bigEndian,
16
+ });
15
17
  }
16
18
  const stszBox = (0, traversal_1.getStszBox)(trakBox);
17
19
  const stcoBox = (0, traversal_1.getStcoBox)(trakBox);
@@ -9,6 +9,7 @@ const cached_sample_positions_1 = require("../../../state/iso-base-media/cached-
9
9
  const may_skip_video_data_1 = require("../../../state/may-skip-video-data");
10
10
  const video_section_1 = require("../../../state/video-section");
11
11
  const get_moov_atom_1 = require("../get-moov-atom");
12
+ const postprocess_bytes_1 = require("./postprocess-bytes");
12
13
  const parseMdatSection = async (state) => {
13
14
  const mediaSection = (0, video_section_1.getCurrentMediaSection)({
14
15
  offset: state.iterator.counter.getOffset(),
@@ -62,8 +63,12 @@ const parseMdatSection = async (state) => {
62
63
  if (iterator.bytesRemaining() < samplesWithIndex.samplePosition.size) {
63
64
  return null;
64
65
  }
65
- const bytes = iterator.getSlice(samplesWithIndex.samplePosition.size);
66
- const { cts, dts, duration, isKeyframe, offset } = samplesWithIndex.samplePosition;
66
+ const { cts, dts, duration, isKeyframe, offset, bigEndian, chunkSize } = samplesWithIndex.samplePosition;
67
+ const bytes = (0, postprocess_bytes_1.postprocessBytes)({
68
+ bytes: iterator.getSlice(samplesWithIndex.samplePosition.size),
69
+ bigEndian,
70
+ chunkSize,
71
+ });
67
72
  if (samplesWithIndex.track.type === 'audio') {
68
73
  await (0, emit_audio_sample_1.emitAudioSample)({
69
74
  trackId: samplesWithIndex.track.trackId,
@@ -0,0 +1,5 @@
1
+ export declare const postprocessBytes: ({ bytes, bigEndian, chunkSize, }: {
2
+ bytes: Uint8Array;
3
+ bigEndian: boolean;
4
+ chunkSize: number | null;
5
+ }) => Uint8Array<ArrayBufferLike>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // Addressing the issue of audio that is stored in big-endian format!
3
+ // If a "twos" atom is present, that is the case.
4
+ // The samples are stored internally in small chunks, like 4 bytes
5
+ // but WebCodecs does not accept such small chunks.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.postprocessBytes = void 0;
8
+ // When entering this function, they are already concatenated, but in litte endian order.
9
+ // This function reverses the bytes in each chunk, so that they are in big-endian order.
10
+ const postprocessBytes = ({ bytes, bigEndian, chunkSize, }) => {
11
+ if (!bigEndian) {
12
+ return bytes;
13
+ }
14
+ if (chunkSize === null) {
15
+ return bytes;
16
+ }
17
+ const newBuffer = new Uint8Array(bytes);
18
+ for (let i = 0; i < newBuffer.length; i += chunkSize) {
19
+ const slice = newBuffer.slice(i, i + chunkSize);
20
+ slice.reverse();
21
+ newBuffer.set(slice, i);
22
+ }
23
+ return newBuffer;
24
+ };
25
+ exports.postprocessBytes = postprocessBytes;
@@ -33,11 +33,12 @@ const getSeekingHintsFromMp4 = ({ structureState, isoState, mp4HeaderSegment, me
33
33
  };
34
34
  };
35
35
  exports.getSeekingHintsFromMp4 = getSeekingHintsFromMp4;
36
- const setSeekingHintsForMp4 = ({ hints, state, }) => {
37
- state.iso.moov.setMoovBox({
38
- moovBox: hints.moovBox,
39
- precomputed: true,
40
- });
36
+ // eslint-disable-next-line no-empty-pattern
37
+ const setSeekingHintsForMp4 = ({}) => {
38
+ // state.iso.moov.setMoovBox({
39
+ // moovBox: hints.moovBox,
40
+ // precomputed: true,
41
+ // });
41
42
  // state.iso.mfra.setFromSeekingHints(hints);
42
43
  // state.iso.moof.setMoofBoxes(hints.moofBoxes);
43
44
  // TODO: Make use of these seeking hints and make tests pass
@@ -0,0 +1,6 @@
1
+ import type { TrakBox } from './trak/trak';
2
+ type ShouldGroup = {
3
+ bigEndian: boolean;
4
+ };
5
+ export declare const shouldGroupAudioSamples: (trakBox: TrakBox) => ShouldGroup | null;
6
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldGroupAudioSamples = void 0;
4
+ const get_audio_codec_1 = require("../../get-audio-codec");
5
+ const shouldGroupAudioSamples = (trakBox) => {
6
+ const isLpcm = (0, get_audio_codec_1.isLpcmAudioCodec)(trakBox);
7
+ const isIn24 = (0, get_audio_codec_1.isIn24AudioCodec)(trakBox);
8
+ const isTwos = (0, get_audio_codec_1.isTwosAudioCodec)(trakBox);
9
+ if (isLpcm || isIn24 || isTwos) {
10
+ return {
11
+ bigEndian: isTwos || isIn24,
12
+ };
13
+ }
14
+ return null;
15
+ };
16
+ exports.shouldGroupAudioSamples = shouldGroupAudioSamples;
@@ -3569,6 +3569,9 @@ var isLpcmAudioCodec = (trak) => {
3569
3569
  var isIn24AudioCodec = (trak) => {
3570
3570
  return getAudioCodecFromTrak(trak)?.format === "in24";
3571
3571
  };
3572
+ var isTwosAudioCodec = (trak) => {
3573
+ return getAudioCodecFromTrak(trak)?.format === "twos";
3574
+ };
3572
3575
  var getAudioCodecStringFromTrak = (trak) => {
3573
3576
  const codec = getAudioCodecFromTrak(trak);
3574
3577
  if (!codec) {
@@ -3580,10 +3583,16 @@ var getAudioCodecStringFromTrak = (trak) => {
3580
3583
  description: codec.description
3581
3584
  };
3582
3585
  }
3586
+ if (codec.format === "twos") {
3587
+ return {
3588
+ codecString: "pcm-s16",
3589
+ description: codec.description
3590
+ };
3591
+ }
3583
3592
  if (codec.format === "in24") {
3584
3593
  return {
3585
3594
  codecString: "pcm-s24",
3586
- description: undefined
3595
+ description: codec.description
3587
3596
  };
3588
3597
  }
3589
3598
  const codecStringWithoutMp3Exception = [
@@ -6642,7 +6651,9 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
6642
6651
  duration: duration2,
6643
6652
  isKeyframe: keyframe,
6644
6653
  size,
6645
- chunk: 0
6654
+ chunk: 0,
6655
+ bigEndian: false,
6656
+ chunkSize: null
6646
6657
  };
6647
6658
  samples.push(samplePosition);
6648
6659
  offset += size;
@@ -6727,7 +6738,9 @@ var getSamplePositions = ({
6727
6738
  dts,
6728
6739
  cts,
6729
6740
  duration: delta,
6730
- chunk: i
6741
+ chunk: i,
6742
+ bigEndian: false,
6743
+ chunkSize: null
6731
6744
  });
6732
6745
  dts += delta;
6733
6746
  offsetInThisChunk += size;
@@ -6737,7 +6750,10 @@ var getSamplePositions = ({
6737
6750
  };
6738
6751
 
6739
6752
  // src/get-sample-positions-from-mp4.ts
6740
- var getGroupedSamplesPositionsFromMp4 = (trakBox) => {
6753
+ var getGroupedSamplesPositionsFromMp4 = ({
6754
+ trakBox,
6755
+ bigEndian
6756
+ }) => {
6741
6757
  const stscBox = getStscBox(trakBox);
6742
6758
  const stszBox = getStszBox(trakBox);
6743
6759
  const stcoBox = getStcoBox(trakBox);
@@ -6769,20 +6785,37 @@ var getGroupedSamplesPositionsFromMp4 = (trakBox) => {
6769
6785
  offset: Number(entry),
6770
6786
  size: stszBox.sampleSize * stscEntry.samplesPerChunk,
6771
6787
  duration: stscEntry.samplesPerChunk,
6772
- isKeyframe: true
6788
+ isKeyframe: true,
6789
+ bigEndian,
6790
+ chunkSize: stszBox.sampleSize
6773
6791
  });
6774
6792
  timestamp += stscEntry.samplesPerChunk;
6775
6793
  }
6776
6794
  return samples;
6777
6795
  };
6778
6796
 
6797
+ // src/containers/iso-base-media/should-group-audio-samples.ts
6798
+ var shouldGroupAudioSamples = (trakBox) => {
6799
+ const isLpcm = isLpcmAudioCodec(trakBox);
6800
+ const isIn24 = isIn24AudioCodec(trakBox);
6801
+ const isTwos = isTwosAudioCodec(trakBox);
6802
+ if (isLpcm || isIn24 || isTwos) {
6803
+ return {
6804
+ bigEndian: isTwos || isIn24
6805
+ };
6806
+ }
6807
+ return null;
6808
+ };
6809
+
6779
6810
  // src/containers/iso-base-media/collect-sample-positions-from-trak.ts
6780
6811
  var collectSamplePositionsFromTrak = (trakBox) => {
6781
- const isLpcm = isLpcmAudioCodec(trakBox);
6812
+ const shouldGroupSamples = shouldGroupAudioSamples(trakBox);
6782
6813
  const timescaleAndDuration = getTimescaleAndDuration(trakBox);
6783
- const isIn24 = isIn24AudioCodec(trakBox);
6784
- if (isLpcm || isIn24) {
6785
- return getGroupedSamplesPositionsFromMp4(trakBox);
6814
+ if (shouldGroupSamples) {
6815
+ return getGroupedSamplesPositionsFromMp4({
6816
+ trakBox,
6817
+ bigEndian: shouldGroupSamples.bigEndian
6818
+ });
6786
6819
  }
6787
6820
  const stszBox = getStszBox(trakBox);
6788
6821
  const stcoBox = getStcoBox(trakBox);
@@ -8211,15 +8244,7 @@ var getSeekingHintsFromMp4 = ({
8211
8244
  mfraAlreadyLoaded: isoState.mfra.getIfAlreadyLoaded()
8212
8245
  };
8213
8246
  };
8214
- var setSeekingHintsForMp4 = ({
8215
- hints,
8216
- state
8217
- }) => {
8218
- state.iso.moov.setMoovBox({
8219
- moovBox: hints.moovBox,
8220
- precomputed: true
8221
- });
8222
- };
8247
+ var setSeekingHintsForMp4 = ({}) => {};
8223
8248
 
8224
8249
  // src/containers/transport-stream/seeking-hints.ts
8225
8250
  var getSeekingHintsFromTransportStream = (transportStream, tracksState) => {
@@ -10017,6 +10042,27 @@ var getMoovAtom = async ({
10017
10042
  return moov;
10018
10043
  };
10019
10044
 
10045
+ // src/containers/iso-base-media/mdat/postprocess-bytes.ts
10046
+ var postprocessBytes = ({
10047
+ bytes,
10048
+ bigEndian,
10049
+ chunkSize
10050
+ }) => {
10051
+ if (!bigEndian) {
10052
+ return bytes;
10053
+ }
10054
+ if (chunkSize === null) {
10055
+ return bytes;
10056
+ }
10057
+ const newBuffer = new Uint8Array(bytes);
10058
+ for (let i = 0;i < newBuffer.length; i += chunkSize) {
10059
+ const slice = newBuffer.slice(i, i + chunkSize);
10060
+ slice.reverse();
10061
+ newBuffer.set(slice, i);
10062
+ }
10063
+ return newBuffer;
10064
+ };
10065
+
10020
10066
  // src/containers/iso-base-media/mdat/mdat.ts
10021
10067
  var parseMdatSection = async (state) => {
10022
10068
  const mediaSection = getCurrentMediaSection({
@@ -10063,8 +10109,12 @@ var parseMdatSection = async (state) => {
10063
10109
  if (iterator.bytesRemaining() < samplesWithIndex.samplePosition.size) {
10064
10110
  return null;
10065
10111
  }
10066
- const bytes = iterator.getSlice(samplesWithIndex.samplePosition.size);
10067
- const { cts, dts, duration: duration2, isKeyframe, offset } = samplesWithIndex.samplePosition;
10112
+ const { cts, dts, duration: duration2, isKeyframe, offset, bigEndian, chunkSize } = samplesWithIndex.samplePosition;
10113
+ const bytes = postprocessBytes({
10114
+ bytes: iterator.getSlice(samplesWithIndex.samplePosition.size),
10115
+ bigEndian,
10116
+ chunkSize
10117
+ });
10068
10118
  if (samplesWithIndex.track.type === "audio") {
10069
10119
  await emitAudioSample({
10070
10120
  trackId: samplesWithIndex.track.trackId,
@@ -14970,7 +15020,7 @@ var downloadAndParseMedia = async (options) => {
14970
15020
  return returnValue;
14971
15021
  };
14972
15022
  // src/version.ts
14973
- var VERSION = "4.0.287";
15023
+ var VERSION = "4.0.288";
14974
15024
 
14975
15025
  // src/index.ts
14976
15026
  var MediaParserInternals = {
@@ -4362,6 +4362,9 @@ var isLpcmAudioCodec = (trak) => {
4362
4362
  var isIn24AudioCodec = (trak) => {
4363
4363
  return getAudioCodecFromTrak(trak)?.format === "in24";
4364
4364
  };
4365
+ var isTwosAudioCodec = (trak) => {
4366
+ return getAudioCodecFromTrak(trak)?.format === "twos";
4367
+ };
4365
4368
  var getAudioCodecStringFromTrak = (trak) => {
4366
4369
  const codec = getAudioCodecFromTrak(trak);
4367
4370
  if (!codec) {
@@ -4373,10 +4376,16 @@ var getAudioCodecStringFromTrak = (trak) => {
4373
4376
  description: codec.description
4374
4377
  };
4375
4378
  }
4379
+ if (codec.format === "twos") {
4380
+ return {
4381
+ codecString: "pcm-s16",
4382
+ description: codec.description
4383
+ };
4384
+ }
4376
4385
  if (codec.format === "in24") {
4377
4386
  return {
4378
4387
  codecString: "pcm-s24",
4379
- description: undefined
4388
+ description: codec.description
4380
4389
  };
4381
4390
  }
4382
4391
  const codecStringWithoutMp3Exception = [
@@ -4556,7 +4565,9 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
4556
4565
  duration: duration2,
4557
4566
  isKeyframe: keyframe,
4558
4567
  size,
4559
- chunk: 0
4568
+ chunk: 0,
4569
+ bigEndian: false,
4570
+ chunkSize: null
4560
4571
  };
4561
4572
  samples.push(samplePosition);
4562
4573
  offset += size;
@@ -4641,7 +4652,9 @@ var getSamplePositions = ({
4641
4652
  dts,
4642
4653
  cts,
4643
4654
  duration: delta,
4644
- chunk: i
4655
+ chunk: i,
4656
+ bigEndian: false,
4657
+ chunkSize: null
4645
4658
  });
4646
4659
  dts += delta;
4647
4660
  offsetInThisChunk += size;
@@ -4651,7 +4664,10 @@ var getSamplePositions = ({
4651
4664
  };
4652
4665
 
4653
4666
  // src/get-sample-positions-from-mp4.ts
4654
- var getGroupedSamplesPositionsFromMp4 = (trakBox) => {
4667
+ var getGroupedSamplesPositionsFromMp4 = ({
4668
+ trakBox,
4669
+ bigEndian
4670
+ }) => {
4655
4671
  const stscBox = getStscBox(trakBox);
4656
4672
  const stszBox = getStszBox(trakBox);
4657
4673
  const stcoBox = getStcoBox(trakBox);
@@ -4683,20 +4699,37 @@ var getGroupedSamplesPositionsFromMp4 = (trakBox) => {
4683
4699
  offset: Number(entry),
4684
4700
  size: stszBox.sampleSize * stscEntry.samplesPerChunk,
4685
4701
  duration: stscEntry.samplesPerChunk,
4686
- isKeyframe: true
4702
+ isKeyframe: true,
4703
+ bigEndian,
4704
+ chunkSize: stszBox.sampleSize
4687
4705
  });
4688
4706
  timestamp += stscEntry.samplesPerChunk;
4689
4707
  }
4690
4708
  return samples;
4691
4709
  };
4692
4710
 
4711
+ // src/containers/iso-base-media/should-group-audio-samples.ts
4712
+ var shouldGroupAudioSamples = (trakBox) => {
4713
+ const isLpcm = isLpcmAudioCodec(trakBox);
4714
+ const isIn24 = isIn24AudioCodec(trakBox);
4715
+ const isTwos = isTwosAudioCodec(trakBox);
4716
+ if (isLpcm || isIn24 || isTwos) {
4717
+ return {
4718
+ bigEndian: isTwos || isIn24
4719
+ };
4720
+ }
4721
+ return null;
4722
+ };
4723
+
4693
4724
  // src/containers/iso-base-media/collect-sample-positions-from-trak.ts
4694
4725
  var collectSamplePositionsFromTrak = (trakBox) => {
4695
- const isLpcm = isLpcmAudioCodec(trakBox);
4726
+ const shouldGroupSamples = shouldGroupAudioSamples(trakBox);
4696
4727
  const timescaleAndDuration = getTimescaleAndDuration(trakBox);
4697
- const isIn24 = isIn24AudioCodec(trakBox);
4698
- if (isLpcm || isIn24) {
4699
- return getGroupedSamplesPositionsFromMp4(trakBox);
4728
+ if (shouldGroupSamples) {
4729
+ return getGroupedSamplesPositionsFromMp4({
4730
+ trakBox,
4731
+ bigEndian: shouldGroupSamples.bigEndian
4732
+ });
4700
4733
  }
4701
4734
  const stszBox = getStszBox(trakBox);
4702
4735
  const stcoBox = getStcoBox(trakBox);
@@ -6440,15 +6473,7 @@ var getSeekingHintsFromMp4 = ({
6440
6473
  mfraAlreadyLoaded: isoState.mfra.getIfAlreadyLoaded()
6441
6474
  };
6442
6475
  };
6443
- var setSeekingHintsForMp4 = ({
6444
- hints,
6445
- state
6446
- }) => {
6447
- state.iso.moov.setMoovBox({
6448
- moovBox: hints.moovBox,
6449
- precomputed: true
6450
- });
6451
- };
6476
+ var setSeekingHintsForMp4 = ({}) => {};
6452
6477
 
6453
6478
  // src/containers/transport-stream/seeking-hints.ts
6454
6479
  var getSeekingHintsFromTransportStream = (transportStream, tracksState) => {
@@ -10040,6 +10065,27 @@ var getMoovAtom = async ({
10040
10065
  return moov;
10041
10066
  };
10042
10067
 
10068
+ // src/containers/iso-base-media/mdat/postprocess-bytes.ts
10069
+ var postprocessBytes = ({
10070
+ bytes,
10071
+ bigEndian,
10072
+ chunkSize
10073
+ }) => {
10074
+ if (!bigEndian) {
10075
+ return bytes;
10076
+ }
10077
+ if (chunkSize === null) {
10078
+ return bytes;
10079
+ }
10080
+ const newBuffer = new Uint8Array(bytes);
10081
+ for (let i = 0;i < newBuffer.length; i += chunkSize) {
10082
+ const slice = newBuffer.slice(i, i + chunkSize);
10083
+ slice.reverse();
10084
+ newBuffer.set(slice, i);
10085
+ }
10086
+ return newBuffer;
10087
+ };
10088
+
10043
10089
  // src/containers/iso-base-media/mdat/mdat.ts
10044
10090
  var parseMdatSection = async (state) => {
10045
10091
  const mediaSection = getCurrentMediaSection({
@@ -10086,8 +10132,12 @@ var parseMdatSection = async (state) => {
10086
10132
  if (iterator.bytesRemaining() < samplesWithIndex.samplePosition.size) {
10087
10133
  return null;
10088
10134
  }
10089
- const bytes = iterator.getSlice(samplesWithIndex.samplePosition.size);
10090
- const { cts, dts, duration: duration2, isKeyframe, offset } = samplesWithIndex.samplePosition;
10135
+ const { cts, dts, duration: duration2, isKeyframe, offset, bigEndian, chunkSize } = samplesWithIndex.samplePosition;
10136
+ const bytes = postprocessBytes({
10137
+ bytes: iterator.getSlice(samplesWithIndex.samplePosition.size),
10138
+ bigEndian,
10139
+ chunkSize
10140
+ });
10091
10141
  if (samplesWithIndex.track.type === "audio") {
10092
10142
  await emitAudioSample({
10093
10143
  trackId: samplesWithIndex.track.trackId,
@@ -4298,6 +4298,9 @@ var isLpcmAudioCodec = (trak) => {
4298
4298
  var isIn24AudioCodec = (trak) => {
4299
4299
  return getAudioCodecFromTrak(trak)?.format === "in24";
4300
4300
  };
4301
+ var isTwosAudioCodec = (trak) => {
4302
+ return getAudioCodecFromTrak(trak)?.format === "twos";
4303
+ };
4301
4304
  var getAudioCodecStringFromTrak = (trak) => {
4302
4305
  const codec = getAudioCodecFromTrak(trak);
4303
4306
  if (!codec) {
@@ -4309,10 +4312,16 @@ var getAudioCodecStringFromTrak = (trak) => {
4309
4312
  description: codec.description
4310
4313
  };
4311
4314
  }
4315
+ if (codec.format === "twos") {
4316
+ return {
4317
+ codecString: "pcm-s16",
4318
+ description: codec.description
4319
+ };
4320
+ }
4312
4321
  if (codec.format === "in24") {
4313
4322
  return {
4314
4323
  codecString: "pcm-s24",
4315
- description: undefined
4324
+ description: codec.description
4316
4325
  };
4317
4326
  }
4318
4327
  const codecStringWithoutMp3Exception = [
@@ -4492,7 +4501,9 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
4492
4501
  duration: duration2,
4493
4502
  isKeyframe: keyframe,
4494
4503
  size,
4495
- chunk: 0
4504
+ chunk: 0,
4505
+ bigEndian: false,
4506
+ chunkSize: null
4496
4507
  };
4497
4508
  samples.push(samplePosition);
4498
4509
  offset += size;
@@ -4577,7 +4588,9 @@ var getSamplePositions = ({
4577
4588
  dts,
4578
4589
  cts,
4579
4590
  duration: delta,
4580
- chunk: i
4591
+ chunk: i,
4592
+ bigEndian: false,
4593
+ chunkSize: null
4581
4594
  });
4582
4595
  dts += delta;
4583
4596
  offsetInThisChunk += size;
@@ -4587,7 +4600,10 @@ var getSamplePositions = ({
4587
4600
  };
4588
4601
 
4589
4602
  // src/get-sample-positions-from-mp4.ts
4590
- var getGroupedSamplesPositionsFromMp4 = (trakBox) => {
4603
+ var getGroupedSamplesPositionsFromMp4 = ({
4604
+ trakBox,
4605
+ bigEndian
4606
+ }) => {
4591
4607
  const stscBox = getStscBox(trakBox);
4592
4608
  const stszBox = getStszBox(trakBox);
4593
4609
  const stcoBox = getStcoBox(trakBox);
@@ -4619,20 +4635,37 @@ var getGroupedSamplesPositionsFromMp4 = (trakBox) => {
4619
4635
  offset: Number(entry),
4620
4636
  size: stszBox.sampleSize * stscEntry.samplesPerChunk,
4621
4637
  duration: stscEntry.samplesPerChunk,
4622
- isKeyframe: true
4638
+ isKeyframe: true,
4639
+ bigEndian,
4640
+ chunkSize: stszBox.sampleSize
4623
4641
  });
4624
4642
  timestamp += stscEntry.samplesPerChunk;
4625
4643
  }
4626
4644
  return samples;
4627
4645
  };
4628
4646
 
4647
+ // src/containers/iso-base-media/should-group-audio-samples.ts
4648
+ var shouldGroupAudioSamples = (trakBox) => {
4649
+ const isLpcm = isLpcmAudioCodec(trakBox);
4650
+ const isIn24 = isIn24AudioCodec(trakBox);
4651
+ const isTwos = isTwosAudioCodec(trakBox);
4652
+ if (isLpcm || isIn24 || isTwos) {
4653
+ return {
4654
+ bigEndian: isTwos || isIn24
4655
+ };
4656
+ }
4657
+ return null;
4658
+ };
4659
+
4629
4660
  // src/containers/iso-base-media/collect-sample-positions-from-trak.ts
4630
4661
  var collectSamplePositionsFromTrak = (trakBox) => {
4631
- const isLpcm = isLpcmAudioCodec(trakBox);
4662
+ const shouldGroupSamples = shouldGroupAudioSamples(trakBox);
4632
4663
  const timescaleAndDuration = getTimescaleAndDuration(trakBox);
4633
- const isIn24 = isIn24AudioCodec(trakBox);
4634
- if (isLpcm || isIn24) {
4635
- return getGroupedSamplesPositionsFromMp4(trakBox);
4664
+ if (shouldGroupSamples) {
4665
+ return getGroupedSamplesPositionsFromMp4({
4666
+ trakBox,
4667
+ bigEndian: shouldGroupSamples.bigEndian
4668
+ });
4636
4669
  }
4637
4670
  const stszBox = getStszBox(trakBox);
4638
4671
  const stcoBox = getStcoBox(trakBox);
@@ -6376,15 +6409,7 @@ var getSeekingHintsFromMp4 = ({
6376
6409
  mfraAlreadyLoaded: isoState.mfra.getIfAlreadyLoaded()
6377
6410
  };
6378
6411
  };
6379
- var setSeekingHintsForMp4 = ({
6380
- hints,
6381
- state
6382
- }) => {
6383
- state.iso.moov.setMoovBox({
6384
- moovBox: hints.moovBox,
6385
- precomputed: true
6386
- });
6387
- };
6412
+ var setSeekingHintsForMp4 = ({}) => {};
6388
6413
 
6389
6414
  // src/containers/transport-stream/seeking-hints.ts
6390
6415
  var getSeekingHintsFromTransportStream = (transportStream, tracksState) => {
@@ -9976,6 +10001,27 @@ var getMoovAtom = async ({
9976
10001
  return moov;
9977
10002
  };
9978
10003
 
10004
+ // src/containers/iso-base-media/mdat/postprocess-bytes.ts
10005
+ var postprocessBytes = ({
10006
+ bytes,
10007
+ bigEndian,
10008
+ chunkSize
10009
+ }) => {
10010
+ if (!bigEndian) {
10011
+ return bytes;
10012
+ }
10013
+ if (chunkSize === null) {
10014
+ return bytes;
10015
+ }
10016
+ const newBuffer = new Uint8Array(bytes);
10017
+ for (let i = 0;i < newBuffer.length; i += chunkSize) {
10018
+ const slice = newBuffer.slice(i, i + chunkSize);
10019
+ slice.reverse();
10020
+ newBuffer.set(slice, i);
10021
+ }
10022
+ return newBuffer;
10023
+ };
10024
+
9979
10025
  // src/containers/iso-base-media/mdat/mdat.ts
9980
10026
  var parseMdatSection = async (state) => {
9981
10027
  const mediaSection = getCurrentMediaSection({
@@ -10022,8 +10068,12 @@ var parseMdatSection = async (state) => {
10022
10068
  if (iterator.bytesRemaining() < samplesWithIndex.samplePosition.size) {
10023
10069
  return null;
10024
10070
  }
10025
- const bytes = iterator.getSlice(samplesWithIndex.samplePosition.size);
10026
- const { cts, dts, duration: duration2, isKeyframe, offset } = samplesWithIndex.samplePosition;
10071
+ const { cts, dts, duration: duration2, isKeyframe, offset, bigEndian, chunkSize } = samplesWithIndex.samplePosition;
10072
+ const bytes = postprocessBytes({
10073
+ bytes: iterator.getSlice(samplesWithIndex.samplePosition.size),
10074
+ bigEndian,
10075
+ chunkSize
10076
+ });
10027
10077
  if (samplesWithIndex.track.type === "audio") {
10028
10078
  await emitAudioSample({
10029
10079
  trackId: samplesWithIndex.track.trackId,
@@ -16,6 +16,7 @@ export declare const getSampleRate: (trak: TrakBox) => number | null;
16
16
  export declare const getAudioCodecFromTrak: (trak: TrakBox) => AudioCodecInfo | null;
17
17
  export declare const isLpcmAudioCodec: (trak: TrakBox) => boolean;
18
18
  export declare const isIn24AudioCodec: (trak: TrakBox) => boolean;
19
+ export declare const isTwosAudioCodec: (trak: TrakBox) => boolean;
19
20
  export declare const getAudioCodecFromIso: (moov: MoovBox) => AudioCodecInfo | null;
20
21
  export declare const getAudioCodecStringFromTrak: (trak: TrakBox) => {
21
22
  codecString: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAudioCodecFromTrack = exports.getAudioCodecStringFromTrak = exports.getAudioCodecFromIso = exports.isIn24AudioCodec = exports.isLpcmAudioCodec = exports.getAudioCodecFromTrak = exports.getSampleRate = exports.getNumberOfChannelsFromTrak = exports.getCodecPrivateFromTrak = exports.hasAudioCodec = exports.getAudioCodec = void 0;
3
+ exports.getAudioCodecFromTrack = exports.getAudioCodecStringFromTrak = exports.getAudioCodecFromIso = exports.isTwosAudioCodec = exports.isIn24AudioCodec = exports.isLpcmAudioCodec = exports.getAudioCodecFromTrak = exports.getSampleRate = exports.getNumberOfChannelsFromTrak = exports.getCodecPrivateFromTrak = exports.hasAudioCodec = exports.getAudioCodec = void 0;
4
4
  const traversal_1 = require("./containers/iso-base-media/traversal");
5
5
  const get_fps_1 = require("./get-fps");
6
6
  const get_tracks_1 = require("./get-tracks");
@@ -153,6 +153,11 @@ const isIn24AudioCodec = (trak) => {
153
153
  return ((_a = (0, exports.getAudioCodecFromTrak)(trak)) === null || _a === void 0 ? void 0 : _a.format) === 'in24';
154
154
  };
155
155
  exports.isIn24AudioCodec = isIn24AudioCodec;
156
+ const isTwosAudioCodec = (trak) => {
157
+ var _a;
158
+ return ((_a = (0, exports.getAudioCodecFromTrak)(trak)) === null || _a === void 0 ? void 0 : _a.format) === 'twos';
159
+ };
160
+ exports.isTwosAudioCodec = isTwosAudioCodec;
156
161
  const getAudioCodecFromIso = (moov) => {
157
162
  const traks = (0, traversal_1.getTraks)(moov);
158
163
  const trakBox = traks.find((b) => b.type === 'trak-box' && (0, get_fps_1.trakBoxContainsAudio)(b));
@@ -173,10 +178,16 @@ const getAudioCodecStringFromTrak = (trak) => {
173
178
  description: codec.description,
174
179
  };
175
180
  }
181
+ if (codec.format === 'twos') {
182
+ return {
183
+ codecString: 'pcm-s16',
184
+ description: codec.description,
185
+ };
186
+ }
176
187
  if (codec.format === 'in24') {
177
188
  return {
178
189
  codecString: 'pcm-s24',
179
- description: undefined,
190
+ description: codec.description,
180
191
  };
181
192
  }
182
193
  const codecStringWithoutMp3Exception = [
@@ -1,3 +1,6 @@
1
1
  import type { TrakBox } from './containers/iso-base-media/trak/trak';
2
2
  import type { SamplePosition } from './get-sample-positions';
3
- export declare const getGroupedSamplesPositionsFromMp4: (trakBox: TrakBox) => SamplePosition[];
3
+ export declare const getGroupedSamplesPositionsFromMp4: ({ trakBox, bigEndian, }: {
4
+ trakBox: TrakBox;
5
+ bigEndian: boolean;
6
+ }) => SamplePosition[];
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.getGroupedSamplesPositionsFromMp4 = void 0;
6
6
  const traversal_1 = require("./containers/iso-base-media/traversal");
7
7
  // example video: mehmet.mov
8
- const getGroupedSamplesPositionsFromMp4 = (trakBox) => {
8
+ const getGroupedSamplesPositionsFromMp4 = ({ trakBox, bigEndian, }) => {
9
9
  const stscBox = (0, traversal_1.getStscBox)(trakBox);
10
10
  const stszBox = (0, traversal_1.getStszBox)(trakBox);
11
11
  const stcoBox = (0, traversal_1.getStcoBox)(trakBox);
@@ -38,6 +38,8 @@ const getGroupedSamplesPositionsFromMp4 = (trakBox) => {
38
38
  size: stszBox.sampleSize * stscEntry.samplesPerChunk,
39
39
  duration: stscEntry.samplesPerChunk,
40
40
  isKeyframe: true,
41
+ bigEndian,
42
+ chunkSize: stszBox.sampleSize,
41
43
  });
42
44
  timestamp += stscEntry.samplesPerChunk;
43
45
  }
@@ -12,6 +12,8 @@ export type SamplePosition = {
12
12
  cts: number;
13
13
  duration: number;
14
14
  chunk: number;
15
+ bigEndian: boolean;
16
+ chunkSize: number | null;
15
17
  };
16
18
  export declare const getSamplePositions: ({ stcoBox, stszBox, stscBox, stssBox, sttsBox, cttsBox, }: {
17
19
  stcoBox: StcoBox;
@@ -45,6 +45,8 @@ const getSamplePositions = ({ stcoBox, stszBox, stscBox, stssBox, sttsBox, cttsB
45
45
  cts,
46
46
  duration: delta,
47
47
  chunk: i,
48
+ bigEndian: false,
49
+ chunkSize: null,
48
50
  });
49
51
  dts += delta;
50
52
  offsetInThisChunk += size;
@@ -52,6 +52,8 @@ const getSamplesFromTraf = (trafSegment, moofOffset) => {
52
52
  isKeyframe: keyframe,
53
53
  size,
54
54
  chunk: 0,
55
+ bigEndian: false,
56
+ chunkSize: null,
55
57
  };
56
58
  samples.push(samplePosition);
57
59
  offset += size;
@@ -0,0 +1,11 @@
1
+ export type AudioSampleOffset = {
2
+ timeInSeconds: number;
3
+ offset: number;
4
+ durationInSeconds: number;
5
+ };
6
+ export declare const audioSampleMapState: () => {
7
+ addSample: (audioSampleOffset: AudioSampleOffset) => void;
8
+ getSamples: () => AudioSampleOffset[];
9
+ setFromSeekingHints: (newMap: AudioSampleOffset[]) => void;
10
+ };
11
+ export type AudioSampleMapState = ReturnType<typeof audioSampleMapState>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.audioSampleMapState = void 0;
4
+ const audioSampleMapState = () => {
5
+ // {[]}
6
+ let map = [];
7
+ const addSample = (audioSampleOffset) => {
8
+ if (map.find((m) => m.offset === audioSampleOffset.offset)) {
9
+ return;
10
+ }
11
+ map.push(audioSampleOffset);
12
+ };
13
+ return {
14
+ addSample,
15
+ getSamples: () => map,
16
+ setFromSeekingHints: (newMap) => {
17
+ map = newMap;
18
+ },
19
+ };
20
+ };
21
+ exports.audioSampleMapState = audioSampleMapState;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.287";
1
+ export declare const VERSION = "4.0.288";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Automatically generated on publish
5
- exports.VERSION = '4.0.287';
5
+ exports.VERSION = '4.0.288';
package/package.json CHANGED
@@ -3,15 +3,15 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/media-parser"
4
4
  },
5
5
  "name": "@remotion/media-parser",
6
- "version": "4.0.287",
6
+ "version": "4.0.288",
7
7
  "main": "dist/index.js",
8
8
  "sideEffects": false,
9
9
  "devDependencies": {
10
10
  "@types/wicg-file-system-access": "2023.10.5",
11
11
  "eslint": "9.19.0",
12
12
  "@types/bun": "1.2.8",
13
- "@remotion/example-videos": "4.0.287",
14
- "@remotion/eslint-config-internal": "4.0.287"
13
+ "@remotion/example-videos": "4.0.288",
14
+ "@remotion/eslint-config-internal": "4.0.288"
15
15
  },
16
16
  "publishConfig": {
17
17
  "access": "public"