@remotion/media-parser 4.0.278 → 4.0.280

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.
Files changed (145) hide show
  1. package/dist/check-if-done.d.ts +2 -0
  2. package/dist/check-if-done.js +34 -0
  3. package/dist/containers/aac/parse-aac.js +15 -10
  4. package/dist/containers/avc/parse-avc.js +1 -1
  5. package/dist/containers/flac/get-block-size.d.ts +1 -1
  6. package/dist/containers/flac/get-channel-count.d.ts +2 -2
  7. package/dist/containers/flac/get-sample-rate.d.ts +1 -1
  8. package/dist/containers/flac/parse-flac-frame.d.ts +1 -1
  9. package/dist/containers/flac/parse-flac-frame.js +16 -11
  10. package/dist/containers/flac/parse-flac.d.ts +1 -1
  11. package/dist/containers/flac/parse-header.d.ts +1 -1
  12. package/dist/containers/flac/parse-metadata.d.ts +1 -1
  13. package/dist/containers/flac/parse-streaminfo.d.ts +1 -1
  14. package/dist/containers/flac/parse-unknown-block.d.ts +1 -1
  15. package/dist/containers/iso-base-media/esds/decoder-specific-config.d.ts +1 -1
  16. package/dist/containers/iso-base-media/esds/esds-descriptors.d.ts +1 -1
  17. package/dist/containers/iso-base-media/esds/esds.d.ts +1 -1
  18. package/dist/containers/iso-base-media/ftyp.d.ts +1 -1
  19. package/dist/containers/iso-base-media/get-moov-atom.js +9 -3
  20. package/dist/containers/iso-base-media/get-seeking-from-mp4.d.ts +5 -0
  21. package/dist/containers/iso-base-media/get-seeking-from-mp4.js +56 -0
  22. package/dist/containers/iso-base-media/mdat/mdat.js +29 -20
  23. package/dist/containers/iso-base-media/mdhd.d.ts +1 -1
  24. package/dist/containers/iso-base-media/meta/hdlr.d.ts +1 -1
  25. package/dist/containers/iso-base-media/meta/ilst.d.ts +1 -1
  26. package/dist/containers/iso-base-media/mvhd.d.ts +1 -1
  27. package/dist/containers/iso-base-media/mvhd.js +1 -1
  28. package/dist/containers/iso-base-media/parse-icc-profile.js +1 -1
  29. package/dist/containers/iso-base-media/stsd/av1c.d.ts +1 -1
  30. package/dist/containers/iso-base-media/stsd/avcc.d.ts +1 -1
  31. package/dist/containers/iso-base-media/stsd/colr.d.ts +1 -1
  32. package/dist/containers/iso-base-media/stsd/ctts.d.ts +1 -1
  33. package/dist/containers/iso-base-media/stsd/hvcc.d.ts +1 -1
  34. package/dist/containers/iso-base-media/stsd/keys.d.ts +1 -1
  35. package/dist/containers/iso-base-media/stsd/pasp.d.ts +1 -1
  36. package/dist/containers/iso-base-media/stsd/stco.d.ts +1 -1
  37. package/dist/containers/iso-base-media/stsd/stsc.d.ts +1 -1
  38. package/dist/containers/iso-base-media/stsd/stss.d.ts +1 -1
  39. package/dist/containers/iso-base-media/stsd/stsz.d.ts +1 -1
  40. package/dist/containers/iso-base-media/stsd/stts.d.ts +1 -1
  41. package/dist/containers/iso-base-media/tfdt.d.ts +1 -1
  42. package/dist/containers/iso-base-media/tfhd.d.ts +1 -1
  43. package/dist/containers/iso-base-media/tkhd.d.ts +1 -1
  44. package/dist/containers/iso-base-media/trun.d.ts +1 -1
  45. package/dist/containers/m3u/parse-m3u-manifest.d.ts +1 -1
  46. package/dist/containers/mp3/id3-v1.d.ts +1 -1
  47. package/dist/containers/mp3/parse-mpeg-header.js +14 -9
  48. package/dist/containers/riff/is-movi.d.ts +1 -1
  49. package/dist/containers/riff/parse-avih.d.ts +1 -1
  50. package/dist/containers/riff/parse-isft.d.ts +1 -1
  51. package/dist/containers/riff/parse-movi.js +29 -20
  52. package/dist/containers/riff/parse-strf.d.ts +1 -1
  53. package/dist/containers/riff/parse-strh.d.ts +1 -1
  54. package/dist/containers/transport-stream/adts-header.js +1 -1
  55. package/dist/containers/transport-stream/discard-rest-of-packet.d.ts +1 -1
  56. package/dist/containers/transport-stream/handle-aac-packet.js +6 -1
  57. package/dist/containers/transport-stream/handle-avc-packet.js +6 -1
  58. package/dist/containers/transport-stream/parse-pat.d.ts +1 -1
  59. package/dist/containers/transport-stream/parse-pes.d.ts +1 -1
  60. package/dist/containers/transport-stream/parse-pmt.d.ts +1 -1
  61. package/dist/containers/wav/parse-video-section.js +15 -10
  62. package/dist/containers/webm/av1-codec-private.js +1 -1
  63. package/dist/containers/webm/description.js +1 -1
  64. package/dist/containers/webm/get-sample-from-block.js +1 -1
  65. package/dist/containers/webm/make-track.js +1 -1
  66. package/dist/containers/webm/parse-ebml.js +16 -3
  67. package/dist/containers/webm/segments/block-simple-block-flags.d.ts +1 -1
  68. package/dist/emit-all-info.d.ts +3 -0
  69. package/dist/emit-all-info.js +30 -0
  70. package/dist/emit-audio-sample.d.ts +12 -0
  71. package/dist/emit-audio-sample.js +14 -0
  72. package/dist/emit-available-info.d.ts +2 -7
  73. package/dist/emit-available-info.js +34 -31
  74. package/dist/esm/index.mjs +1936 -1635
  75. package/dist/esm/worker-server-entry.mjs +855 -554
  76. package/dist/esm/worker-web-entry.mjs +855 -554
  77. package/dist/fields.d.ts +61 -0
  78. package/dist/fields.js +2 -0
  79. package/dist/get-fields-from-callbacks.d.ts +2 -1
  80. package/dist/get-seeking-info.d.ts +4 -0
  81. package/dist/get-seeking-info.js +22 -0
  82. package/dist/has-all-info.d.ts +3 -5
  83. package/dist/has-all-info.js +3 -4
  84. package/dist/index.d.ts +53 -14
  85. package/dist/index.js +1 -1
  86. package/dist/init-video.d.ts +1 -4
  87. package/dist/init-video.js +2 -1
  88. package/dist/internal-parse-media.js +25 -188
  89. package/dist/{buffer-iterator.d.ts → iterator/buffer-iterator.d.ts} +12 -15
  90. package/dist/{buffer-iterator.js → iterator/buffer-iterator.js} +8 -116
  91. package/dist/iterator/buffer-manager.d.ts +18 -0
  92. package/dist/iterator/buffer-manager.js +86 -0
  93. package/dist/iterator/offset-counter.d.ts +10 -0
  94. package/dist/iterator/offset-counter.js +31 -0
  95. package/dist/make-hvc1-codec-strings.d.ts +1 -1
  96. package/dist/make-progress-object.d.ts +6 -0
  97. package/dist/make-progress-object.js +13 -0
  98. package/dist/media-parser-controller.d.ts +3 -0
  99. package/dist/media-parser-controller.js +4 -0
  100. package/dist/options.d.ts +1 -61
  101. package/dist/parse-loop.d.ts +8 -0
  102. package/dist/parse-loop.js +93 -0
  103. package/dist/parse-media-on-worker-entry.d.ts +2 -1
  104. package/dist/perform-seek.d.ts +2 -7
  105. package/dist/perform-seek.js +23 -24
  106. package/dist/print-timings.d.ts +2 -0
  107. package/dist/print-timings.js +12 -0
  108. package/dist/register-track.js +3 -0
  109. package/dist/run-parse-iteration.d.ts +1 -4
  110. package/dist/run-parse-iteration.js +1 -4
  111. package/dist/seek-backwards.d.ts +2 -0
  112. package/dist/seek-backwards.js +26 -0
  113. package/dist/seek-forwards.d.ts +2 -0
  114. package/dist/seek-forwards.js +28 -0
  115. package/dist/seek-signal.d.ts +22 -0
  116. package/dist/seek-signal.js +26 -0
  117. package/dist/seeking-info.d.ts +8 -0
  118. package/dist/seeking-info.js +2 -0
  119. package/dist/state/can-skip-tracks.d.ts +2 -2
  120. package/dist/state/can-skip-tracks.js +5 -2
  121. package/dist/state/emitted-fields.d.ts +1 -1
  122. package/dist/state/has-tracks-section.d.ts +2 -1
  123. package/dist/state/need-samples-for-fields.d.ts +1 -1
  124. package/dist/state/parser-state.d.ts +38 -8
  125. package/dist/state/parser-state.js +22 -2
  126. package/dist/state/sample-callbacks.d.ts +8 -3
  127. package/dist/state/sample-callbacks.js +16 -3
  128. package/dist/state/slow-duration-fps.js +15 -17
  129. package/dist/state/timings.d.ts +8 -0
  130. package/dist/state/timings.js +13 -0
  131. package/dist/state/video-section.d.ts +1 -1
  132. package/dist/state/webm.d.ts +1 -1
  133. package/dist/throttled-progress.d.ts +2 -3
  134. package/dist/version.d.ts +1 -1
  135. package/dist/version.js +1 -1
  136. package/dist/work-on-seek-request.d.ts +2 -0
  137. package/dist/work-on-seek-request.js +43 -0
  138. package/dist/worker/worker-types.d.ts +2 -1
  139. package/package.json +10 -10
  140. package/dist/parse-media-on-server-worker.d.ts +0 -2
  141. package/dist/parse-media-on-server-worker.js +0 -4
  142. package/dist/parse-media-on-web-worker.d.ts +0 -2
  143. package/dist/parse-media-on-web-worker.js +0 -4
  144. package/dist/worker.module.d.ts +0 -4
  145. package/dist/worker.module.js +0 -16
