@microfox/remotion 1.2.3 → 1.2.5
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/CHANGELOG.md +13 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +74 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -84,6 +84,13 @@ var useComposition = () => {
|
|
|
84
84
|
|
|
85
85
|
// src/core/context/timing.ts
|
|
86
86
|
import { ALL_FORMATS, Input, UrlSource } from "mediabunny";
|
|
87
|
+
var durationCache = /* @__PURE__ */ new Map();
|
|
88
|
+
var getDurationCacheKey = (src, startFrom, endAt, playbackRate) => {
|
|
89
|
+
const startFromStr = startFrom === void 0 ? "undefined" : String(startFrom);
|
|
90
|
+
const endAtStr = endAt === void 0 ? "undefined" : String(endAt);
|
|
91
|
+
const playbackRateStr = playbackRate === void 0 ? "1" : String(playbackRate);
|
|
92
|
+
return `${src}|${startFromStr}|${endAtStr}|${playbackRateStr}`;
|
|
93
|
+
};
|
|
87
94
|
var findMatchingComponents = (childrenData, targetIds) => {
|
|
88
95
|
const matches = [];
|
|
89
96
|
const searchRecursively = (components) => {
|
|
@@ -126,19 +133,29 @@ var findMatchingComponentsByQuery = (childrenData, query) => {
|
|
|
126
133
|
};
|
|
127
134
|
var calculateComponentDuration = async (component) => {
|
|
128
135
|
const src = component.data.src;
|
|
129
|
-
if (src
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
source: new UrlSource(src)
|
|
133
|
-
});
|
|
134
|
-
const audioDuration = await audioInput.computeDuration();
|
|
135
|
-
let trimmedDuration = audioDuration;
|
|
136
|
-
if (component.data.startFrom || component.data.endAt) {
|
|
137
|
-
trimmedDuration = audioDuration - (component.data.startFrom || 0) - (component.data.endAt ? audioDuration - (component.data.endAt || 0) : 0);
|
|
138
|
-
}
|
|
136
|
+
if (src?.startsWith("http")) {
|
|
137
|
+
const startFrom = component.data.startFrom;
|
|
138
|
+
const endAt = component.data.endAt;
|
|
139
139
|
const playbackRate = component.data.playbackRate || 1;
|
|
140
|
-
const
|
|
141
|
-
|
|
140
|
+
const cacheKey = getDurationCacheKey(src, startFrom, endAt, playbackRate);
|
|
141
|
+
if (durationCache.has(cacheKey)) {
|
|
142
|
+
return durationCache.get(cacheKey);
|
|
143
|
+
}
|
|
144
|
+
const calculationPromise = (async () => {
|
|
145
|
+
const audioInput = new Input({
|
|
146
|
+
formats: ALL_FORMATS,
|
|
147
|
+
source: new UrlSource(src)
|
|
148
|
+
});
|
|
149
|
+
const audioDuration = await audioInput.computeDuration();
|
|
150
|
+
let trimmedDuration = audioDuration;
|
|
151
|
+
if (startFrom || endAt) {
|
|
152
|
+
trimmedDuration = audioDuration - (startFrom || 0) - (endAt ? audioDuration - (endAt || 0) : 0);
|
|
153
|
+
}
|
|
154
|
+
const effectiveDuration = trimmedDuration / playbackRate;
|
|
155
|
+
return effectiveDuration;
|
|
156
|
+
})();
|
|
157
|
+
durationCache.set(cacheKey, calculationPromise);
|
|
158
|
+
return calculationPromise;
|
|
142
159
|
} else {
|
|
143
160
|
}
|
|
144
161
|
};
|
|
@@ -151,9 +168,13 @@ var calculateDuration = async (childrenData, config18) => {
|
|
|
151
168
|
);
|
|
152
169
|
if (matchingComponents.length === 1) {
|
|
153
170
|
if (matchingComponents[0].type === "atom" && (matchingComponents[0].componentId === "AudioAtom" || matchingComponents[0].componentId === "VideoAtom")) {
|
|
154
|
-
|
|
155
|
-
matchingComponents[0]
|
|
156
|
-
|
|
171
|
+
if (matchingComponents[0].context?.timing?.duration) {
|
|
172
|
+
calculatedDuration = matchingComponents[0].context.timing.duration;
|
|
173
|
+
} else {
|
|
174
|
+
calculatedDuration = await calculateComponentDuration(
|
|
175
|
+
matchingComponents[0]
|
|
176
|
+
);
|
|
177
|
+
}
|
|
157
178
|
}
|
|
158
179
|
if ((matchingComponents[0].type === "scene" || matchingComponents[0].type === "layout") && matchingComponents[0].context?.timing?.duration) {
|
|
159
180
|
calculatedDuration = matchingComponents[0].context.timing.duration;
|
|
@@ -162,6 +183,7 @@ var calculateDuration = async (childrenData, config18) => {
|
|
|
162
183
|
return calculatedDuration;
|
|
163
184
|
};
|
|
164
185
|
var setDurationsInContext = async (root) => {
|
|
186
|
+
durationCache.clear();
|
|
165
187
|
const iterateRecursively = async (components, onlyScene = false) => {
|
|
166
188
|
const updatedComponents = [];
|
|
167
189
|
for (const component of components) {
|
|
@@ -173,12 +195,15 @@ var setDurationsInContext = async (root) => {
|
|
|
173
195
|
);
|
|
174
196
|
}
|
|
175
197
|
if (updatedComponent.context?.timing?.fitDurationTo?.length > 0 && !onlyScene && updatedComponent.context?.timing?.fitDurationTo != updatedComponent.id && updatedComponent.context?.timing?.fitDurationTo != "this" && updatedComponent.context?.timing?.fitDurationTo != "fill") {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
198
|
+
let duration = updatedComponent.context?.timing?.duration;
|
|
199
|
+
if (!duration) {
|
|
200
|
+
duration = await calculateDuration(
|
|
201
|
+
updatedComponent.childrenData,
|
|
202
|
+
{
|
|
203
|
+
fitDurationTo: updatedComponent.context?.timing?.fitDurationTo
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
}
|
|
182
207
|
updatedComponent = {
|
|
183
208
|
...updatedComponent,
|
|
184
209
|
context: {
|
|
@@ -201,6 +226,8 @@ var setDurationsInContext = async (root) => {
|
|
|
201
226
|
(acc, child) => acc + (child.context?.timing?.duration ?? 0),
|
|
202
227
|
0
|
|
203
228
|
) ?? 10;
|
|
229
|
+
} else {
|
|
230
|
+
duration = updatedComponent.context.timing.duration;
|
|
204
231
|
}
|
|
205
232
|
if (duration !== void 0) {
|
|
206
233
|
updatedComponent.context = {
|
|
@@ -214,7 +241,13 @@ var setDurationsInContext = async (root) => {
|
|
|
214
241
|
}
|
|
215
242
|
if (updatedComponent.type === "atom" && !onlyScene) {
|
|
216
243
|
if (updatedComponent.componentId === "VideoAtom" || updatedComponent.componentId === "AudioAtom") {
|
|
217
|
-
const
|
|
244
|
+
const needsDurationCalculation = !updatedComponent.context?.timing?.duration || updatedComponent.data?.loop && !updatedComponent.data?.srcDuration;
|
|
245
|
+
let mediaDuration;
|
|
246
|
+
if (needsDurationCalculation) {
|
|
247
|
+
mediaDuration = await calculateComponentDuration(updatedComponent);
|
|
248
|
+
} else {
|
|
249
|
+
mediaDuration = updatedComponent.context?.timing?.duration;
|
|
250
|
+
}
|
|
218
251
|
if (!updatedComponent.context?.timing?.fitDurationTo) {
|
|
219
252
|
updatedComponent.context = {
|
|
220
253
|
...updatedComponent.context || {},
|
|
@@ -225,9 +258,9 @@ var setDurationsInContext = async (root) => {
|
|
|
225
258
|
};
|
|
226
259
|
updatedComponent.data = {
|
|
227
260
|
...updatedComponent.data,
|
|
228
|
-
...updatedComponent.data.loop ? { srcDuration: mediaDuration } : {}
|
|
261
|
+
...updatedComponent.data.loop && mediaDuration ? { srcDuration: mediaDuration } : {}
|
|
229
262
|
};
|
|
230
|
-
} else if (updatedComponent.context?.timing?.fitDurationTo) {
|
|
263
|
+
} else if (updatedComponent.context?.timing?.fitDurationTo && mediaDuration) {
|
|
231
264
|
updatedComponent.data = {
|
|
232
265
|
...updatedComponent.data,
|
|
233
266
|
srcDuration: mediaDuration
|
|
@@ -5241,6 +5274,7 @@ var WaveformHistogram = ({ data }) => {
|
|
|
5241
5274
|
histogramStyle = "centered",
|
|
5242
5275
|
amplitude = 1,
|
|
5243
5276
|
multiplier = 1,
|
|
5277
|
+
barSlant = 0,
|
|
5244
5278
|
gradientStartColor,
|
|
5245
5279
|
gradientEndColor,
|
|
5246
5280
|
gradientDirection = "vertical",
|
|
@@ -5264,7 +5298,8 @@ var WaveformHistogram = ({ data }) => {
|
|
|
5264
5298
|
gradientDirection,
|
|
5265
5299
|
multiplier,
|
|
5266
5300
|
gradientStyle,
|
|
5267
|
-
waveDirection
|
|
5301
|
+
waveDirection,
|
|
5302
|
+
barSlant
|
|
5268
5303
|
}
|
|
5269
5304
|
));
|
|
5270
5305
|
};
|
|
@@ -5283,7 +5318,8 @@ var WaveformHistogramContent = ({
|
|
|
5283
5318
|
gradientDirection,
|
|
5284
5319
|
multiplier,
|
|
5285
5320
|
gradientStyle,
|
|
5286
|
-
waveDirection
|
|
5321
|
+
waveDirection,
|
|
5322
|
+
barSlant
|
|
5287
5323
|
}) => {
|
|
5288
5324
|
const { waveformData, frequencyData, amplitudes, width, height } = useWaveformContext();
|
|
5289
5325
|
const dataToUse = amplitudes || waveformData;
|
|
@@ -5324,7 +5360,9 @@ var WaveformHistogramContent = ({
|
|
|
5324
5360
|
Math.abs(value) * (height / 2) * (amplitude || 1)
|
|
5325
5361
|
)}px`,
|
|
5326
5362
|
borderRadius: growUpwards ? `${barBorderRadius}px ${barBorderRadius}px 0 0` : `0 0 ${barBorderRadius}px ${barBorderRadius}px`,
|
|
5327
|
-
opacity
|
|
5363
|
+
opacity,
|
|
5364
|
+
transform: barSlant ? `rotate(${barSlant}deg)` : void 0,
|
|
5365
|
+
transformOrigin: "center bottom"
|
|
5328
5366
|
}
|
|
5329
5367
|
}
|
|
5330
5368
|
)));
|
|
@@ -5382,7 +5420,8 @@ var WaveformHistogramRanged = ({ data }) => {
|
|
|
5382
5420
|
gradientDirection = "vertical",
|
|
5383
5421
|
gradientStyle = "normal",
|
|
5384
5422
|
horizontalSymmetry = false,
|
|
5385
|
-
waveDirection = "right-to-left"
|
|
5423
|
+
waveDirection = "right-to-left",
|
|
5424
|
+
barSlant = 0
|
|
5386
5425
|
} = data;
|
|
5387
5426
|
return /* @__PURE__ */ React35.createElement(Waveform, { config: config18, className, style }, /* @__PURE__ */ React35.createElement(
|
|
5388
5427
|
WaveformHistogramRangedContent,
|
|
@@ -5406,7 +5445,8 @@ var WaveformHistogramRanged = ({ data }) => {
|
|
|
5406
5445
|
gradientDirection,
|
|
5407
5446
|
gradientStyle,
|
|
5408
5447
|
horizontalSymmetry,
|
|
5409
|
-
waveDirection
|
|
5448
|
+
waveDirection,
|
|
5449
|
+
barSlant
|
|
5410
5450
|
}
|
|
5411
5451
|
));
|
|
5412
5452
|
};
|
|
@@ -5430,7 +5470,8 @@ var WaveformHistogramRangedContent = ({
|
|
|
5430
5470
|
gradientDirection,
|
|
5431
5471
|
gradientStyle,
|
|
5432
5472
|
horizontalSymmetry,
|
|
5433
|
-
waveDirection
|
|
5473
|
+
waveDirection,
|
|
5474
|
+
barSlant
|
|
5434
5475
|
}) => {
|
|
5435
5476
|
const { amplitudes, bassValues, midValues, trebleValues, height } = useWaveformContext();
|
|
5436
5477
|
if (!amplitudes || !bassValues || !midValues || !trebleValues) {
|
|
@@ -5477,7 +5518,9 @@ var WaveformHistogramRangedContent = ({
|
|
|
5477
5518
|
)}px`,
|
|
5478
5519
|
borderRadius: growUpwards ? `${barBorderRadius}px ${barBorderRadius}px 0 0` : `0 0 ${barBorderRadius}px ${barBorderRadius}px`,
|
|
5479
5520
|
opacity,
|
|
5480
|
-
position: "relative"
|
|
5521
|
+
position: "relative",
|
|
5522
|
+
transform: barSlant ? `rotate(${barSlant}deg)` : void 0,
|
|
5523
|
+
transformOrigin: "center bottom"
|
|
5481
5524
|
},
|
|
5482
5525
|
title: `${rangeName}: ${(value * 100).toFixed(1)}%`
|
|
5483
5526
|
},
|