Update server.js
Browse files
server.js
CHANGED
|
@@ -97,37 +97,53 @@ app.post('/render', async (req, res) => {
|
|
| 97 |
|
| 98 |
console.log(`[Render] Processing Chunk ${chunkIndex + 1}/${Math.ceil(totalFrames / CHUNK_SIZE)} (Frames ${startFrame}-${endFrame})`);
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
chunkPaths.push(chunkPath);
|
| 133 |
|
|
|
|
| 97 |
|
| 98 |
console.log(`[Render] Processing Chunk ${chunkIndex + 1}/${Math.ceil(totalFrames / CHUNK_SIZE)} (Frames ${startFrame}-${endFrame})`);
|
| 99 |
|
| 100 |
+
let attempts = 0;
|
| 101 |
+
const maxRetries = 3;
|
| 102 |
+
let success = false;
|
| 103 |
+
|
| 104 |
+
while (attempts < maxRetries && !success) {
|
| 105 |
+
attempts++;
|
| 106 |
+
try {
|
| 107 |
+
// Explicitly launching a fresh render for each chunk clears memory
|
| 108 |
+
await renderMedia({
|
| 109 |
+
composition,
|
| 110 |
+
serveUrl: bundleLocation,
|
| 111 |
+
codec: 'h264',
|
| 112 |
+
pixelFormat: 'yuv420p',
|
| 113 |
+
outputLocation: chunkPath,
|
| 114 |
+
imageFormat: 'jpeg',
|
| 115 |
+
jpegQuality: 80,
|
| 116 |
+
inputProps: { scenes, settings },
|
| 117 |
+
frameRange: [startFrame, endFrame], // Only render this segment
|
| 118 |
+
chromiumOptions: {
|
| 119 |
+
executablePath: process.env.CHROME_BIN || '/usr/bin/google-chrome-stable',
|
| 120 |
+
enableMultiProcessRendering: true,
|
| 121 |
+
args: ['--no-sandbox', '--disable-dev-shm-usage', '--disable-software-rasterizer'],
|
| 122 |
+
dumpio: true, // Log Chrome output to debug crashes
|
| 123 |
+
},
|
| 124 |
+
concurrency: safeConcurrency,
|
| 125 |
+
disallowParallelEncoding: false,
|
| 126 |
+
onProgress: ({ progress }) => {
|
| 127 |
+
// Normalize progress relative to the whole video
|
| 128 |
+
// Chunk progress (0-1) * Fraction of Total + Start Fraction
|
| 129 |
+
const chunkProgress = progress;
|
| 130 |
+
const totalProgress = (i + (chunkProgress * (endFrame - startFrame))) / totalFrames;
|
| 131 |
+
const percent = Math.round(totalProgress * 100);
|
| 132 |
+
|
| 133 |
+
if (percent - lastLog >= 1 || percent === 100) {
|
| 134 |
+
console.log(`[Render] Total Progress: ${percent}% (Chunk ${chunkIndex}: ${Math.round(chunkProgress * 100)}%)`);
|
| 135 |
+
lastLog = percent;
|
| 136 |
+
}
|
| 137 |
+
},
|
| 138 |
+
});
|
| 139 |
+
success = true;
|
| 140 |
+
} catch (e) {
|
| 141 |
+
console.error(`[Render] Chunk ${chunkIndex} failed (Attempt ${attempts}/${maxRetries}):`, e);
|
| 142 |
+
if (attempts >= maxRetries) throw e;
|
| 143 |
+
console.log(`[Render] Retrying Chunk ${chunkIndex} in 3 seconds...`);
|
| 144 |
+
await new Promise(r => setTimeout(r, 3000));
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
|
| 148 |
chunkPaths.push(chunkPath);
|
| 149 |
|