Stylique commited on
Commit
d1ca43e
·
verified ·
1 Parent(s): d052d5e

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +47 -31
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
- // Explicitly launching a fresh render for each chunk clears memory
101
- await renderMedia({
102
- composition,
103
- serveUrl: bundleLocation,
104
- codec: 'h264',
105
- pixelFormat: 'yuv420p',
106
- outputLocation: chunkPath,
107
- imageFormat: 'jpeg',
108
- jpegQuality: 80,
109
- inputProps: { scenes, settings },
110
- frameRange: [startFrame, endFrame], // Only render this segment
111
- chromiumOptions: {
112
- executablePath: process.env.CHROME_BIN || '/usr/bin/google-chrome-stable',
113
- enableMultiProcessRendering: true,
114
- args: ['--no-sandbox', '--disable-dev-shm-usage', '--disable-software-rasterizer']
115
- },
116
- concurrency: safeConcurrency,
117
- disallowParallelEncoding: false,
118
- onProgress: ({ progress }) => {
119
- // Normalize progress relative to the whole video
120
- // Chunk progress (0-1) * Fraction of Total + Start Fraction
121
- const chunkProgress = progress;
122
- const totalProgress = (i + (chunkProgress * (endFrame - startFrame))) / totalFrames;
123
- const percent = Math.round(totalProgress * 100);
124
-
125
- if (percent - lastLog >= 1 || percent === 100) {
126
- console.log(`[Render] Total Progress: ${percent}% (Chunk ${chunkIndex}: ${Math.round(chunkProgress * 100)}%)`);
127
- lastLog = percent;
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