Spaces:
Configuration error
Configuration error
Dee Ferdinand commited on
Commit ·
017f3f3
1
Parent(s): b132b92
fix: correct HyperFrames CLI syntax — render takes file path + -o flag, not --width/--height args
Browse files- lib/renderer.js +19 -29
lib/renderer.js
CHANGED
|
@@ -1,52 +1,45 @@
|
|
| 1 |
import { execFile } from 'child_process';
|
| 2 |
-
import { promisify } from 'util';
|
| 3 |
import path from 'path';
|
| 4 |
import fs from 'fs';
|
| 5 |
|
| 6 |
-
const execFileAsync = promisify(execFile);
|
| 7 |
-
|
| 8 |
export async function renderVideo(compDir, outputFile, config, onProgress) {
|
| 9 |
const { format = '9:16', duration = 75 } = config;
|
| 10 |
const [w, h] = format === '9:16' ? [1080, 1920] : format === '1:1' ? [1080, 1080] : [1920, 1080];
|
| 11 |
onProgress?.(0);
|
| 12 |
|
| 13 |
-
// Write meta.json
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
// Detect Chrome
|
| 18 |
-
const
|
| 19 |
process.env.PUPPETEER_EXECUTABLE_PATH,
|
| 20 |
process.env.CHROME_PATH,
|
| 21 |
'/usr/bin/chromium',
|
| 22 |
'/usr/bin/chromium-browser',
|
| 23 |
'/usr/bin/google-chrome',
|
| 24 |
-
].
|
| 25 |
|
| 26 |
-
|
| 27 |
-
for (const p of chromePaths) {
|
| 28 |
-
if (fs.existsSync(p)) { chromePath = p; break; }
|
| 29 |
-
}
|
| 30 |
-
console.log(`[renderer] Chrome path: ${chromePath || 'auto-detect'}`);
|
| 31 |
|
| 32 |
-
//
|
| 33 |
const args = ['hyperframes', 'render',
|
| 34 |
-
'
|
| 35 |
-
'-
|
| 36 |
-
'--height', String(h),
|
| 37 |
-
'--fps', '30',
|
| 38 |
];
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
return new Promise((resolve, reject) => {
|
| 42 |
const proc = execFile('npx', args, {
|
| 43 |
cwd: compDir,
|
| 44 |
maxBuffer: 500 * 1024 * 1024,
|
| 45 |
-
env
|
| 46 |
-
...process.env,
|
| 47 |
-
PUPPETEER_EXECUTABLE_PATH: chromePath || '/usr/bin/chromium',
|
| 48 |
-
CHROME_PATH: chromePath || '/usr/bin/chromium',
|
| 49 |
-
},
|
| 50 |
});
|
| 51 |
|
| 52 |
let stderr = '';
|
|
@@ -62,10 +55,7 @@ export async function renderVideo(compDir, outputFile, config, onProgress) {
|
|
| 62 |
});
|
| 63 |
proc.on('close', (code) => {
|
| 64 |
if (code === 0) { onProgress?.(1); resolve(outputFile); }
|
| 65 |
-
else {
|
| 66 |
-
const errMsg = stderr.slice(-500) || `exit code ${code}`;
|
| 67 |
-
reject(new Error(`HyperFrames render failed:\n${errMsg}`));
|
| 68 |
-
}
|
| 69 |
});
|
| 70 |
});
|
| 71 |
}
|
|
|
|
| 1 |
import { execFile } from 'child_process';
|
|
|
|
| 2 |
import path from 'path';
|
| 3 |
import fs from 'fs';
|
| 4 |
|
|
|
|
|
|
|
| 5 |
export async function renderVideo(compDir, outputFile, config, onProgress) {
|
| 6 |
const { format = '9:16', duration = 75 } = config;
|
| 7 |
const [w, h] = format === '9:16' ? [1080, 1920] : format === '1:1' ? [1080, 1080] : [1920, 1080];
|
| 8 |
onProgress?.(0);
|
| 9 |
|
| 10 |
+
// Write meta.json — HyperFrames reads width/height/fps/duration from here
|
| 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,
|
| 19 |
'/usr/bin/chromium',
|
| 20 |
'/usr/bin/chromium-browser',
|
| 21 |
'/usr/bin/google-chrome',
|
| 22 |
+
].find(p => p && fs.existsSync(p));
|
| 23 |
|
| 24 |
+
console.log(`[renderer] Chrome: ${chromePath || 'auto'} | ${w}x${h} | ${duration}s`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
// Correct CLI: npx hyperframes render ./index.html -o output.mp4
|
| 27 |
const args = ['hyperframes', 'render',
|
| 28 |
+
path.join(compDir, 'index.html'),
|
| 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('npx', args, {
|
| 40 |
cwd: compDir,
|
| 41 |
maxBuffer: 500 * 1024 * 1024,
|
| 42 |
+
env,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
});
|
| 44 |
|
| 45 |
let stderr = '';
|
|
|
|
| 55 |
});
|
| 56 |
proc.on('close', (code) => {
|
| 57 |
if (code === 0) { onProgress?.(1); resolve(outputFile); }
|
| 58 |
+
else reject(new Error(`HyperFrames render failed:\n${stderr.slice(-800)}`));
|
|
|
|
|
|
|
|
|
|
| 59 |
});
|
| 60 |
});
|
| 61 |
}
|