@@ -0,0 +1,2 @@
1
+ import type { ParserState } from './state/parser-state';
2
+ export declare const checkIfDone: (state: ParserState) => Promise<boolean>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIfDone = void 0;
4
+ const has_all_info_1 = require("./has-all-info");
5
+ const log_1 = require("./log");
6
+ const checkIfDone = async (state) => {
7
+ const startCheck = Date.now();
8
+ const hasAll = (0, has_all_info_1.hasAllInfo)({
9
+ state,
10
+ });
11
+ state.timings.timeCheckingIfDone += Date.now() - startCheck;
12
+ if (hasAll && state.mode === 'query') {
13
+ log_1.Log.verbose(state.logLevel, 'Got all info, skipping to the end.');
14
+ state.increaseSkippedBytes(state.contentLength - state.iterator.counter.getOffset());
15
+ return true;
16
+ }
17
+ if (state.iterator.counter.getOffset() === state.contentLength) {
18
+ if (state.getStructure().type === 'm3u' &&
19
+ !state.m3u.getAllChunksProcessedOverall()) {
20
+ return false;
21
+ }
22
+ log_1.Log.verbose(state.logLevel, 'Reached end of file');
23
+ await state.discardReadBytes(true);
24
+ return true;
25
+ }
26
+ if (state.iterator.counter.getOffset() + state.iterator.bytesRemaining() ===
27
+ state.contentLength &&
28
+ state.errored) {
29
+ log_1.Log.verbose(state.logLevel, 'Reached end of file and errorred');
30
+ return true;
31
+ }
32
+ return false;
33
+ };
34
+ exports.checkIfDone = checkIfDone;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseAac = void 0;
4
4
  const aac_codecprivate_1 = require("../../aac-codecprivate");
