@remotion/media-parser 4.0.333 → 4.0.334

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.
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cachedSamplePositionsState = exports.calculateFlatSamples = void 0;
3
+ exports.getSampleWithLowestDts = exports.cachedSamplePositionsState = exports.calculateSamplePositions = void 0;
4
4
  const are_samples_complete_1 = require("../../containers/iso-base-media/are-samples-complete");
5
5
  const get_sample_positions_from_track_1 = require("../../containers/iso-base-media/get-sample-positions-from-track");
6
6
  const traversal_1 = require("../../containers/iso-base-media/traversal");
7
7
  const get_tracks_1 = require("../../get-tracks");
8
+ const log_1 = require("../../log");
8
9
  const precomputed_tfra_1 = require("./precomputed-tfra");
9
- const calculateFlatSamples = ({ state, mediaSectionStart, }) => {
10
+ const calculateSamplePositions = ({ state, mediaSectionStart, trackIds, }) => {
10
11
  var _a, _b;
11
12
  const tracks = (0, get_tracks_1.getTracks)(state, true);
12
13
  const moofBoxes = (0, traversal_1.getMoofBoxes)(state.structure.getIsoStructure().boxes);
@@ -28,11 +29,13 @@ const calculateFlatSamples = ({ state, mediaSectionStart, }) => {
28
29
  if (!moov) {
29
30
  throw new Error('No moov box found');
30
31
  }
31
- const offsets = [];
32
- const trackIds = [];
33
- const map = new Map();
32
+ const trackIdAndSamplePositions = [];
34
33
  for (const track of tracks) {
35
34
  const trakBox = (0, traversal_1.getTrakBoxByTrackId)(moov, track.trackId);
35
+ if (!trackIds.includes(track.trackId)) {
36
+ log_1.Log.verbose(state.logLevel, 'Skipping calculating sample positions for track', track.trackId);
37
+ continue;
38
+ }
36
39
  if (!trakBox) {
37
40
  throw new Error('No trak box found');
38
41
  }
@@ -42,37 +45,93 @@ const calculateFlatSamples = ({ state, mediaSectionStart, }) => {
42
45
  moofComplete,
43
46
  trexBoxes: (0, traversal_1.getTrexBoxes)(moov),
44
47
  });
45
- trackIds.push(track.trackId);
46
- for (const samplePosition of samplePositions) {
47
- offsets.push(samplePosition.offset);
48
- map.set(samplePosition.offset, {
49
- track,
50
- samplePosition,
51
- });
48
+ trackIdAndSamplePositions.push({
49
+ trackId: track.trackId,
50
+ samplePositions,
51
+ });
52
+ }
53
+ return trackIdAndSamplePositions;
54
+ };
55
+ exports.calculateSamplePositions = calculateSamplePositions;
56
+ const updateSampleIndicesAfterSeek = ({ samplePositionsForMdatStart, seekedByte, }) => {
57
+ const currentSampleIndices = {};
58
+ const keys = Object.keys(samplePositionsForMdatStart).map(Number).sort();
59
+ const mdat = keys.find((key) => seekedByte >= key);
60
+ if (!mdat) {
61
+ return currentSampleIndices;
62
+ }
63
+ const samplePositions = samplePositionsForMdatStart[mdat];
64
+ if (!samplePositions) {
65
+ return currentSampleIndices;
66
+ }
67
+ for (const track of samplePositions) {
68
+ const currentSampleIndex = track.samplePositions.findIndex((sample) => sample.offset >= seekedByte);
69
+ if (!currentSampleIndices[mdat]) {
70
+ currentSampleIndices[mdat] = {};
71
+ }
72
+ if (!currentSampleIndices[mdat][track.trackId]) {
73
+ currentSampleIndices[mdat][track.trackId] = 0;
74
+ }
75
+ if (currentSampleIndex === -1) {
76
+ currentSampleIndices[mdat][track.trackId] = track.samplePositions.length;
77
+ }
78
+ else {
79
+ currentSampleIndices[mdat][track.trackId] = currentSampleIndex;
52
80
  }
53
81
  }
54
- offsets.sort((a, b) => a - b);
55
- return { flatSamples: map, offsets, trackIds };
82
+ return currentSampleIndices;
56
83
  };
57
- exports.calculateFlatSamples = calculateFlatSamples;
58
84
  const cachedSamplePositionsState = () => {
59
- // offset -> flat sample
60
- const cachedForMdatStart = {};
61
- const jumpMarksForMdatStart = {};
85
+ // offset -> sample positions
86
+ const samplePositionsForMdatStart = {};
87
+ let currentSampleIndex = {};
62
88
  return {
63
89
  getSamples: (mdatStart) => {
64
90
  var _a;
65
- return (_a = cachedForMdatStart[mdatStart]) !== null && _a !== void 0 ? _a : null;
91
+ return (_a = samplePositionsForMdatStart[mdatStart]) !== null && _a !== void 0 ? _a : null;
66
92
  },
67
93
  setSamples: (mdatStart, samples) => {
68
- cachedForMdatStart[mdatStart] = samples;
94
+ samplePositionsForMdatStart[mdatStart] = samples;
95
+ },
96
+ setCurrentSampleIndex: (mdatStart, trackId, index) => {
97
+ if (!currentSampleIndex[mdatStart]) {
98
+ currentSampleIndex[mdatStart] = {};
99
+ }
100
+ if (!currentSampleIndex[mdatStart][trackId]) {
101
+ currentSampleIndex[mdatStart][trackId] = 0;
102
+ }
103
+ currentSampleIndex[mdatStart][trackId] = index;
69
104
  },
70
- setJumpMarks: (mdatStart, marks) => {
71
- jumpMarksForMdatStart[mdatStart] = marks;
105
+ getCurrentSampleIndices: (mdatStart) => {
106
+ var _a;
107
+ return (_a = currentSampleIndex[mdatStart]) !== null && _a !== void 0 ? _a : {};
72
108
  },
73
- getJumpMarks: (mdatStart) => {
74
- return jumpMarksForMdatStart[mdatStart];
109
+ updateAfterSeek: (seekedByte) => {
110
+ currentSampleIndex = updateSampleIndicesAfterSeek({
111
+ samplePositionsForMdatStart,
112
+ seekedByte,
113
+ });
75
114
  },
76
115
  };
77
116
  };
78
117
  exports.cachedSamplePositionsState = cachedSamplePositionsState;
118
+ const getSampleWithLowestDts = (samplePositions, currentSampleIndexMap) => {
119
+ var _a;
120
+ const lowestDts = [];
121
+ for (const track of samplePositions) {
122
+ const currentSampleIndex = (_a = currentSampleIndexMap[track.trackId]) !== null && _a !== void 0 ? _a : 0;
123
+ const currentSample = track.samplePositions[currentSampleIndex];
124
+ if (currentSample &&
125
+ (lowestDts.length === 0 ||
126
+ currentSample.decodingTimestamp <=
127
+ lowestDts[0].samplePosition.decodingTimestamp)) {
128
+ lowestDts.push({
129
+ samplePosition: currentSample,
130
+ trackId: track.trackId,
131
+ index: currentSampleIndex,
132
+ });
133
+ }
134
+ }
135
+ return lowestDts;
136
+ };
137
+ exports.getSampleWithLowestDts = getSampleWithLowestDts;
@@ -12,10 +12,17 @@ export declare const isoBaseMediaState: ({ contentLength, controller, readerInte
12
12
  prefetchCache: PrefetchCache;
13
13
  }) => {
14
14
  flatSamples: {
15
- getSamples: (mdatStart: number) => Map<number, import("./cached-sample-positions").FlatSample> | null;
16
- setSamples: (mdatStart: number, samples: Map<number, import("./cached-sample-positions").FlatSample>) => void;
17
- setJumpMarks: (mdatStart: number, marks: import("../../containers/iso-base-media/mdat/calculate-jump-marks").JumpMark[]) => void;
18
- getJumpMarks: (mdatStart: number) => import("../../containers/iso-base-media/mdat/calculate-jump-marks").JumpMark[];
15
+ getSamples: (mdatStart: number) => {
16
+ trackId: number;
17
+ samplePositions: import("../../get-sample-positions").SamplePosition[];
18
+ }[] | null;
19
+ setSamples: (mdatStart: number, samples: {
20
+ trackId: number;
21
+ samplePositions: import("../../get-sample-positions").SamplePosition[];
22
+ }[]) => void;
23
+ setCurrentSampleIndex: (mdatStart: number, trackId: number, index: number) => void;
24
+ getCurrentSampleIndices: (mdatStart: number) => Record<number, number>;
25
+ updateAfterSeek: (seekedByte: number) => void;
19
26
  };
20
27
  moov: {
21
28
  setMoovBox: (moov: {
@@ -164,10 +164,17 @@ export declare const makeParserState: ({ hasAudioTrackHandlers, hasVideoTrackHan
164
164
  };
165
165
  iso: {
166
166
  flatSamples: {
167
- getSamples: (mdatStart: number) => Map<number, import("./iso-base-media/cached-sample-positions").FlatSample> | null;
168
- setSamples: (mdatStart: number, samples: Map<number, import("./iso-base-media/cached-sample-positions").FlatSample>) => void;
169
- setJumpMarks: (mdatStart: number, marks: import("../containers/iso-base-media/mdat/calculate-jump-marks").JumpMark[]) => void;
170
- getJumpMarks: (mdatStart: number) => import("../containers/iso-base-media/mdat/calculate-jump-marks").JumpMark[];
167
+ getSamples: (mdatStart: number) => {
168
+ trackId: number;
169
+ samplePositions: import("../get-sample-positions").SamplePosition[];
170
+ }[] | null;
171
+ setSamples: (mdatStart: number, samples: {
172
+ trackId: number;
173
+ samplePositions: import("../get-sample-positions").SamplePosition[];
174
+ }[]) => void;
175
+ setCurrentSampleIndex: (mdatStart: number, trackId: number, index: number) => void;
176
+ getCurrentSampleIndices: (mdatStart: number) => Record<number, number>;
177
+ updateAfterSeek: (seekedByte: number) => void;
171
178
  };
172
179
  moov: {
173
180
  setMoovBox: (moov: {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.333";
1
+ export declare const VERSION = "4.0.334";
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.333';
5
+ exports.VERSION = '4.0.334';
@@ -134,6 +134,7 @@ const workOnSeekRequest = async (options) => {
134
134
  discardReadBytes,
135
135
  fields,
136
136
  prefetchCache,
137
+ isoState,
137
138
  });
138
139
  return;
139
140
  }
@@ -154,6 +155,7 @@ const workOnSeekRequest = async (options) => {
154
155
  discardReadBytes,
155
156
  fields,
156
157
  prefetchCache,
158
+ isoState,
157
159
  });
158
160
  const { hasChanged } = controller._internals.seekSignal.clearSeekIfStillSame(seek);
159
161
  if (hasChanged) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
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.333",
6
+ "version": "4.0.334",
7
7
  "main": "dist/index.js",
8
8
  "sideEffects": false,
9
9
  "devDependencies": {
@@ -11,8 +11,8 @@
11
11
  "eslint": "9.19.0",
12
12
  "mediabunny": "1.3.0",
13
13
  "@types/bun": "1.2.8",
14
- "@remotion/example-videos": "4.0.333",
15
- "@remotion/eslint-config-internal": "4.0.333"
14
+ "@remotion/example-videos": "4.0.334",
15
+ "@remotion/eslint-config-internal": "4.0.334"
16
16
  },
17
17
  "publishConfig": {
18
18
  "access": "public"