| 1 | import {bundle} from '@remotion/bundler'; |
| 2 | import {getCompositions, renderMedia, selectComposition} from '@remotion/renderer'; |
| 3 | import path from 'node:path'; |
| 4 | import os from 'node:os'; |
| 5 | |
| 6 | const format = process.argv[2]; |
| 7 | if (!format || !['mp4', 'webm'].includes(format)) { |
| 8 | console.error('Usage: node scripts/render.mjs <mp4|webm>'); |
| 9 | process.exit(1); |
| 10 | } |
| 11 | |
| 12 | const root = path.resolve(process.cwd()); |
| 13 | const entry = path.join(root, 'src', 'index.ts'); |
| 14 | |
| 15 | const outDir = path.resolve(root, '..', '..', 'docs', 'assets', 'hero'); |
| 16 | const outPath = path.join(outDir, `copilot-hub.${format}`); |
| 17 | |
| 18 | const tmpDir = path.join(os.tmpdir(), 'copilot-remotion-bundle'); |
| 19 | |
| 20 | const serveUrl = await bundle({ |
| 21 | entryPoint: entry, |
| 22 | outDir: tmpDir, |
| 23 | webpackOverride: (config) => config, |
| 24 | }); |
| 25 | |
| 26 | // Resolve composition metadata (duration, fps, etc.) |
| 27 | const composition = await selectComposition({ |
| 28 | serveUrl, |
| 29 | id: 'copilot-hub', |
| 30 | inputProps: {}, |
| 31 | }); |
| 32 | |
| 33 | await renderMedia({ |
| 34 | composition, |
| 35 | serveUrl, |
| 36 | codec: format === 'webm' ? 'vp9' : 'h264', |
| 37 | outputLocation: outPath, |
| 38 | inputProps: {}, |
| 39 | crf: format === 'webm' ? 36 : 22, |
| 40 | pixelFormat: 'yuv420p', |
| 41 | mute: true, |
| 42 | }); |
| 43 | |
| 44 | console.log(`Rendered ${outPath}`); |