@remotion/renderer 4.0.489 → 4.0.491

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.
@@ -5,39 +5,68 @@ const filter_asset_types_1 = require("../filter-asset-types");
5
5
  const resolve_asset_src_1 = require("../resolve-asset-src");
6
6
  const flatten_volume_array_1 = require("./flatten-volume-array");
7
7
  const types_1 = require("./types");
8
- const areEqual = (a, b) => {
9
- return a.id === b.id;
10
- };
11
- const findFrom = (target, renderAsset) => {
12
- const index = target.findIndex((a) => areEqual(a, renderAsset));
13
- if (index === -1) {
14
- return false;
15
- }
16
- target.splice(index, 1);
17
- return true;
18
- };
19
- const copyAndDeduplicateAssets = (renderAssets) => {
8
+ const deduplicateAssets = (renderAssets) => {
20
9
  const onlyAudioAndVideo = (0, filter_asset_types_1.onlyAudioAndVideoAssets)(renderAssets);
10
+ const seenIds = new Set();
21
11
  const deduplicated = [];
22
12
  for (const renderAsset of onlyAudioAndVideo) {
23
- if (!deduplicated.find((d) => d.id === renderAsset.id)) {
13
+ if (!seenIds.has(renderAsset.id)) {
14
+ seenIds.add(renderAsset.id);
24
15
  deduplicated.push(renderAsset);
25
16
  }
26
17
  }
27
18
  return deduplicated;
28
19
  };
20
+ const indexUncompressedAssets = (renderAssets) => {
21
+ const referencedAssets = new Set();
22
+ for (const renderAsset of renderAssets) {
23
+ if (renderAsset.src.startsWith('same-as')) {
24
+ referencedAssets.add(renderAsset.src);
25
+ }
26
+ }
27
+ const assetsByReference = new Map();
28
+ for (const renderAsset of renderAssets) {
29
+ if (referencedAssets.size === 0) {
30
+ break;
31
+ }
32
+ if (renderAsset.src.startsWith('same-as')) {
33
+ continue;
34
+ }
35
+ const reference = `same-as-${renderAsset.id}-${renderAsset.frame}`;
36
+ if (referencedAssets.has(reference)) {
37
+ assetsByReference.set(reference, renderAsset);
38
+ referencedAssets.delete(reference);
39
+ }
40
+ }
41
+ return assetsByReference;
42
+ };
29
43
  const calculateAssetPositions = (frames) => {
30
- var _a, _b;
31
44
  const assets = [];
45
+ // Assets that have started but not yet ended, keyed by asset id.
46
+ // Since assets are deduplicated by id within a frame, at most one
47
+ // asset per id is open at a time.
48
+ const openAssets = new Map();
32
49
  const flattened = frames.flat(1);
50
+ const uncompressedAssets = indexUncompressedAssets(flattened);
33
51
  for (let frame = 0; frame < frames.length; frame++) {
34
- const prev = copyAndDeduplicateAssets((_a = frames[frame - 1]) !== null && _a !== void 0 ? _a : []);
35
- const current = copyAndDeduplicateAssets(frames[frame]);
36
- const next = copyAndDeduplicateAssets((_b = frames[frame + 1]) !== null && _b !== void 0 ? _b : []);
52
+ const current = deduplicateAssets(frames[frame]);
53
+ const currentIds = new Set(current.map((a) => a.id));
54
+ for (const [id, openAsset] of openAssets) {
55
+ if (!currentIds.has(id)) {
56
+ // The asset was last present on the previous frame.
57
+ // Duration calculation:
58
+ // start 0, present for frames 0-59, gone at frame 60:
59
+ // 60 - 0 ==> 60 frames duration
60
+ openAsset.duration = frame - openAsset.startInVideo;
61
+ openAssets.delete(id);
62
+ }
63
+ }
37
64
  for (const asset of current) {
38
- if (!findFrom(prev, asset)) {
39
- assets.push({
40
- src: (0, resolve_asset_src_1.resolveAssetSrc)((0, types_1.uncompressMediaAsset)(flattened, asset).src),
65
+ let openAsset = openAssets.get(asset.id);
66
+ if (openAsset === undefined) {
67
+ const uncompressedAsset = uncompressedAssets.get(asset.src);
68
+ openAsset = {
69
+ src: (0, resolve_asset_src_1.resolveAssetSrc)((0, types_1.uncompressMediaAsset)(uncompressedAsset ? [uncompressedAsset] : flattened, asset).src),
41
70
  type: asset.type,
42
71
  duration: null,
43
72
  id: asset.id,
@@ -48,20 +77,17 @@ const calculateAssetPositions = (frames) => {
48
77
  toneFrequency: asset.toneFrequency,
49
78
  audioStartFrame: asset.audioStartFrame,
50
79
  audioStreamIndex: asset.audioStreamIndex,
51
- });
52
- }
53
- const found = assets.find((a) => a.duration === null && areEqual(a, asset));
54
- if (!found)
55
- throw new Error('something wrong');
56
- if (!findFrom(next, asset)) {
57
- // Duration calculation:
58
- // start 0, range 0-59:
59
- // 59 - 0 + 1 ==> 60 frames duration
60
- found.duration = frame - found.startInVideo + 1;
80
+ };
81
+ assets.push(openAsset);
82
+ openAssets.set(asset.id, openAsset);
61
83
  }
62
- found.volume.push(asset.volume);
84
+ openAsset.volume.push(asset.volume);
63
85
  }
64
86
  }
87
+ // Assets that lasted until the end of the video.
88
+ for (const openAsset of openAssets.values()) {
89
+ openAsset.duration = frames.length - openAsset.startInVideo;
90
+ }
65
91
  for (const asset of assets) {
66
92
  if (asset.duration === null) {
67
93
  throw new Error('duration is unexpectedly null');
package/dist/client.d.ts CHANGED
@@ -246,22 +246,6 @@ export declare const BrowserSafeApis: {
246
246
  separateAudioTo: string | null;
247
247
  }) => void;
248
248
  options: {
249
- allowHtmlInCanvasOption: {
250
- name: string;
251
- cliFlag: "allow-html-in-canvas";
252
- description: () => import("react/jsx-runtime").JSX.Element;
253
- ssrName: null;
254
- docLink: string;
255
- type: boolean;
256
- getValue: ({ commandLine }: {
257
- commandLine: Record<string, unknown>;
258
- }) => {
259
- value: boolean;
260
- source: string;
261
- };
262
- setConfig(value: boolean): void;
263
- id: "allow-html-in-canvas";
264
- };
265
249
  audioCodecOption: {
266
250
  cliFlag: "audio-codec";
267
251
  setConfig: (audioCodec: "aac" | "mp3" | "opus" | "pcm-16" | null) => void;
@@ -1356,22 +1340,6 @@ export declare const BrowserSafeApis: {
1356
1340
  setConfig(value: boolean): void;
1357
1341
  id: "disable-interactivity";
1358
1342
  };
1359
- experimentalClientSideRenderingOption: {
1360
- name: string;
1361
- cliFlag: "enable-experimental-client-side-rendering";
1362
- description: () => import("react/jsx-runtime").JSX.Element;
1363
- ssrName: null;
1364
- docLink: string;
1365
- type: boolean;
1366
- getValue: ({ commandLine }: {
1367
- commandLine: Record<string, unknown>;
1368
- }) => {
1369
- value: boolean;
1370
- source: string;
1371
- };
1372
- setConfig(value: boolean): void;
1373
- id: "enable-experimental-client-side-rendering";
1374
- };
1375
1343
  keyboardShortcutsOption: {
1376
1344
  name: string;
1377
1345
  cliFlag: "disable-keyboard-shortcuts";