5
5
  const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sample");
6
+ const emit_audio_sample_1 = require("../../emit-audio-sample");
6
7
  const register_track_1 = require("../../register-track");
7
8
  const parseAac = async (state) => {
8
9
  const { iterator } = state;
@@ -68,17 +69,21 @@ const parseAac = async (state) => {
68
69
  const { index } = state.aac.addSample({ offset: startOffset, size: frameLength });
69
70
  const timestamp = (1024 / sampleRate) * index;
70
71
  // One ADTS frame contains 1024 samples
71
- await state.callbacks.onAudioSample(0, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
72
- duration,
73
- type: 'key',
74
- data,
75
- offset: startOffset,
76
- timescale: 1000000,
72
+ await (0, emit_audio_sample_1.emitAudioSample)({
77
73
  trackId: 0,
78
- cts: timestamp,
79
- dts: timestamp,
80
- timestamp,
81
- }, 1));
74
+ audioSample: (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
75
+ duration,
76
+ type: 'key',
77
+ data,
78
+ offset: startOffset,
79
+ timescale: 1000000,
80
+ trackId: 0,
81
+ cts: timestamp,
82
+ dts: timestamp,
83
+ timestamp,
84
+ }, 1),
85
+ state,
86
+ });
82
87
  return Promise.resolve(null);
