Spaces:
Configuration error
Configuration error
Dee Ferdinand commited on
Commit ·
5a4b7f7
1
Parent(s): 017f3f3
fix: run hyperframes from inside compDir with relative paths (cwd=compDir, ./index.html, -o ./render.mp4)
Browse files- lib/renderer.js +32 -26
lib/renderer.js
CHANGED
|
@@ -7,12 +7,11 @@ export async function renderVideo(compDir, outputFile, config, onProgress) {
|
|
| 7 |
const [w, h] = format === '9:16' ? [1080, 1920] : format === '1:1' ? [1080, 1080] : [1920, 1080];
|
| 8 |
onProgress?.(0);
|
| 9 |
|
| 10 |
-
//
|
| 11 |
fs.writeFileSync(path.join(compDir, 'meta.json'), JSON.stringify(
|
| 12 |
{ duration, width: w, height: h, fps: 30 }, null, 2
|
| 13 |
));
|
| 14 |
|
| 15 |
-
// Detect Chrome
|
| 16 |
const chromePath = [
|
| 17 |
process.env.PUPPETEER_EXECUTABLE_PATH,
|
| 18 |
process.env.CHROME_PATH,
|
|
@@ -21,26 +20,25 @@ export async function renderVideo(compDir, outputFile, config, onProgress) {
|
|
| 21 |
'/usr/bin/google-chrome',
|
| 22 |
].find(p => p && fs.existsSync(p));
|
| 23 |
|
| 24 |
-
console.log(`[renderer] Chrome: ${chromePath
|
| 25 |
|
| 26 |
-
//
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
'-o', outputFile,
|
| 30 |
-
];
|
| 31 |
-
|
| 32 |
-
const env = {
|
| 33 |
-
...process.env,
|
| 34 |
-
PUPPETEER_EXECUTABLE_PATH: chromePath || '/usr/bin/chromium',
|
| 35 |
-
CHROME_PATH: chromePath || '/usr/bin/chromium',
|
| 36 |
-
};
|
| 37 |
|
| 38 |
return new Promise((resolve, reject) => {
|
| 39 |
-
const proc = execFile(
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
let stderr = '';
|
| 46 |
proc.stdout?.on('data', (d) => {
|
|
@@ -49,13 +47,21 @@ export async function renderVideo(compDir, outputFile, config, onProgress) {
|
|
| 49 |
const m = line.match(/frame\s+(\d+)\/(\d+)/i);
|
| 50 |
if (m) onProgress?.(parseInt(m[1]) / parseInt(m[2]));
|
| 51 |
});
|
| 52 |
-
proc.stderr?.on('data', (d) => {
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
});
|
| 60 |
});
|
| 61 |
}
|
|
|
|
| 7 |
const [w, h] = format === '9:16' ? [1080, 1920] : format === '1:1' ? [1080, 1080] : [1920, 1080];
|
| 8 |
onProgress?.(0);
|
| 9 |
|
| 10 |
+
// meta.json tells HyperFrames the canvas size and duration
|
| 11 |
fs.writeFileSync(path.join(compDir, 'meta.json'), JSON.stringify(
|
| 12 |
{ duration, width: w, height: h, fps: 30 }, null, 2
|
| 13 |
));
|
| 14 |
|
|
|
|
| 15 |
const chromePath = [
|
| 16 |
process.env.PUPPETEER_EXECUTABLE_PATH,
|
| 17 |
process.env.CHROME_PATH,
|
|
|
|
| 20 |
'/usr/bin/google-chrome',
|
| 21 |
].find(p => p && fs.existsSync(p));
|
| 22 |
|
| 23 |
+
console.log(`[renderer] Chrome: ${chromePath} | ${w}x${h} | ${duration}s | cwd: ${compDir}`);
|
| 24 |
|
| 25 |
+
// Run from INSIDE compDir using relative paths
|
| 26 |
+
// CLI: npx hyperframes render ./index.html -o ./output.mp4
|
| 27 |
+
const localOutput = './render_out.mp4';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
return new Promise((resolve, reject) => {
|
| 30 |
+
const proc = execFile(
|
| 31 |
+
'npx', ['hyperframes', 'render', './index.html', '-o', localOutput],
|
| 32 |
+
{
|
| 33 |
+
cwd: compDir, // <-- run from inside the project directory
|
| 34 |
+
maxBuffer: 500 * 1024 * 1024,
|
| 35 |
+
env: {
|
| 36 |
+
...process.env,
|
| 37 |
+
PUPPETEER_EXECUTABLE_PATH: chromePath || '/usr/bin/chromium',
|
| 38 |
+
CHROME_PATH: chromePath || '/usr/bin/chromium',
|
| 39 |
+
},
|
| 40 |
+
}
|
| 41 |
+
);
|
| 42 |
|
| 43 |
let stderr = '';
|
| 44 |
proc.stdout?.on('data', (d) => {
|
|
|
|
| 47 |
const m = line.match(/frame\s+(\d+)\/(\d+)/i);
|
| 48 |
if (m) onProgress?.(parseInt(m[1]) / parseInt(m[2]));
|
| 49 |
});
|
| 50 |
+
proc.stderr?.on('data', (d) => { stderr += d; process.stderr.write(d); });
|
| 51 |
+
proc.on('close', async (code) => {
|
| 52 |
+
if (code !== 0) {
|
| 53 |
+
reject(new Error(`HyperFrames render failed:\n${stderr.slice(-800)}`));
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
// Move output to final destination
|
| 57 |
+
const rendered = path.join(compDir, 'render_out.mp4');
|
| 58 |
+
if (fs.existsSync(rendered)) {
|
| 59 |
+
fs.renameSync(rendered, outputFile);
|
| 60 |
+
onProgress?.(1);
|
| 61 |
+
resolve(outputFile);
|
| 62 |
+
} else {
|
| 63 |
+
reject(new Error('Render completed but output file not found'));
|
| 64 |
+
}
|
| 65 |
});
|
| 66 |
});
|
| 67 |
}
|