// Rendu image par image de video-pub.html → MP4 (voix off + musique). // Usage : node render.js [audio.wav, par défaut mix.wav] process.chdir(__dirname); const { chromium } = require('playwright-core'); const ffmpeg = require('ffmpeg-static'); const { spawn } = require('child_process'); const FPS = +process.argv[2] || 120; const OUT = require('path').resolve(process.argv[3] || `MonEspacePro-pub-${FPS}fps.mp4`); const SRC = require('url').pathToFileURL(__dirname + '/video-pub.html').href + '?t=0'; (async () => { const browser = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe', headless: true }); const page = await browser.newPage({ viewport: { width: 1080, height: 1920 }, deviceScaleFactor: 1 }); await page.goto(SRC); await page.waitForFunction(() => typeof seek === 'function' && typeof A !== 'undefined' && A.length > 100 && document.fonts.check('800 100px Figtree')); await page.addStyleTag({ content: '#replay{display:none!important}' }); const ff = spawn(ffmpeg, ['-y', '-hide_banner', '-loglevel', 'error', '-f', 'image2pipe', '-framerate', String(FPS), '-c:v', 'mjpeg', '-i', '-', '-i', process.argv[4] || 'mix.wav', '-c:v', 'libx264', '-preset', 'slow', '-crf', '17', '-pix_fmt', 'yuv420p', '-profile:v', 'high', '-r', String(FPS), '-c:a', 'aac', '-b:a', '192k', '-ar', '48000', '-shortest', '-movflags', '+faststart', OUT], { stdio: ['pipe', 'inherit', 'inherit'] }); const total = FPS * 30; const t0 = Date.now(); for (let i = 0; i < total; i++) { await page.evaluate(t => { seek(t); return new Promise(r => requestAnimationFrame(() => r())); }, i / FPS); const buf = await page.screenshot({ type: 'jpeg', quality: 95, clip: { x: 0, y: 0, width: 1080, height: 1920 } }); if (!ff.stdin.write(buf)) await new Promise(r => ff.stdin.once('drain', r)); if (i % (FPS * 2) === 0) console.log(`${(i / FPS).toFixed(0)} s / 30 — ${((Date.now() - t0) / 1000).toFixed(0)} s écoulées`); } ff.stdin.end(); await new Promise(r => ff.on('close', r)); await browser.close(); console.log('Terminé :', OUT); })();