File size: 1,497 Bytes
41f10a5 4f0e4df 41f10a5 4f0e4df 41f10a5 4f0e4df 41f10a5 4f0e4df 41f10a5 4f0e4df 41f10a5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import express from 'express';
import fs from 'fs';
import path from 'path';
import { bundle } from '@remotion/bundler';
import { renderMedia, selectComposition } from '@remotion/renderer';
const app = express();
app.use(express.json());
const OUTPUT_DIR = './out';
if (!fs.existsSync(OUTPUT_DIR)) fs.mkdirSync(OUTPUT_DIR);
app.post('/render', async (req, res) => {
try {
const inputProps = req.body || {}; // pass your script from frontend
const entryPoint = './remotion/src/index.tsx';
const bundled = await bundle({ entryPoint });
const composition = await selectComposition({
serveUrl: bundled,
id: 'VideoComposition', // MUST MATCH your index.tsx Composition id
inputProps,
onBrowserDownload: (progress) => {
console.log(`Chrome download progress: ${progress.percent.toFixed(2)}%`);
},
});
console.log('=== SCENES TO RENDER ===', inputProps.script?.scenes || []);
const outputPath = path.join(OUTPUT_DIR, `${composition.id}.mp4`);
await renderMedia({
serveUrl: bundled,
composition,
outputLocation: outputPath,
chromiumOptions: {
enableMultiProcessOnLinux: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
},
inputProps,
});
res.download(outputPath);
} catch (err) {
console.error('Render error:', err);
res.status(500).json({ error: err.message });
}
});
app.listen(7860, () => console.log('🚀 Server running on port 7860'));
|