🎥 Make videos programmatically with React
integration test
Igor Samokhovetscfd6fe0f7e9d
diff --git a/packages/create-video/src/templates.ts b/packages/create-video/src/templates.tsindex b4bd16e4d3..a39e93d2cd 100644--- a/packages/create-video/src/templates.ts+++ b/packages/create-video/src/templates.ts@@ -44,6 +44,7 @@ export type Template = {| 'render-server'| 'recorder'| 'prompt-to-motion-graphics'+ | 'electron'| 'vercel';defaultBranch: string;featuredOnHomePage: string | null;@@ -305,6 +306,30 @@ export const FEATURED_TEMPLATES: Template[] = [contributedBy: null,showStackblitz: true,},+ {+ homePageLabel: 'Electron',+ shortName: 'Electron',+ org: 'remotion-dev',+ repoName: 'template-electron',+ description: 'Render Remotion videos from a desktop app',+ longerDescription:+ 'An Electron Forge + Vite starter template that renders Remotion videos from the Electron main process.',+ promoBanner: {+ width: 1200,+ height: 630,+ src: '/generated/articles-docs-electron.png',+ },+ cliId: 'electron' as const,+ type: 'image' as const,+ defaultBranch: 'main',+ featuredOnHomePage: null,+ previewURL: null,+ previewLabel: null,+ templateInMonorepo: 'template-electron',+ allowEnableTailwind: false,+ contributedBy: null,+ showStackblitz: false,+ },{homePageLabel: 'React Router 7',shortName: 'React Router',diff --git a/packages/docs/docs/electron.mdx b/packages/docs/docs/electron.mdxindex dbfddde3c5..2515a1fccb 100644--- a/packages/docs/docs/electron.mdx+++ b/packages/docs/docs/electron.mdx@@ -9,7 +9,7 @@ crumb: 'Integrations'# Using Remotion in Electron<ExperimentalBadge>-<p>This page documents a verified local setup. Packaged app rendering still needs more testing.</p>+<p>This page documents the packaged-render flow used by the Electron template. Code signing and installers are still app-specific.</p></ExperimentalBadge>Use Electron Forge with the official `vite-typescript` template.@@ -67,20 +67,41 @@ npm install --save-dev @vitejs/plugin-reactUse the official Forge Vite layout with TypeScript entry files.-For packaged apps, use Electron Forge's official `packageAfterCopy()` hook to generate the Remotion bundle during the package step:+For packaged apps, use Electron Forge's official `packageAfterCopy()` hook to generate the Remotion bundle during the package step and stage the matching Remotion compositor package:```ts title="forge.config.ts"+import {cp, mkdir} from 'node:fs/promises';import {VitePlugin} from '@electron-forge/plugin-vite';import {bundle} from '@remotion/bundler';import path from 'node:path';export default {+ packagerConfig: {+ asar: {+ unpackDir: 'node_modules/@remotion/compositor-*',+ },+ },hooks: {- packageAfterCopy: async (_config, buildPath) => {+ packageAfterCopy: async (_config, buildPath, _electronVersion, platform, arch) => {await bundle({entryPoint: path.join(process.cwd(), 'remotion/index.ts'),outDir: path.join(buildPath, 'remotion-bundle'),});++ const compositorPackage = getCompositorPackage({platform, arch});+ const compositorSource = path.dirname(+ require.resolve(`${compositorPackage}/package.json`, {+ paths: [process.cwd()],+ }),+ );+ const compositorDestination = path.join(+ buildPath,+ 'node_modules',+ compositorPackage,+ );++ await mkdir(path.dirname(compositorDestination), {recursive: true});+ await cp(compositorSource, compositorDestination, {recursive: true});},},plugins: [@@ -146,6 +167,28 @@ import {bundle} from '@remotion/bundler';import {ensureBrowser, renderMedia, selectComposition} from '@remotion/renderer';import path from 'node:path';+const getBinariesDirectory = ({+ isPackaged,+ projectRoot,+}: {+ isPackaged: boolean;+ projectRoot: string;+}) => {+ if (!isPackaged) {+ return null;+ }++ return path.join(+ path.dirname(projectRoot),+ 'app.asar.unpacked',+ 'node_modules',+ getCompositorPackage({+ platform: process.platform,+ arch: process.arch,+ }),+ );+};+export const renderVideo = async ({isPackaged,outputPath,@@ -157,7 +200,14 @@ export const renderVideo = async ({projectRoot: string;titleText: string;}) => {- await ensureBrowser();+ await ensureBrowser({+ onBrowserDownload: () => ({+ version: null,+ onProgress: ({percent}) => {+ console.log(`Downloading browser: ${Math.round(percent)}%`);+ },+ }),+ });const serveUrl = isPackaged? path.join(projectRoot, 'remotion-bundle')@@ -165,6 +215,7 @@ export const renderVideo = async ({entryPoint: path.join(projectRoot, 'remotion/index.ts'),});+ const binariesDirectory = getBinariesDirectory({isPackaged, projectRoot});const inputProps = {titleText: titleText.trim() || 'Hello from Electron',};@@ -173,6 +224,7 @@ export const renderVideo = async ({serveUrl,id: 'HelloWorld',inputProps,+ binariesDirectory,});await renderMedia({@@ -181,6 +233,7 @@ export const renderVideo = async ({codec: 'h264',outputLocation: outputPath,inputProps,+ binariesDirectory,});};```@@ -199,15 +252,15 @@ Run Remotion Studio in a separate terminal:npm run studio```-The first render may download Chrome Headless Shell. This is expected.+The first render may download Chrome Headless Shell. Surface that progress in your UI using `onBrowserDownload`.## Packaged appsDo not call `bundle()` inside the packaged app runtime.-Instead, build the Remotion bundle once during Electron Forge's package step and load that prebuilt folder from the app at runtime.+Instead, build the Remotion bundle once during Electron Forge's package step, copy the selected compositor package into the packaged app, and load that prebuilt folder from the app at runtime.-This still leaves one caveat: [`binariesDirectory`](/docs/renderer/render-media#binariesdirectory) may be needed for packaged rendering, because Remotion binaries must not be loaded from inside `app.asar`.+Use [`binariesDirectory`](/docs/renderer/render-media#binariesdirectory) for packaged renders and point it at the compositor package inside `app.asar.unpacked`, because Remotion binaries must not be loaded from inside `app.asar`.## See alsodiff --git a/packages/docs/src/components/IconForTemplate.tsx b/packages/docs/src/components/IconForTemplate.tsxindex a812e6dd98..532ad56b94 100644--- a/packages/docs/src/components/IconForTemplate.tsx+++ b/packages/docs/src/components/IconForTemplate.tsx@@ -4,6 +4,7 @@ import {Blank} from './icons/blank';import {BrainIcon} from './icons/brain';import {CodeHike} from './icons/code-hike';import {Cubes} from './icons/cubes';+import {ElectronIcon} from './icons/electron';import {JSIcon} from './icons/js';import {MusicIcon} from './icons/music';import {NextIcon} from './icons/next';@@ -49,6 +50,10 @@ export const IconForTemplate: React.FC<{return <RenderServerIcon style={{height: scale * 36}} />;}+ if (template.cliId === 'electron') {+ return <ElectronIcon style={{height: scale * 36}} />;+ }+if (template.cliId === 'javascript') {return (<JSIcondiff --git a/packages/docs/src/components/icons/electron.tsx b/packages/docs/src/components/icons/electron.tsxnew file mode 100644index 0000000000..e713695918--- /dev/null+++ b/packages/docs/src/components/icons/electron.tsx@@ -0,0 +1,14 @@+import React from 'react';++export const ElectronIcon: React.FC<{+ readonly style: React.CSSProperties;+}> = ({style}) => {+ return (+ <svg viewBox="0 0 640 640" style={style} xmlns="http://www.w3.org/2000/svg">+ <path+ d="M402 488.7C376.3 484 348.5 475.2 320 462.8C291.4 475.3 263.7 484.1 238 488.7C238.8 490.5 239.6 492.3 240.5 494.1C261.3 538 289.1 559.9 320 559.9C350.9 559.9 378.7 537.9 399.5 494.1C400.3 492.3 401.2 490.5 402 488.7zM320 576C277.2 576 243.6 543.3 221.6 491.2C168.9 497.3 126.6 484.4 106.4 448C85.7 410.9 97 365.2 130 320C97 274.8 85.7 229.1 106.4 192C126.6 155.7 168.9 142.7 221.6 148.8C243.6 96.7 277.3 64 320 64C362.7 64 396.4 96.7 418.4 148.8C471.1 142.7 513.4 155.6 533.6 192C554.3 229.1 543 274.8 510 320C543 365.2 554.3 410.9 533.6 448C513.4 484.3 471.1 497.3 418.4 491.2C396.4 543.3 362.7 576 320 576zM300.3 453.7C286.4 446.9 272.4 439.3 258.3 430.9C242.6 421.5 227.7 411.6 213.8 401.4C217.8 428 223.9 452.4 231.8 473.7C253.1 470.1 276.2 463.4 300.3 453.8zM408.2 473.6C416 452.4 422.1 428 426.2 401.3C412.3 411.6 397.4 421.5 381.7 430.8C367.7 439.2 353.6 446.8 339.7 453.6C363.8 463.2 386.9 469.9 408.2 473.5zM373.5 417.2C393.6 405.2 412.2 392.4 429.1 379.1C431.1 360.3 432.1 340.5 432.1 320.1C432.1 299.7 431.1 279.9 429.1 261.1C412.2 247.8 393.6 235 373.5 223C355.5 212.2 337.6 202.8 320.1 194.8C302.6 202.8 284.7 212.2 266.7 223C246.6 235 228 247.8 211.1 261.1C209.1 279.9 208.1 299.7 208.1 320.1C208.1 340.5 209.1 360.3 211.1 379.1C228 392.4 246.6 405.2 266.7 417.2C284.7 428 302.6 437.4 320.1 445.4C337.6 437.4 355.5 428 373.5 417.2zM424.5 475.8C425.4 475.9 426.3 476 427.2 476C473.5 479.9 504.8 467 519.7 440.2C534.8 413.1 529.6 377.9 503.1 337.9C502 336.3 501 334.7 499.8 333.1C484.5 351.6 465.8 369.9 444.2 387.3C440.4 419.8 433.7 449.7 424.5 475.6zM446.4 364.7C463.2 350.1 477.8 335 489.9 320C477.9 305 463.2 290 446.4 275.3C447.5 289.8 448.1 304.7 448.1 320C448.1 335.3 447.5 350.2 446.4 364.7zM503 302C529.6 262 534.7 226.8 519.6 199.7C504.7 172.9 473.3 160.1 427.1 164C426.2 164.1 425.3 164.2 424.4 164.2C433.6 190.2 440.3 220.1 444.1 252.5C465.7 270 484.4 288.2 499.7 306.7C500.8 305.1 501.9 303.5 503 301.9zM399.5 145.8C378.7 102 351 80 320 80C289 80 261.3 102 240.5 145.8C239.7 147.6 238.8 149.4 238 151.2C263.7 155.9 291.5 164.7 320 177.1C348.6 164.6 376.3 155.8 402 151.2C401.2 149.4 400.4 147.6 399.5 145.8zM408.1 166.4C386.8 170 363.7 176.7 339.6 186.3C353.5 193.1 367.5 200.7 381.6 209.1C397.3 218.5 412.2 228.4 426.1 238.6C422.1 212 416 187.6 408.1 166.3zM231.7 166.4C223.9 187.6 217.8 212 213.7 238.7C227.6 228.4 242.5 218.6 258.2 209.2C272.2 200.8 286.3 193.2 300.2 186.4C276.1 176.8 253 170.1 231.7 166.5zM215.5 164.2C214.6 164.1 213.7 164 212.8 164C166.5 160.1 135.2 173 120.3 199.7C105.2 226.8 110.4 262 136.9 302C138 303.6 139 305.2 140.2 306.8C155.5 288.3 174.2 270 195.8 252.6C199.6 220.1 206.3 190.2 215.5 164.3zM195.8 387.4C174.2 369.9 155.5 351.7 140.2 333.2C139.1 334.8 138 336.4 136.9 338C110.3 378 105.2 413.2 120.3 440.3C135.2 467.1 166.6 479.9 212.8 476.1C213.7 476 214.6 475.9 215.5 475.9C206.3 449.9 199.6 420 195.8 387.6zM193.7 275.3C176.9 289.9 162.3 305 150.2 320C162.2 335 176.9 350 193.7 364.7C192.6 350.2 192 335.3 192 320C192 304.7 192.6 289.8 193.7 275.3zM320 272C346.5 272 368 293.5 368 320C368 346.5 346.5 368 320 368C293.5 368 272 346.5 272 320C272 293.5 293.5 272 320 272zM352 320C352 302.3 337.7 288 320 288C302.3 288 288 302.3 288 320C288 337.7 302.3 352 320 352C337.7 352 352 337.7 352 320z"+ fill="currentColor"+ />+ </svg>+ );+};diff --git a/packages/docs/static/generated/template-electron.png b/packages/docs/static/generated/template-electron.pngnew file mode 100644index 0000000000..58c60ecb50Binary files /dev/null and b/packages/docs/static/generated/template-electron.png differdiff --git a/packages/it-tests/src/monorepo/get-all-packages.ts b/packages/it-tests/src/monorepo/get-all-packages.tsindex 332670f036..a54a738409 100644--- a/packages/it-tests/src/monorepo/get-all-packages.ts+++ b/packages/it-tests/src/monorepo/get-all-packages.ts@@ -3,7 +3,6 @@ import {readFileSync} from 'node:fs';import path from 'path';import {Pkgs, packages} from '@remotion/studio-shared';import {CreateVideoInternals} from 'create-video';-import {INTERNAL_TEMPLATES} from '../templates/internal-templates';export const getAllPackages = () => {const pkgDir = path.join(__dirname, '..', '..', '..');@@ -11,7 +10,6 @@ export const getAllPackages = () => {const localTemplates = CreateVideoInternals.FEATURED_TEMPLATES.map((t) => t.templateInMonorepo,).filter(Boolean) as string[];- const internalTemplates = INTERNAL_TEMPLATES.map((t) => t.templateInMonorepo);const folders = readdirSync(pkgDir).filter((pkg) => lstatSync(path.join(pkgDir, pkg)).isDirectory())@@ -29,7 +27,6 @@ export const getAllPackages = () => {.map((pkg) => pkg) as string[]).concat(localTemplates)- .concat(internalTemplates).sort();const packagesAndTemplates = folders.map((pkg) => pkg.pkg).sort() as string[];diff --git a/packages/it-tests/src/templates/electron-template-smoke.test.ts b/packages/it-tests/src/templates/electron-template-smoke.test.tsnew file mode 100644index 0000000000..7e7b36b1ca--- /dev/null+++ b/packages/it-tests/src/templates/electron-template-smoke.test.ts@@ -0,0 +1,131 @@+import {expect, test} from 'bun:test';+import {+ cpSync,+ existsSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ rmSync,+ statSync,+ writeFileSync,+} from 'node:fs';+import {tmpdir} from 'node:os';+import path from 'node:path';+import execa from 'execa';++const repoRoot = path.join(process.cwd(), '..', '..');+const templateRoot = path.join(process.cwd(), '..', 'template-electron');+const remotionVersion = JSON.parse(+ readFileSync(path.join(repoRoot, 'packages/core/package.json'), 'utf8'),+).version as string;++function getPackageRoot(workingDir: string): string {+ return path.join(+ workingDir,+ 'out',+ `template-electron-${process.platform}-${process.arch}`,+ );+}++function getPackagedResourcesPath(workingDir: string): string {+ const packageRoot = getPackageRoot(workingDir);++ if (process.platform === 'darwin') {+ return path.join(+ packageRoot,+ 'template-electron.app',+ 'Contents',+ 'Resources',+ );+ }++ return path.join(packageRoot, 'resources');+}++function getLaunchPath(workingDir: string): string {+ const packageRoot = getPackageRoot(workingDir);++ if (process.platform === 'darwin') {+ return path.join(+ packageRoot,+ 'template-electron.app',+ 'Contents',+ 'MacOS',+ 'template-electron',+ );+ }++ if (process.platform === 'win32') {+ return path.join(packageRoot, 'template-electron.exe');+ }++ return path.join(packageRoot, 'template-electron');+}++async function copyTemplateForPublishCheck(workingDir: string): Promise<void> {+ const {stdout} = await execa(+ 'git',+ ['ls-files', '--cached', '--others', '--exclude-standard'],+ {+ cwd: templateRoot,+ },+ );++ for (const file of stdout.split('\n').filter(Boolean)) {+ const src = path.join(templateRoot, file);+ const dst = path.join(workingDir, file);+ mkdirSync(path.dirname(dst), {recursive: true});+ cpSync(src, dst);+ }++ const packageJsonPath = path.join(workingDir, 'package.json');+ const contents = readFileSync(packageJsonPath, 'utf8');+ writeFileSync(+ packageJsonPath,+ contents.replaceAll('workspace:*', `^${remotionVersion}`),+ );+}++async function packagePublishedTemplate(workingDir: string): Promise<void> {+ await copyTemplateForPublishCheck(workingDir);+ await execa('bun', ['install'], {+ cwd: workingDir,+ stdio: 'inherit',+ });+ await execa('npm', ['run', 'package'], {+ cwd: workingDir,+ stdio: 'inherit',+ });+}++async function runPackagedRender(+ workingDir: string,+ outputPath: string,+): Promise<void> {+ const launchPath = getLaunchPath(workingDir);++ await execa(launchPath, ['--integration-render-test', outputPath], {+ cwd: path.dirname(launchPath),+ stdio: 'inherit',+ timeout: 240000,+ });+}++test('Electron template should package and render after publish-style dependency rewriting', async () => {+ const workingDir = mkdtempSync(path.join(tmpdir(), 'remotion-electron-'));+ const outputPath = path.join(workingDir, 'integration-render.mp4');++ try {+ await packagePublishedTemplate(workingDir);++ const resourcesPath = getPackagedResourcesPath(workingDir);+ expect(existsSync(path.join(resourcesPath, 'app.asar'))).toBe(true);++ await runPackagedRender(workingDir, outputPath);++ expect(existsSync(outputPath)).toBe(true);+ expect(statSync(outputPath).size).toBeGreaterThan(0);+ } finally {+ rmSync(workingDir, {recursive: true, force: true});+ }+}, 360000);diff --git a/packages/it-tests/src/templates/internal-templates.ts b/packages/it-tests/src/templates/internal-templates.tsdeleted file mode 100644index 1f3230de75..0000000000--- a/packages/it-tests/src/templates/internal-templates.ts+++ /dev/null@@ -1,6 +0,0 @@-export const INTERNAL_TEMPLATES = [- {- shortName: 'Electron',- templateInMonorepo: 'template-electron',- },-] as const;diff --git a/packages/it-tests/src/templates/validate-internal-templates.test.ts b/packages/it-tests/src/templates/validate-internal-templates.test.tsdeleted file mode 100644index 9cbaba37b4..0000000000--- a/packages/it-tests/src/templates/validate-internal-templates.test.ts+++ /dev/null@@ -1,169 +0,0 @@-import {describe, expect, it} from 'bun:test';-import {existsSync, readFileSync} from 'node:fs';-import path from 'node:path';-import {INTERNAL_TEMPLATES} from './internal-templates';--type InternalTemplate = (typeof INTERNAL_TEMPLATES)[number];--const getFileForTemplate = (template: InternalTemplate, file: string) => {- return path.join(process.cwd(), '..', template.templateInMonorepo, file);-};--const findFile = async (options: string[]) => {- let entryPoint: string | null = null;- let contents: string | null = null;- for (const point of options) {- if (existsSync(point)) {- entryPoint = point;- contents = readFileSync(point, 'utf-8');- break;- }- }-- return {entryPoint, contents};-};--describe('Internal templates should be valid', () => {- for (const template of INTERNAL_TEMPLATES) {- it(`${template.shortName} should have a valid package.json`, async () => {- const packageJson = getFileForTemplate(template, 'package.json');- const res = readFileSync(packageJson, 'utf8');- const body = JSON.parse(res);-- expect(body.private).toBe(true);- expect(body.name).toStartWith('template-');- expect(body.main).toBe('.vite/build/main.js');- expect(body.dependencies.remotion).toBe('workspace:*');- expect(body.dependencies['@remotion/cli']).toBe('workspace:*');- expect(body.dependencies['@remotion/bundler']).toBe('workspace:*');- expect(body.dependencies['@remotion/renderer']).toBe('workspace:*');- expect(body.dependencies.react).toMatch(/^\^?19/);- expect(body.dependencies['react-dom']).toMatch(/^\^?19/);- expect(body.devDependencies['@electron-forge/cli']).toBeTruthy();- expect(body.devDependencies['@electron-forge/plugin-vite']).toBeTruthy();-- const scripts = body.scripts;- expect(scripts.dev).toBe('electron-forge start');- expect(scripts.studio).toBe('remotion studio');- expect(scripts.build).toBe('electron-forge package');- expect(scripts.lint).toInclude('tsc --noEmit');- });-- it(`${template.shortName} should not have any lockfiles`, async () => {- expect(- existsSync(getFileForTemplate(template, 'package-lock.json')),- ).toBe(false);- expect(existsSync(getFileForTemplate(template, 'yarn.lock'))).toBe(false);- expect(existsSync(getFileForTemplate(template, 'pnpm-lock.yaml'))).toBe(- false,- );- expect(existsSync(getFileForTemplate(template, 'bun.lockb'))).toBe(false);- expect(existsSync(getFileForTemplate(template, 'bun.lock'))).toBe(false);- });-- it(`${template.shortName} should have a standard entry point`, async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'src/index.ts'),- getFileForTemplate(template, 'remotion/index.ts'),- getFileForTemplate(template, 'src/remotion/index.ts'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).toMatch(/RemotionRoot/);- });-- it(`${template.shortName} should have a standard Root file`, async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'src/Root.tsx'),- getFileForTemplate(template, 'remotion/Root.tsx'),- getFileForTemplate(template, 'src/remotion/Root.tsx'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).toMatch(/export const RemotionRoot/);- });-- it(`${template.shortName} should use the new config file format`, async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'remotion.config.ts'),- getFileForTemplate(template, 'remotion.config.js'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).not.toContain('Config.Rendering');- expect(contents).not.toContain('Config.Bundling');- expect(contents).not.toContain('Config.Log');- expect(contents).not.toContain('Config.Puppeteer');- expect(contents).not.toContain('Config.Output');- expect(contents).not.toContain('Config.Preview');- });-- it(`${template.shortName} should have Electron Forge Vite files`, async () => {- expect(existsSync(getFileForTemplate(template, 'forge.config.ts'))).toBe(- true,- );- expect(existsSync(getFileForTemplate(template, 'forge.env.d.ts'))).toBe(- true,- );- expect(- existsSync(getFileForTemplate(template, 'vite.main.config.ts')),- ).toBe(true);- expect(- existsSync(getFileForTemplate(template, 'vite.preload.config.ts')),- ).toBe(true);- expect(- existsSync(getFileForTemplate(template, 'vite.renderer.config.ts')),- ).toBe(true);- expect(existsSync(getFileForTemplate(template, 'src/main.ts'))).toBe(- true,- );- expect(existsSync(getFileForTemplate(template, 'src/preload.ts'))).toBe(- true,- );- expect(- existsSync(getFileForTemplate(template, 'src/remotion-bundle.ts')),- ).toBe(true);- expect(existsSync(getFileForTemplate(template, 'src/renderer.ts'))).toBe(- true,- );- expect(existsSync(getFileForTemplate(template, 'index.html'))).toBe(true);- });-- it(`${template.shortName} should prebuild the Remotion bundle during packaging`, async () => {- const forgeConfig = readFileSync(- getFileForTemplate(template, 'forge.config.ts'),- 'utf8',- );- expect(forgeConfig).toContain('packageAfterCopy');- expect(forgeConfig).toContain('getPrebuiltRemotionBundlePath');- });-- it(`${template.shortName} should use good tsconfig values`, async () => {- const tsconfig = getFileForTemplate(template, 'tsconfig.json');- const contents = readFileSync(tsconfig, 'utf8');- const parsed = JSON.parse(contents);-- expect(parsed.compilerOptions.noUnusedLocals).toBe(true);- expect(parsed.exclude).toContain('remotion.config.ts');- });-- it(`${template.shortName} should reference commands`, async () => {- const readme = readFileSync(- getFileForTemplate(template, 'README.md'),- 'utf8',- );- expect(readme).toInclude('npm run dev');- expect(readme).toInclude('npm run studio');- expect(readme).toInclude('npx remotion render');- expect(readme).toInclude('npx remotion upgrade');- });-- it(`${template.shortName} should be registered in tsconfig.json`, async () => {- const tsconfig = path.join(process.cwd(), '..', '..', 'tsconfig.json');- const contents = readFileSync(tsconfig, 'utf8');- const parsed = JSON.parse(contents);- const references = parsed.references.map((r: {path: string}) =>- r.path.replace('./packages/', ''),- );-- expect(references).toContain(template.templateInMonorepo);- });- }-});diff --git a/packages/it-tests/src/templates/validate-templates.test.ts b/packages/it-tests/src/templates/validate-templates.test.tsindex 1542f926e9..e1b8d283bd 100644--- a/packages/it-tests/src/templates/validate-templates.test.ts+++ b/packages/it-tests/src/templates/validate-templates.test.ts@@ -118,10 +118,10 @@ describe('Templates should be valid', () => {const scripts = body.scripts;expect(scripts.dev).toMatch(- /(remotion\sstudio)|(next dev)|(react-router dev)|(tsx watch)|(tsx src\/studio)|(bun studio\.ts)/,+ /(remotion\sstudio)|(next dev)|(react-router dev)|(tsx watch)|(tsx src\/studio)|(bun studio\.ts)|(electron-forge start)/,);expect(scripts.build).toMatch(- /(remotion\sbundle)|(react-router build)|(next\sbuild)|(tsx src\/render)|(tsc \&\& vite build)|(bun build\.ts)/,+ /(remotion\sbundle)|(react-router build)|(next\sbuild)|(tsx src\/render)|(tsc \&\& vite build)|(bun build\.ts)|(electron-forge package)/,);});@@ -176,6 +176,63 @@ describe('Templates should be valid', () => {expect(contents).not.toContain('Config.Preview');});+ it(`${template.shortName} should keep template-specific packaging files in sync`, async () => {+ if (template.templateInMonorepo !== 'template-electron') {+ return;+ }++ const packageJson = JSON.parse(+ readFileSync(getFileForTemplate(template, 'package.json'), 'utf8'),+ );+ expect(+ packageJson.optionalDependencies['@remotion/compositor-linux-x64-musl'],+ ).toBe('workspace:*');+ expect(+ packageJson.optionalDependencies[+ '@remotion/compositor-linux-arm64-musl'+ ],+ ).toBe('workspace:*');++ expect(existsSync(getFileForTemplate(template, 'forge.config.ts'))).toBe(+ true,+ );+ expect(existsSync(getFileForTemplate(template, 'forge.env.d.ts'))).toBe(+ true,+ );+ expect(+ existsSync(getFileForTemplate(template, 'vite.main.config.ts')),+ ).toBe(true);+ expect(+ existsSync(getFileForTemplate(template, 'vite.preload.config.ts')),+ ).toBe(true);+ expect(+ existsSync(getFileForTemplate(template, 'vite.renderer.config.ts')),+ ).toBe(true);+ expect(existsSync(getFileForTemplate(template, 'src/main.ts'))).toBe(+ true,+ );+ expect(existsSync(getFileForTemplate(template, 'src/preload.ts'))).toBe(+ true,+ );+ expect(+ existsSync(getFileForTemplate(template, 'src/remotion-bundle.ts')),+ ).toBe(true);+ expect(existsSync(getFileForTemplate(template, 'src/renderer.ts'))).toBe(+ true,+ );+ expect(existsSync(getFileForTemplate(template, 'index.html'))).toBe(true);++ const forgeConfig = readFileSync(+ getFileForTemplate(template, 'forge.config.ts'),+ 'utf8',+ );+ expect(forgeConfig).toContain('packageAfterCopy');+ expect(forgeConfig).toContain('getPrebuiltRemotionBundlePath');+ expect(forgeConfig).toContain(+ 'stage the selected compositor package explicitly',+ );+ });+it(`${template.shortName} should not use setExperimentalClientSideRenderingEnabled`, async () => {const {contents, entryPoint} = await findFile([getFileForTemplate(template, 'remotion.config.ts'),diff --git a/packages/promo-pages/src/components/homepage/IconForTemplate.tsx b/packages/promo-pages/src/components/homepage/IconForTemplate.tsxindex 7f29b00649..393d373ef6 100644--- a/packages/promo-pages/src/components/homepage/IconForTemplate.tsx+++ b/packages/promo-pages/src/components/homepage/IconForTemplate.tsx@@ -4,6 +4,7 @@ import {Blank} from '../icons/blank';import {BrainIcon} from '../icons/brain';import {CodeHike} from '../icons/code-hike';import {Cubes} from '../icons/cubes';+import {ElectronIcon} from '../icons/electron';import {JSIcon} from '../icons/js';import {MusicIcon} from '../icons/music';import {NextIcon} from '../icons/next';@@ -123,6 +124,10 @@ export const IconForTemplate: React.FC<{return <RenderServerIcon style={{height: scale * 36}} />;}+ if (template.cliId === 'electron') {+ return <ElectronIcon style={{height: scale * 36}} />;+ }+if (template.cliId === 'recorder') {return <Recorder style={{height: scale * 36}} />;}diff --git a/packages/promo-pages/src/components/icons/electron.tsx b/packages/promo-pages/src/components/icons/electron.tsxnew file mode 100644index 0000000000..72972e23bb--- /dev/null+++ b/packages/promo-pages/src/components/icons/electron.tsx@@ -0,0 +1,18 @@+import React from 'react';++export const ElectronIcon: React.FC<{+ readonly style: React.CSSProperties;+}> = ({style}) => {+ return (+ <svg+ viewBox="0 0 640 640"+ style={style}+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M402 488.7C376.3 484 348.5 475.2 320 462.8C291.4 475.3 263.7 484.1 238 488.7C238.8 490.5 239.6 492.3 240.5 494.1C261.3 538 289.1 559.9 320 559.9C350.9 559.9 378.7 537.9 399.5 494.1C400.3 492.3 401.2 490.5 402 488.7zM320 576C277.2 576 243.6 543.3 221.6 491.2C168.9 497.3 126.6 484.4 106.4 448C85.7 410.9 97 365.2 130 320C97 274.8 85.7 229.1 106.4 192C126.6 155.7 168.9 142.7 221.6 148.8C243.6 96.7 277.3 64 320 64C362.7 64 396.4 96.7 418.4 148.8C471.1 142.7 513.4 155.6 533.6 192C554.3 229.1 543 274.8 510 320C543 365.2 554.3 410.9 533.6 448C513.4 484.3 471.1 497.3 418.4 491.2C396.4 543.3 362.7 576 320 576zM300.3 453.7C286.4 446.9 272.4 439.3 258.3 430.9C242.6 421.5 227.7 411.6 213.8 401.4C217.8 428 223.9 452.4 231.8 473.7C253.1 470.1 276.2 463.4 300.3 453.8zM408.2 473.6C416 452.4 422.1 428 426.2 401.3C412.3 411.6 397.4 421.5 381.7 430.8C367.7 439.2 353.6 446.8 339.7 453.6C363.8 463.2 386.9 469.9 408.2 473.5zM373.5 417.2C393.6 405.2 412.2 392.4 429.1 379.1C431.1 360.3 432.1 340.5 432.1 320.1C432.1 299.7 431.1 279.9 429.1 261.1C412.2 247.8 393.6 235 373.5 223C355.5 212.2 337.6 202.8 320.1 194.8C302.6 202.8 284.7 212.2 266.7 223C246.6 235 228 247.8 211.1 261.1C209.1 279.9 208.1 299.7 208.1 320.1C208.1 340.5 209.1 360.3 211.1 379.1C228 392.4 246.6 405.2 266.7 417.2C284.7 428 302.6 437.4 320.1 445.4C337.6 437.4 355.5 428 373.5 417.2zM424.5 475.8C425.4 475.9 426.3 476 427.2 476C473.5 479.9 504.8 467 519.7 440.2C534.8 413.1 529.6 377.9 503.1 337.9C502 336.3 501 334.7 499.8 333.1C484.5 351.6 465.8 369.9 444.2 387.3C440.4 419.8 433.7 449.7 424.5 475.6zM446.4 364.7C463.2 350.1 477.8 335 489.9 320C477.9 305 463.2 290 446.4 275.3C447.5 289.8 448.1 304.7 448.1 320C448.1 335.3 447.5 350.2 446.4 364.7zM503 302C529.6 262 534.7 226.8 519.6 199.7C504.7 172.9 473.3 160.1 427.1 164C426.2 164.1 425.3 164.2 424.4 164.2C433.6 190.2 440.3 220.1 444.1 252.5C465.7 270 484.4 288.2 499.7 306.7C500.8 305.1 501.9 303.5 503 301.9zM399.5 145.8C378.7 102 351 80 320 80C289 80 261.3 102 240.5 145.8C239.7 147.6 238.8 149.4 238 151.2C263.7 155.9 291.5 164.7 320 177.1C348.6 164.6 376.3 155.8 402 151.2C401.2 149.4 400.4 147.6 399.5 145.8zM408.1 166.4C386.8 170 363.7 176.7 339.6 186.3C353.5 193.1 367.5 200.7 381.6 209.1C397.3 218.5 412.2 228.4 426.1 238.6C422.1 212 416 187.6 408.1 166.3zM231.7 166.4C223.9 187.6 217.8 212 213.7 238.7C227.6 228.4 242.5 218.6 258.2 209.2C272.2 200.8 286.3 193.2 300.2 186.4C276.1 176.8 253 170.1 231.7 166.5zM215.5 164.2C214.6 164.1 213.7 164 212.8 164C166.5 160.1 135.2 173 120.3 199.7C105.2 226.8 110.4 262 136.9 302C138 303.6 139 305.2 140.2 306.8C155.5 288.3 174.2 270 195.8 252.6C199.6 220.1 206.3 190.2 215.5 164.3zM195.8 387.4C174.2 369.9 155.5 351.7 140.2 333.2C139.1 334.8 138 336.4 136.9 338C110.3 378 105.2 413.2 120.3 440.3C135.2 467.1 166.6 479.9 212.8 476.1C213.7 476 214.6 475.9 215.5 475.9C206.3 449.9 199.6 420 195.8 387.6zM193.7 275.3C176.9 289.9 162.3 305 150.2 320C162.2 335 176.9 350 193.7 364.7C192.6 350.2 192 335.3 192 320C192 304.7 192.6 289.8 193.7 275.3zM320 272C346.5 272 368 293.5 368 320C368 346.5 346.5 368 320 368C293.5 368 272 346.5 272 320C272 293.5 293.5 272 320 272zM352 320C352 302.3 337.7 288 320 288C302.3 288 288 302.3 288 320C288 337.7 302.3 352 320 352C337.7 352 352 337.7 352 320z"+ fill="currentColor"+ />+ </svg>+ );+};diff --git a/packages/template-electron/README.md b/packages/template-electron/README.mdindex 1bbb9981a6..f44dcee5db 100644--- a/packages/template-electron/README.md+++ b/packages/template-electron/README.md@@ -25,9 +25,9 @@ npm installnpm run dev```-Type a title, then click the render button in the app window. The video will be written to your `Downloads` folder.+Type a title, then click the render button in the app window. The app will ask where to save the video before rendering.-In development, the Remotion project is bundled on each render so composition changes are always picked up.+In development, the Remotion project is bundled on each render so composition changes are always picked up. The first render may also download Chrome Headless Shell if no compatible local browser is installed yet.**Run Remotion Studio**@@ -47,7 +47,9 @@ npx remotion render HelloWorldnpm run build```-During `npm run build`, Electron Forge creates a prebuilt Remotion bundle as part of the package step. The packaged app reuses that bundle at runtime instead of calling `bundle()` again.+During `npm run build`, Electron Forge creates a prebuilt Remotion bundle and stages the matching Remotion compositor package as part of the package step. The packaged app reuses that bundle at runtime instead of calling `bundle()` again.++The packaged binary also accepts `--integration-render-test <absolute-output-path>` for Remotion's automated integration test. It starts a hidden render immediately and is not needed for normal app usage, so feel free to remove `src/integration-render-test-mode.ts` and its import from `src/main.ts` in your own app.**Upgrade all Remotion packages**diff --git a/packages/template-electron/forge.config.ts b/packages/template-electron/forge.config.tsindex caf70f06fd..3e70cd7e75 100644--- a/packages/template-electron/forge.config.ts+++ b/packages/template-electron/forge.config.ts@@ -24,9 +24,8 @@ const config = {outDir: getPrebuiltRemotionBundlePath(buildPath),});- // TODO: Remove these manual runtime package copies before making this a public template.- // End users should get the packaged Remotion runtime through normal dependency installation,- // not through monorepo-specific Electron Forge copy workarounds.+ // Electron Forge's Vite packaging does not materialize this optional runtime binary+ // into the packaged app automatically, so stage the selected compositor package explicitly.const compositorPackage = getCompositorPackage({arch,platform,diff --git a/packages/template-electron/index.html b/packages/template-electron/index.htmlindex b3c413abc3..fb6f968b36 100644--- a/packages/template-electron/index.html+++ b/packages/template-electron/index.html@@ -6,6 +6,10 @@name="viewport"content="width=device-width, initial-scale=1.0"/>+ <meta+ http-equiv="Content-Security-Policy"+ content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' http://localhost:* ws://localhost:* http://127.0.0.1:* ws://127.0.0.1:*; font-src 'self' data:;"+ /><title>Remotion + Electron</title></head><body>diff --git a/packages/template-electron/package.json b/packages/template-electron/package.jsonindex 76dcd1a133..1b666c72e2 100644--- a/packages/template-electron/package.json+++ b/packages/template-electron/package.json@@ -29,7 +29,9 @@"@remotion/compositor-darwin-arm64": "workspace:*","@remotion/compositor-darwin-x64": "workspace:*","@remotion/compositor-linux-arm64-gnu": "workspace:*",+ "@remotion/compositor-linux-arm64-musl": "workspace:*","@remotion/compositor-linux-x64-gnu": "workspace:*",+ "@remotion/compositor-linux-x64-musl": "workspace:*","@remotion/compositor-win32-x64-msvc": "workspace:*"},"devDependencies": {diff --git a/packages/template-electron/src/App.tsx b/packages/template-electron/src/App.tsxindex 7b1ab9a54d..618bc9ffe3 100644--- a/packages/template-electron/src/App.tsx+++ b/packages/template-electron/src/App.tsx@@ -1,5 +1,18 @@import {useEffect, useState} from "react";+function getProgressLabel(stage: "browser-download" | "bundling" | "rendering") {+ switch (stage) {+ case "browser-download":+ return "Downloading Chrome Headless Shell";+ case "bundling":+ return "Bundling the Remotion project";+ case "rendering":+ return "Rendering video";+ default:+ throw new Error(`Unknown render stage: ${stage satisfies never}`);+ }+}+export const App: React.FC = () => {const [titleText, setTitleText] = useState("Hello from Electron");const [status, setStatus] = useState("Ready to render.");@@ -14,11 +27,7 @@ export const App: React.FC = () => {}const rounded = Math.round(update.progress);- const label =- update.stage === "bundling"- ? "Bundling the Remotion project"- : "Rendering video";- setStatus(`${label}: ${rounded}%`);+ setStatus(`${getProgressLabel(update.stage)}: ${rounded}%`);});}, []);@@ -42,7 +51,7 @@ export const App: React.FC = () => {});setStatus("Render complete.");- setResult(`Saved to ${outputPath} and revealed in Finder.`);+ setResult(`Saved to ${outputPath} and revealed in your file manager.`);} catch (error) {const message =error instanceof Errordiff --git a/packages/template-electron/src/compositor-package.ts b/packages/template-electron/src/compositor-package.tsindex 14ccfbd2cc..68fd0b30c5 100644--- a/packages/template-electron/src/compositor-package.ts+++ b/packages/template-electron/src/compositor-package.ts@@ -1,28 +1,61 @@+type LinuxLibc = "gnu" | "musl";++const getLinuxLibc = (): LinuxLibc => {+ const report = process.report?.getReport();++ if (!report || typeof report === "string") {+ return "gnu";+ }++ const header = (report as {header?: {glibcVersionRuntime?: string}}).header;+ return header?.glibcVersionRuntime ? "gnu" : "musl";+};++function getLinuxCompositorPackage(arch: string, libc: LinuxLibc) {+ switch (arch) {+ case "x64":+ return libc === "musl"+ ? "@remotion/compositor-linux-x64-musl"+ : "@remotion/compositor-linux-x64-gnu";+ case "arm64":+ return libc === "musl"+ ? "@remotion/compositor-linux-arm64-musl"+ : "@remotion/compositor-linux-arm64-gnu";+ default:+ throw new Error(`Unsupported Linux architecture: ${arch}`);+ }+}+export const getCompositorPackage = ({arch,platform,+ libc = platform === "linux" ? getLinuxLibc() : undefined,}: {arch: string;platform: string;+ libc?: LinuxLibc;}) => {- if (platform === "darwin" && arch === "arm64") {- return "@remotion/compositor-darwin-arm64";- }-- if (platform === "darwin" && arch === "x64") {- return "@remotion/compositor-darwin-x64";- }+ switch (platform) {+ case "darwin":+ if (arch === "arm64") {+ return "@remotion/compositor-darwin-arm64";+ }- if (platform === "linux" && arch === "x64") {- return "@remotion/compositor-linux-x64-gnu";- }+ if (arch === "x64") {+ return "@remotion/compositor-darwin-x64";+ }- if (platform === "linux" && arch === "arm64") {- return "@remotion/compositor-linux-arm64-gnu";- }+ break;+ case "linux":+ return getLinuxCompositorPackage(arch, libc ?? getLinuxLibc());+ case "win32":+ if (arch === "x64") {+ return "@remotion/compositor-win32-x64-msvc";+ }- if (platform === "win32" && arch === "x64") {- return "@remotion/compositor-win32-x64-msvc";+ break;+ default:+ break;}throw new Error(`Unsupported platform/arch combination: ${platform}/${arch}`);diff --git a/packages/template-electron/src/electron-api.ts b/packages/template-electron/src/electron-api.tsindex 6ab550730d..cc5b46604f 100644--- a/packages/template-electron/src/electron-api.ts+++ b/packages/template-electron/src/electron-api.ts@@ -23,7 +23,7 @@ export type RenderUpdate =}| {type: "progress";- stage: "bundling" | "rendering";+ stage: "browser-download" | "bundling" | "rendering";progress: number;};diff --git a/packages/template-electron/src/integration-render-test-mode.ts b/packages/template-electron/src/integration-render-test-mode.tsnew file mode 100644index 0000000000..ebc627f418--- /dev/null+++ b/packages/template-electron/src/integration-render-test-mode.ts@@ -0,0 +1,52 @@+import {app} from "electron";+import path from "node:path";+import {renderVideo} from "./render-video";++export function getIntegrationRenderOutputPath(): string | null {+ const flagIndex = process.argv.indexOf("--integration-render-test");++ if (flagIndex === -1) {+ return null;+ }++ return process.argv[flagIndex + 1] ?? null;+}++export async function runIntegrationRenderTest(+ outputPath: string,+): Promise<void> {+ if (!path.isAbsolute(outputPath)) {+ throw new Error("Integration render output path must be absolute.");+ }++ try {+ const result = await renderVideo({+ isPackaged: app.isPackaged,+ outputPath,+ projectRoot: app.getAppPath(),+ titleText: "Integration render test",+ onUpdate: (update) => {+ if (update.type === "status") {+ console.log("[integration-render] " + update.message);+ return;+ }++ console.log(+ "[integration-render] " ++ update.stage ++ ": " ++ Math.round(update.progress) ++ "%",+ );+ },+ });++ console.log("[integration-render] complete: " + result.outputPath);+ app.exit(0);+ } catch (error) {+ const message =+ error instanceof Error ? error.stack ?? error.message : String(error);+ console.error(`[integration-render] failed: ${message}`);+ app.exit(1);+ }+}diff --git a/packages/template-electron/src/main.ts b/packages/template-electron/src/main.tsindex 9b776075f3..aaaf4dd14a 100644--- a/packages/template-electron/src/main.ts+++ b/packages/template-electron/src/main.ts@@ -1,4 +1,11 @@-import {app, BrowserWindow, dialog, ipcMain, shell} from "electron";+import {+ app,+ BrowserWindow,+ dialog,+ ipcMain,+ shell,+ type IpcMainInvokeEvent,+} from "electron";import path from "node:path";import {RENDER_PROGRESS_CHANNEL,@@ -8,10 +15,15 @@ import {type RenderResult,type RenderUpdate,} from "./electron-api";+import {+ getIntegrationRenderOutputPath,+ runIntegrationRenderTest,+} from "./integration-render-test-mode";import {renderVideo} from "./render-video";let mainWindow: BrowserWindow | null = null;let activeRender: Promise<RenderResult> | null = null;+const integrationRenderOutputPath = getIntegrationRenderOutputPath();if (app.isPackaged) {process.chdir(app.getPath("userData"));@@ -21,15 +33,25 @@ const sendRenderUpdate = (update: RenderUpdate) => {mainWindow?.webContents.send(RENDER_PROGRESS_CHANNEL, update);};+const assertTrustedSender = (event: IpcMainInvokeEvent) => {+ if (!mainWindow || event.sender.id !== mainWindow.webContents.id) {+ throw new Error("Blocked IPC call from an unknown renderer.");+ }+};+const createWindow = () => {mainWindow = new BrowserWindow({width: 960,height: 760,webPreferences: {contextIsolation: true,+ nodeIntegration: false,preload: path.join(__dirname, "preload.js"),},});+ mainWindow.webContents.setWindowOpenHandler(() => {+ return {action: "deny"};+ });if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);@@ -40,7 +62,9 @@ const createWindow = () => {}};-ipcMain.handle(SELECT_RENDER_OUTPUT_CHANNEL, async () => {+ipcMain.handle(SELECT_RENDER_OUTPUT_CHANNEL, async (event) => {+ assertTrustedSender(event);+const defaultPath = path.join(app.getPath("downloads"),`remotion-electron-${Date.now()}.mp4`,@@ -71,11 +95,17 @@ ipcMain.handle(SELECT_RENDER_OUTPUT_CHANNEL, async () => {};});-ipcMain.handle(RENDER_VIDEO_CHANNEL, async (_event, input: RenderRequest) => {+ipcMain.handle(RENDER_VIDEO_CHANNEL, async (event, input: RenderRequest) => {+ assertTrustedSender(event);+if (activeRender) {throw new Error("A render is already in progress.");}+ if (!path.isAbsolute(input.outputPath)) {+ throw new Error("Output path must be absolute.");+ }+activeRender = renderVideo({isPackaged: app.isPackaged,outputPath: input.outputPath,@@ -104,7 +134,14 @@ ipcMain.handle(RENDER_VIDEO_CHANNEL, async (_event, input: RenderRequest) => {}});-app.on("ready", createWindow);+app.on("ready", () => {+ if (integrationRenderOutputPath) {+ void runIntegrationRenderTest(integrationRenderOutputPath);+ return;+ }++ createWindow();+});app.on("window-all-closed", () => {if (process.platform !== "darwin") {@@ -113,6 +150,10 @@ app.on("window-all-closed", () => {});app.on("activate", () => {+ if (integrationRenderOutputPath) {+ return;+ }+if (BrowserWindow.getAllWindows().length === 0) {createWindow();}diff --git a/packages/template-electron/src/render-video.ts b/packages/template-electron/src/render-video.tsindex d273152547..8368b1f407 100644--- a/packages/template-electron/src/render-video.ts+++ b/packages/template-electron/src/render-video.ts@@ -82,7 +82,32 @@ export const renderVideo = async ({titleText: string;onUpdate?: (update: RenderUpdate) => void;}): Promise<RenderResult> => {- await ensureBrowser();+ onUpdate?.({+ type: "status",+ message: "Checking browser installation...",+ });+ await ensureBrowser({+ onBrowserDownload: ({chromeMode}) => {+ const browserName =+ chromeMode === "chrome-for-testing" ? "Chrome" : "Chrome Headless Shell";++ onUpdate?.({+ type: "status",+ message: `Downloading ${browserName}...`,+ });++ return {+ version: null,+ onProgress: (progress) => {+ onUpdate?.({+ type: "progress",+ stage: "browser-download",+ progress: progress.percent,+ });+ },+ };+ },+ });const serveUrl = await getServeUrl({isPackaged,