Update server.js
Browse files
server.js
CHANGED
|
@@ -7,7 +7,6 @@ import { tmpdir } from 'os';
|
|
| 7 |
import { join, dirname } from 'path';
|
| 8 |
import { randomUUID } from 'crypto';
|
| 9 |
import { fileURLToPath } from 'url';
|
| 10 |
-
import { createClient } from '@supabase/supabase-js';
|
| 11 |
|
| 12 |
const __filename = fileURLToPath(import.meta.url);
|
| 13 |
const __dirname = dirname(__filename);
|
|
@@ -32,7 +31,7 @@ app.get('/', (req, res) => {
|
|
| 32 |
});
|
| 33 |
});
|
| 34 |
|
| 35 |
-
// Get bundle with caching
|
| 36 |
async function getCachedBundle() {
|
| 37 |
const now = Date.now();
|
| 38 |
|
|
@@ -43,25 +42,21 @@ async function getCachedBundle() {
|
|
| 43 |
|
| 44 |
console.log('[Performance] Creating new bundle');
|
| 45 |
|
| 46 |
-
// FIX: Custom webpack configuration to avoid bundle.js conflicts
|
| 47 |
cachedBundle = await bundle({
|
| 48 |
entryPoint: join(__dirname, 'remotion', 'index.tsx'),
|
| 49 |
webpackOverride: (config) => {
|
| 50 |
-
// Fix: Configure output to avoid conflicts
|
| 51 |
config.output = {
|
| 52 |
...config.output,
|
| 53 |
filename: '[name].js',
|
| 54 |
chunkFilename: '[name].chunk.js',
|
| 55 |
};
|
| 56 |
|
| 57 |
-
// Fix: Disable split chunks to avoid multiple chunks
|
| 58 |
config.optimization = {
|
| 59 |
...config.optimization,
|
| 60 |
splitChunks: false,
|
| 61 |
runtimeChunk: false,
|
| 62 |
};
|
| 63 |
|
| 64 |
-
// Performance optimizations
|
| 65 |
config.mode = 'production';
|
| 66 |
config.devtool = false;
|
| 67 |
|
|
@@ -79,7 +74,7 @@ function isGpuAvailable() {
|
|
| 79 |
process.env.CUDA_VISIBLE_DEVICES !== undefined;
|
| 80 |
}
|
| 81 |
|
| 82 |
-
// Get optimized chromium options
|
| 83 |
function getChromiumOptions() {
|
| 84 |
const baseOptions = {
|
| 85 |
executablePath: process.env.CHROME_BIN || '/usr/bin/google-chrome-stable',
|
|
@@ -88,69 +83,27 @@ function getChromiumOptions() {
|
|
| 88 |
args: ['--no-sandbox', '--disable-dev-shm-usage']
|
| 89 |
};
|
| 90 |
|
| 91 |
-
|
| 92 |
-
// GPU-accelerated options for L4
|
| 93 |
-
console.log('[GPU] GPU acceleration enabled');
|
| 94 |
-
return {
|
| 95 |
-
...baseOptions,
|
| 96 |
-
gl: 'angle',
|
| 97 |
-
args: [
|
| 98 |
-
'--use-gl=angle',
|
| 99 |
-
'--use-angle=gl-egl',
|
| 100 |
-
'--no-sandbox',
|
| 101 |
-
'--disable-dev-shm-usage',
|
| 102 |
-
'--enable-gpu-rasterization',
|
| 103 |
-
'--enable-oop-rasterization',
|
| 104 |
-
'--max-active-webgl-contexts=32',
|
| 105 |
-
'--disable-frame-rate-limit',
|
| 106 |
-
]
|
| 107 |
-
};
|
| 108 |
-
} else {
|
| 109 |
-
// CPU-only options
|
| 110 |
-
console.log('[GPU] GPU not available, using CPU rendering');
|
| 111 |
-
return baseOptions;
|
| 112 |
-
}
|
| 113 |
}
|
| 114 |
|
| 115 |
-
// Get FFmpeg override
|
| 116 |
function getFFmpegOverride() {
|
| 117 |
return ({ args }) => {
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
'-cq', '23',
|
| 126 |
-
'-movflags', '+faststart',
|
| 127 |
-
];
|
| 128 |
-
} else {
|
| 129 |
-
console.log('[GPU] Using software encoding (libx264)');
|
| 130 |
-
return [
|
| 131 |
-
...args,
|
| 132 |
-
'-c:v', 'libx264',
|
| 133 |
-
'-preset', 'fast',
|
| 134 |
-
'-crf', '23',
|
| 135 |
-
'-movflags', '+faststart',
|
| 136 |
-
];
|
| 137 |
-
}
|
| 138 |
};
|
| 139 |
}
|
| 140 |
|
| 141 |
-
// Calculate optimal concurrency
|
| 142 |
-
function getOptimalConcurrency() {
|
| 143 |
-
// Dynamically import os module
|
| 144 |
const os = await import('os');
|
| 145 |
const cpuCount = os.cpus().length;
|
| 146 |
-
|
| 147 |
-
if (isGpuAvailable()) {
|
| 148 |
-
// With GPU, we can handle more concurrency
|
| 149 |
-
return Math.min(cpuCount * 2, 12);
|
| 150 |
-
} else {
|
| 151 |
-
// CPU-only, be conservative
|
| 152 |
-
return Math.min(cpuCount, 8);
|
| 153 |
-
}
|
| 154 |
}
|
| 155 |
|
| 156 |
// Render endpoint
|
|
@@ -170,6 +123,7 @@ app.post('/render', async (req, res) => {
|
|
| 170 |
return res.status(500).json({ error: 'Renderer configuration error' });
|
| 171 |
}
|
| 172 |
|
|
|
|
| 173 |
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY);
|
| 174 |
|
| 175 |
// 1. Respond immediately
|
|
@@ -316,17 +270,19 @@ app.get('/status', async (req, res) => {
|
|
| 316 |
});
|
| 317 |
});
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
console.log(`⚡ GPU Available: ${isGpuAvailable() ? 'Yes' : 'No'}`);
|
| 322 |
-
|
| 323 |
-
// Dynamically import os module
|
| 324 |
const os = await import('os');
|
| 325 |
-
console.log(`💾 Memory: ${Math.round(os.totalmem() / (1024 * 1024 * 1024))}GB`);
|
| 326 |
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import { join, dirname } from 'path';
|
| 8 |
import { randomUUID } from 'crypto';
|
| 9 |
import { fileURLToPath } from 'url';
|
|
|
|
| 10 |
|
| 11 |
const __filename = fileURLToPath(import.meta.url);
|
| 12 |
const __dirname = dirname(__filename);
|
|
|
|
| 31 |
});
|
| 32 |
});
|
| 33 |
|
| 34 |
+
// Get bundle with caching
|
| 35 |
async function getCachedBundle() {
|
| 36 |
const now = Date.now();
|
| 37 |
|
|
|
|
| 42 |
|
| 43 |
console.log('[Performance] Creating new bundle');
|
| 44 |
|
|
|
|
| 45 |
cachedBundle = await bundle({
|
| 46 |
entryPoint: join(__dirname, 'remotion', 'index.tsx'),
|
| 47 |
webpackOverride: (config) => {
|
|
|
|
| 48 |
config.output = {
|
| 49 |
...config.output,
|
| 50 |
filename: '[name].js',
|
| 51 |
chunkFilename: '[name].chunk.js',
|
| 52 |
};
|
| 53 |
|
|
|
|
| 54 |
config.optimization = {
|
| 55 |
...config.optimization,
|
| 56 |
splitChunks: false,
|
| 57 |
runtimeChunk: false,
|
| 58 |
};
|
| 59 |
|
|
|
|
| 60 |
config.mode = 'production';
|
| 61 |
config.devtool = false;
|
| 62 |
|
|
|
|
| 74 |
process.env.CUDA_VISIBLE_DEVICES !== undefined;
|
| 75 |
}
|
| 76 |
|
| 77 |
+
// Get optimized chromium options
|
| 78 |
function getChromiumOptions() {
|
| 79 |
const baseOptions = {
|
| 80 |
executablePath: process.env.CHROME_BIN || '/usr/bin/google-chrome-stable',
|
|
|
|
| 83 |
args: ['--no-sandbox', '--disable-dev-shm-usage']
|
| 84 |
};
|
| 85 |
|
| 86 |
+
return baseOptions;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
+
// Get FFmpeg override
|
| 90 |
function getFFmpegOverride() {
|
| 91 |
return ({ args }) => {
|
| 92 |
+
return [
|
| 93 |
+
...args,
|
| 94 |
+
'-c:v', 'libx264',
|
| 95 |
+
'-preset', 'fast',
|
| 96 |
+
'-crf', '23',
|
| 97 |
+
'-movflags', '+faststart',
|
| 98 |
+
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
};
|
| 100 |
}
|
| 101 |
|
| 102 |
+
// Calculate optimal concurrency
|
| 103 |
+
async function getOptimalConcurrency() {
|
|
|
|
| 104 |
const os = await import('os');
|
| 105 |
const cpuCount = os.cpus().length;
|
| 106 |
+
return Math.min(cpuCount, 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
|
| 109 |
// Render endpoint
|
|
|
|
| 123 |
return res.status(500).json({ error: 'Renderer configuration error' });
|
| 124 |
}
|
| 125 |
|
| 126 |
+
const { createClient } = await import('@supabase/supabase-js');
|
| 127 |
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY);
|
| 128 |
|
| 129 |
// 1. Respond immediately
|
|
|
|
| 270 |
});
|
| 271 |
});
|
| 272 |
|
| 273 |
+
// Start server
|
| 274 |
+
(async () => {
|
|
|
|
|
|
|
|
|
|
| 275 |
const os = await import('os');
|
|
|
|
| 276 |
|
| 277 |
+
app.listen(PORT, () => {
|
| 278 |
+
console.log(`🎬 FacelessFlowAI Renderer running on port ${PORT}`);
|
| 279 |
+
console.log(`⚡ GPU Available: ${isGpuAvailable() ? 'Yes' : 'No'}`);
|
| 280 |
+
console.log(`💾 Memory: ${Math.round(os.totalmem() / (1024 * 1024 * 1024))}GB`);
|
| 281 |
+
|
| 282 |
+
// Environment check
|
| 283 |
+
console.log('--- Environment ---');
|
| 284 |
+
console.log('CHROME_BIN:', process.env.CHROME_BIN || 'default');
|
| 285 |
+
console.log('COMPUTE_TYPE:', process.env.COMPUTE_TYPE || 'cpu');
|
| 286 |
+
console.log('------------------');
|
| 287 |
+
});
|
| 288 |
+
})();
|