83
88
  };
84
89
  exports.parseAac = parseAac;
@@ -3,7 +3,7 @@
3
3
  // Page 455
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.parseAvc = void 0;
6
- const buffer_iterator_1 = require("../../buffer-iterator");
6
+ const buffer_iterator_1 = require("../../iterator/buffer-iterator");
7
7
  const Extended_SAR = 255;
8
8
  const readVuiParameters = (iterator) => {
9
9
  let sar_width = null;
@@ -1,2 +1,2 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export declare const getBlockSize: (iterator: BufferIterator) => number | "uncommon-u16" | "uncommon-u8";
@@ -1,2 +1,2 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
2
- export declare const getChannelCount: (iterator: BufferIterator) => 5 | 1 | 2 | 3 | 4 | 6 | 7 | 8;
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
+ export declare const getChannelCount: (iterator: BufferIterator) => 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
@@ -1,3 +1,3 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParserState } from '../../state/parser-state';
3
3
  export declare const getSampleRate: (iterator: BufferIterator, state: ParserState) => number | "uncommon-u8" | "uncommon-u16" | "uncommon-u16-10";
@@ -1,4 +1,4 @@
1
- import { type BufferIterator } from '../../buffer-iterator';
1
+ import { type BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
4
  export declare const parseFrameHeader: ({ iterator, state, }: {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseFlacFrame = exports.parseFrameHeader = void 0;
4
- const buffer_iterator_1 = require("../../buffer-iterator");
5
4
  const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sample");
5
+ const emit_audio_sample_1 = require("../../emit-audio-sample");
6
+ const buffer_iterator_1 = require("../../iterator/buffer-iterator");
6
7
  const get_block_size_1 = require("./get-block-size");
7
8
  const get_channel_count_1 = require("./get-channel-count");
8
9
  const get_sample_rate_1 = require("./get-sample-rate");
@@ -80,17 +81,21 @@ const emitSample = async ({ state, data, offset, }) => {
80
81
  throw new Error('Cannot determine timestamp');
81
82
  }
82
83
  const timestamp = (num * streamInfo.maximumBlockSize) / streamInfo.sampleRate;
83
- await state.callbacks.onAudioSample(0, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
84
- data,
85
- duration,
86
- cts: timestamp,
87
- dts: timestamp,
88
- timestamp,
89
- type: 'key',
90
- offset,
91
- timescale: 1000000,
84
+ await (0, emit_audio_sample_1.emitAudioSample)({
92
85
  trackId: 0,
93
- }, 1));
86
+ audioSample: (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
87
+ data,
88
+ duration,
89
+ cts: timestamp,
90
+ dts: timestamp,
91
+ timestamp,
92
+ type: 'key',
93
+ offset,
94
+ timescale: 1000000,
95
+ trackId: 0,
96
+ }, 1),
97
+ state,
98
+ });
94
99
  iterator.destroy();
95
100
  };
