Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Reject two artifacts with the same filename on the same frame

parbhatkapila44ceb0f9aab93
diff --git a/packages/it-tests/src/ssr/duplicate-artifacts.test.ts b/packages/it-tests/src/ssr/duplicate-artifacts.test.ts
new file mode 100644
index 0000000000..55b86012b8
--- /dev/null
+++ b/packages/it-tests/src/ssr/duplicate-artifacts.test.ts
@@ -0,0 +1,46 @@
+import {expect, test} from 'bun:test';
+import {mkdtempSync, rmSync} from 'node:fs';
+import {tmpdir} from 'node:os';
+import path from 'node:path';
+import {bundle} from '@remotion/bundler';
+import {openBrowser, renderMedia, selectComposition} from '@remotion/renderer';
+
+test(
+ 'renderMedia() rejects two artifacts with the same filename on the same frame',
+ async () => {
+ const directory = mkdtempSync(path.join(tmpdir(), 'duplicate-artifacts-'));
+ const browser = await openBrowser('chrome');
+ try {
+ const serveUrl = await bundle({
+ entryPoint: path.join(__dirname, 'fixtures', 'duplicate-artifacts.tsx'),
+ outDir: path.join(directory, 'bundle'),
+ enableCaching: false,
+ });
+ const composition = await selectComposition({
+ serveUrl,
+ id: 'duplicate-artifacts',
+ puppeteerInstance: browser,
+ });
+ const emitted: string[] = [];
+
+ await expect(
+ renderMedia({
+ composition,
+ serveUrl,
+ codec: 'h264',
+ outputLocation: path.join(directory, 'out.mp4'),
+ puppeteerInstance: browser,
+ logLevel: 'error',
+ onArtifact: (artifact) => {
+ emitted.push(artifact.filename);
+ },
+ }),
+ ).rejects.toThrow(/Artifacts must have unique names/);
+ expect(emitted).toEqual(['captions.srt']);
+ } finally {
+ await browser.close({silent: true});
+ rmSync(directory, {recursive: true, force: true});
+ }
+ },
+ {timeout: 60000},
+);
diff --git a/packages/it-tests/src/ssr/fixtures/duplicate-artifacts.tsx b/packages/it-tests/src/ssr/fixtures/duplicate-artifacts.tsx
new file mode 100644
index 0000000000..e11c21dbfb
--- /dev/null
+++ b/packages/it-tests/src/ssr/fixtures/duplicate-artifacts.tsx
@@ -0,0 +1,26 @@
+import {Artifact, Composition, registerRoot, useCurrentFrame} from 'remotion';
+
+const DuplicateArtifacts = () => {
+ const frame = useCurrentFrame();
+ if (frame !== 0) {
+ return null;
+ }
+
+ return (
+ <>
+ <Artifact filename="captions.srt" content="first" />
+ <Artifact filename="captions.srt" content="second" />
+ </>
+ );
+};
+
+registerRoot(() => (
+ <Composition
+ id="duplicate-artifacts"
+ component={DuplicateArtifacts}
+ fps={30}
+ width={16}
+ height={16}
+ durationInFrames={2}
+ />
+));
diff --git a/packages/renderer/src/render-frame-with-option-to-reject.ts b/packages/renderer/src/render-frame-with-option-to-reject.ts
index 1c468b5df0..bc3b5596de 100644
--- a/packages/renderer/src/render-frame-with-option-to-reject.ts
+++ b/packages/renderer/src/render-frame-with-option-to-reject.ts
@@ -323,6 +323,10 @@ export const renderFrameWithOptionToReject = async ({
);
}
+ assetIndex.firstArtifactFrameByFilename.set(
+ artifact.filename,
+ artifact.frame,
+ );
onArtifact?.(artifact);
}
@@ -354,15 +358,6 @@ export const renderFrameWithOptionToReject = async ({
}
}
- for (const artifact of artifactAssets) {
- if (!assetIndex.firstArtifactFrameByFilename.has(artifact.filename)) {
- assetIndex.firstArtifactFrameByFilename.set(
- artifact.filename,
- artifact.frame,
- );
- }
- }
-
for (const renderAsset of compressedAssets) {
downloadAndMapAssetsToFileUrl({
renderAsset,