96
101
  const parseFlacFrame = async ({ state, iterator, }) => {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
4
  export declare const parseFlac: ({ iterator, state, }: {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
4
  export declare const parseFlacHeader: ({ state, }: {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
4
  export declare const parseVorbisComment: ({ state, iterator, size, }: {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
4
  export declare const parseStreamInfo: ({ iterator, state, }: {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
4
  export declare const parseFlacUnkownBlock: ({ iterator, state, size, }: {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  type UnknownDecoderSpecificConfig = {
3
3
  type: 'unknown-decoder-specific-config';
4
4
  };
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { DecoderSpecificConfig } from './decoder-specific-config';
3
3
  type AudioObjectType = 'aac' | 'mp3' | 'unknown';
4
4
  type DecoderConfigDescriptor = {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { Descriptor } from './esds-descriptors';
3
3
  export interface EsdsBox {
4
4
  type: 'esds-box';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from './base-type';
3
3
  export interface FtypBox extends BaseBox {
4
4
  type: 'ftyp-box';
@@ -6,6 +6,7 @@ const register_track_1 = require("../../register-track");
6
6
  const parser_state_1 = require("../../state/parser-state");
7
7
  const process_box_1 = require("./process-box");
8
8
  const traversal_1 = require("./traversal");
9
+ // TODO: await parseMedia({fields: {moovAtom: true}) would be a nicer API
9
10
  const getMoovAtom = async ({ endOfMdat, state, }) => {
10
11
  const headerSegment = state.mp4HeaderSegment;
11
12
  if (headerSegment) {
@@ -26,9 +27,6 @@ const getMoovAtom = async ({ endOfMdat, state, }) => {
26
27
  hasAudioTrackHandlers: false,
27
28
  hasVideoTrackHandlers: false,
28
29
  controller: state.controller,
29
- fields: {
30
- structure: true,
31
- },
32
30
  onAudioTrack: state.onAudioTrack
33
31
  ? async ({ track, container }) => {
34
32
  await (0, register_track_1.registerAudioTrack)({ state, track, container });
@@ -50,6 +48,14 @@ const getMoovAtom = async ({ endOfMdat, state, }) => {
50
48
  selectM3uStreamFn: state.selectM3uStreamFn,
51
49
  selectM3uAssociatedPlaylistsFn: state.selectM3uAssociatedPlaylistsFn,
52
50
  mp4HeaderSegment: state.mp4HeaderSegment,
51
+ callbacks: {},
52
+ fieldsInReturnValue: {
53
+ structure: true,
54
+ },
55
+ contentType: null,
56
+ mimeType: null,
57
+ name: '',
58
+ initialReaderInstance: reader,
53
59
  });
54
60
  while (true) {
55
61
  const result = await reader.reader.read();
@@ -0,0 +1,5 @@
1
+ import type { SamplePosition } from '../../get-sample-positions';
2
+ import type { IsoBaseMediaSeekingInfo, SeekingInfo } from '../../seeking-info';
3
+ import type { ParserState } from '../../state/parser-state';
4
+ export declare const getSeekingInfoFromMp4: (state: ParserState) => SeekingInfo | null;
5
+ export declare const getSeekingByteFromIsoBaseMedia: (info: IsoBaseMediaSeekingInfo, time: number) => SamplePosition;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSeekingByteFromIsoBaseMedia = exports.getSeekingInfoFromMp4 = void 0;
4
+ const get_tracks_1 = require("../../get-tracks");
5
+ const get_sample_positions_from_track_1 = require("./get-sample-positions-from-track");
6
+ const traversal_1 = require("./traversal");
7
+ const getSeekingInfoFromMp4 = (state) => {
8
+ const structure = state.getIsoStructure();
9
+ const moovAtom = (0, traversal_1.getMoovBoxFromState)(state);
10
+ const moofBoxes = (0, traversal_1.getMoofBoxes)(structure.boxes);
11
+ if (!moovAtom) {
12
+ return null;
13
+ }
14
+ return {
15
+ type: 'iso-base-media-seeking-info',
16
+ moovBox: moovAtom,
17
+ moofBoxes,
18
+ };
19
+ };
20
+ exports.getSeekingInfoFromMp4 = getSeekingInfoFromMp4;
21
+ const getSeekingByteFromIsoBaseMedia = (info, time) => {
22
+ const tracks = (0, get_tracks_1.getTracksFromMoovBox)(info.moovBox);
23
+ const allTracks = [
24
+ ...tracks.videoTracks,
25
+ ...tracks.audioTracks,
26
+ ...tracks.otherTracks,
27
+ ];
28
+ let byte = 0;
29
+ let sam = null;
30
+ for (const t of allTracks) {
31
+ const { timescale: ts, type } = t;
32
+ if (type !== 'video') {
33
+ continue;
34
+ }
35
+ const samplePositions = (0, get_sample_positions_from_track_1.getSamplePositionsFromTrack)({
36
+ trakBox: t.trakBox,
37
+ moofBoxes: info.moofBoxes,
38
+ });
39
+ for (const sample of samplePositions) {
40
+ const ctsInSeconds = sample.cts / ts;
41
+ const dtsInSeconds = sample.dts / ts;
42
+ if ((ctsInSeconds <= time || dtsInSeconds <= time) &&
43
+ byte <= sample.offset &&
44
+ type === 'video' &&
45
+ sample.isKeyframe) {
46
+ byte = sample.offset;
47
+ sam = sample;
48
+ }
49
+ }
50
+ }
51
+ if (!sam) {
52
+ throw new Error('No sample found');
53
+ }
54
+ return sam;
55
+ };
56
+ exports.getSeekingByteFromIsoBaseMedia = getSeekingByteFromIsoBaseMedia;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMdatSection = void 0;
4
4
  const convert_audio_or_video_sample_1 = require("../../../convert-audio-or-video-sample");
5
+ const emit_audio_sample_1 = require("../../../emit-audio-sample");
5
6
  const get_tracks_1 = require("../../../get-tracks");
6
7
  const skip_1 = require("../../../skip");
7
8
  const cached_sample_positions_1 = require("../../../state/iso-base-media/cached-sample-positions");
@@ -54,17 +55,21 @@ const parseMdatSection = async (state) => {
54
55
  const bytes = iterator.getSlice(samplesWithIndex.samplePosition.size);
55
56
  const { cts, dts, duration, isKeyframe, offset } = samplesWithIndex.samplePosition;
56
57
  if (samplesWithIndex.track.type === 'audio') {
57
- await state.callbacks.onAudioSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
58
- data: bytes,
59
- timestamp: cts,
60
- duration,
61
- cts,
62
- dts,
58
+ await (0, emit_audio_sample_1.emitAudioSample)({
63
59
  trackId: samplesWithIndex.track.trackId,
64
- type: isKeyframe ? 'key' : 'delta',
65
- offset,
66
- timescale: samplesWithIndex.track.timescale,
67
- }, samplesWithIndex.track.timescale));
60
+ audioSample: (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
61
+ data: bytes,
62
+ timestamp: cts,
63
+ duration,
64
+ cts,
65
+ dts,
66
+ trackId: samplesWithIndex.track.trackId,
67
+ type: isKeyframe ? 'key' : 'delta',
68
+ offset,
69
+ timescale: samplesWithIndex.track.timescale,
70
+ }, samplesWithIndex.track.timescale),
71
+ state,
72
+ });
68
73
  }
69
74
  if (samplesWithIndex.track.type === 'video') {
70
75
  // https://remotion-assets.s3.eu-central-1.amazonaws.com/example-videos/sei_checkpoint.mp4
@@ -79,17 +84,21 @@ const parseMdatSection = async (state) => {
79
84
  const seiType = bytes[5];
80
85
  isRecoveryPoint = seiType === 6;
81
86
  }
82
- await state.callbacks.onVideoSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
83
- data: bytes,
84
- timestamp: cts,
85
- duration,
86
- cts,
87
- dts,
87
+ await (0, emit_audio_sample_1.emitVideoSample)({
88
88
  trackId: samplesWithIndex.track.trackId,
89
- type: isKeyframe && !isRecoveryPoint ? 'key' : 'delta',
90
- offset,
91
- timescale: samplesWithIndex.track.timescale,
92
- }, samplesWithIndex.track.timescale));
89
+ videoSample: (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
90
+ data: bytes,
91
+ timestamp: cts,
92
+ duration,
93
+ cts,
94
+ dts,
95
+ trackId: samplesWithIndex.track.trackId,
96
+ type: isKeyframe && !isRecoveryPoint ? 'key' : 'delta',
97
+ offset,
98
+ timescale: samplesWithIndex.track.timescale,
99
+ }, samplesWithIndex.track.timescale),
100
+ state,
101
+ });
93
102
  }
94
103
  return null;
95
104
  };
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export interface MdhdBox {
3
3
  type: 'mdhd-box';
4
4
  version: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  export interface HdlrBox extends BaseBox {
4
4
  type: 'hdlr-box';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  type IlstEntry = {
4
4
  index: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from './base-type';
3
3
  export type ThreeDMatrix = [
4
4
  number,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMvhd = void 0;
4
- const buffer_iterator_1 = require("../../buffer-iterator");
4
+ const buffer_iterator_1 = require("../../iterator/buffer-iterator");
5
5
  const to_date_1 = require("./to-date");
6
6
  const parseMvhd = ({ iterator, offset, size, }) => {
7
7
  const version = iterator.getUint8();
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseIccProfile = void 0;
4
- const buffer_iterator_1 = require("../../buffer-iterator");
4
+ const buffer_iterator_1 = require("../../iterator/buffer-iterator");
5
5
  const parseIccProfile = (data) => {
6
6
  const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data, Infinity);
7
7
  const size = iterator.getUint32();
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  export interface Av1CBox {
3
3
  type: 'av1C-box';
4
4
  privateData: Uint8Array;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  export interface AvccBox {
3
3
  type: 'avcc-box';
4
4
  privateData: Uint8Array;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { IccProfile } from '../parse-icc-profile';
3
3
  type ExtraData = {
4
4
  colorType: 'transfer-characteristics';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  type CttsEntry = {
4
4
  sampleCount: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  export interface HvccBox {
3
3
  type: 'hvcc-box';
4
4
  privateData: Uint8Array;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  type KeysEntry = {
4
4
  keySize: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  export interface PaspBox extends BaseBox {
4
4
  type: 'pasp-box';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  export interface StcoBox extends BaseBox {
4
4
  type: 'stco-box';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  type StscEntry = {
4
4
  firstChunk: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  export interface StssBox extends BaseBox {
4
4
  type: 'stss-box';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
3
  type Discriminated = {
4
4
  countType: 'fixed';
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
1
+ import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  export interface SttsBox {
3
3
  type: 'stts-box';
4
4
  sampleDistribution: SampleDistribution[];
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export interface TfdtBox {
3
3
  type: 'tfdt-box';
4
4
  version: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export interface TfhdBox {
3
3
  type: 'tfhd-box';
4
4
  version: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from './base-type';
3
3
  import type { ThreeDMatrix } from './mvhd';
4
4
  export interface TkhdBox extends BaseBox {
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export interface TrunBox {
3
3
  type: 'trun-box';
4
4
  version: number;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { ParseResult } from '../../parse-result';
3
3
  import type { M3uStructure } from './types';
4
4
  export declare const parseM3uManifest: ({ iterator, structure, contentLength, }: {
@@ -1,2 +1,2 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export declare const parseID3V1: (iterator: BufferIterator) => void;
@@ -2,6 +2,7 @@
2
2
  // spec: http://www.mp3-tech.org/programmer/frame_header.html
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.parseMpegHeader = void 0;
5
+ const emit_audio_sample_1 = require("../../emit-audio-sample");
5
6
  const log_1 = require("../../log");
6
7
  const register_track_1 = require("../../register-track");
7
8
  const get_frame_length_1 = require("./get-frame-length");
@@ -276,16 +277,20 @@ const parseMpegHeader = async ({ state, }) => {
276
277
  const timeInSeconds = (nthFrame * samplesPerFrame) / sampleRate;
277
278
  const timestamp = Math.round(timeInSeconds * 1000000);
278
279
  const duration = Math.round(durationInSeconds * 1000000);
279
- await state.callbacks.onAudioSample(0, {
280
- data,
281
- cts: timestamp,
282
- dts: timestamp,
283
- duration,
284
- offset: initialOffset,
285
- timescale: 1000000,
286
- timestamp,
280
+ await (0, emit_audio_sample_1.emitAudioSample)({
287
281
  trackId: 0,
288
- type: 'key',
282
+ audioSample: {
283
+ data,
284
+ cts: timestamp,
285
+ dts: timestamp,
286
+ duration,
287
+ offset: initialOffset,
288
+ timescale: 1000000,
289
+ timestamp,
290
+ trackId: 0,
291
+ type: 'key',
292
+ },
293
+ state,
289
294
  });
290
295
  }
291
296
  };
@@ -1,2 +1,2 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  export declare const isMoviAtom: (iterator: BufferIterator, ckId: string) => boolean;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { RiffBox } from './riff-box';
3
3
  export declare const parseAvih: ({ iterator, size, }: {
4
4
  iterator: BufferIterator;
@@ -1,4 +1,4 @@
1
- import type { BufferIterator } from '../../buffer-iterator';
1
+ import type { BufferIterator } from '../../iterator/buffer-iterator';
2
2
  import type { IsftBox } from './riff-box';
3
3
  export declare const parseIsft: ({ iterator, size, }: {
4
4
  iterator: BufferIterator;