Stylique commited on
Commit
6d29b7e
·
verified ·
1 Parent(s): ad4e5f8

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +215 -187
server.js CHANGED
@@ -26,8 +26,8 @@ const BUNDLE_CACHE_TTL = 5 * 60 * 1000;
26
  app.get('/', (req, res) => {
27
  res.json({
28
  status: 'ok',
29
- service: 'FacelessFlowAI Video Renderer (L4 GPU Optimized)',
30
- note: 'NVENC hardware encoding enabled'
31
  });
32
  });
33
 
@@ -74,51 +74,164 @@ async function getCachedBundle() {
74
  }
75
  }
76
 
77
- // Check if NVENC is available
78
- async function checkNvenc() {
79
  try {
80
  const { execSync } = await import('child_process');
81
- const result = execSync('ffmpeg -encoders 2>/dev/null | grep -i nvenc', { encoding: 'utf8' });
82
- console.log('[GPU] NVENC detected');
 
 
83
  return true;
84
  } catch (error) {
85
- console.log('[GPU] NVENC not available');
86
  return false;
87
  }
88
  }
89
 
90
- // Get optimal concurrency (respects Remotion limits)
91
- async function getOptimalConcurrency() {
 
 
 
 
92
  try {
93
- const os = await import('os');
94
- const cpuCount = os.cpus().length;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
- // Remotion suggests max concurrency = number of cores
97
- // For L4 with 8 vCPUs, use 6 (as suggested by Remotion)
98
- const optimal = Math.min(cpuCount, 6);
99
- console.log(`[CPU] Detected ${cpuCount} cores, using concurrency: ${optimal}`);
100
- return optimal;
101
- } catch (error) {
102
- console.log('[CPU] Using default concurrency: 4');
103
- return 4;
104
- }
105
- }
106
-
107
- // Pre-check Chrome to avoid download during render
108
- async function ensureChrome() {
109
- console.log('[Chrome] Checking Chrome...');
110
- try {
111
- const { execSync } = await import('child_process');
112
- execSync('/usr/bin/google-chrome-stable --version', { stdio: 'pipe' });
113
- console.log('[Chrome] Chrome is ready');
114
- return true;
115
- } catch (error) {
116
- console.log('[Chrome] Will use headless shell');
117
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  }
119
  }
120
 
121
- // Render endpoint - OPTIMIZED FOR L4
122
  app.post('/render', async (req, res) => {
123
  const { projectId, scenes, settings } = req.body;
124
 
@@ -142,7 +255,7 @@ app.post('/render', async (req, res) => {
142
  res.json({
143
  success: true,
144
  message: 'Rendering started in background',
145
- hardware: 'L4 GPU with NVENC'
146
  });
147
 
148
  // 2. Start Background Process
@@ -152,10 +265,6 @@ app.post('/render', async (req, res) => {
152
  try {
153
  console.log(`[Render] Starting render for project ${projectId}`);
154
 
155
- // Pre-checks
156
- const nvencAvailable = await checkNvenc();
157
- await ensureChrome();
158
-
159
  const bundleLocation = await getCachedBundle();
160
  console.log('[Bundle] Bundle ready');
161
 
@@ -165,104 +274,32 @@ app.post('/render', async (req, res) => {
165
  inputProps: { scenes, settings },
166
  chromiumOptions: {
167
  executablePath: '/usr/bin/google-chrome-stable',
168
- args: [
169
- '--no-sandbox',
170
- '--disable-dev-shm-usage',
171
- // GPU acceleration
172
- '--use-gl=angle',
173
- '--use-angle=gl-egl',
174
- '--enable-gpu-rasterization',
175
- '--enable-oop-rasterization',
176
- ],
177
- onBrowserDownload: (progress) => {
178
- const downloadedMB = (progress.downloadedBytes / 1024 / 1024).toFixed(1);
179
- const totalMB = (progress.totalSize / 1024 / 1024).toFixed(1);
180
- console.log(`[Chrome] Downloading: ${downloadedMB}Mb/${totalMB}Mb`);
181
- }
182
  },
183
  });
184
 
185
  console.log(`[Composition] Loaded: ${composition.durationInFrames} frames at ${composition.fps}fps`);
186
- console.log(`[GPU] NVENC available: ${nvencAvailable}`);
187
 
188
  const tempDir = join(tmpdir(), `remotion-${randomUUID()}`);
189
  await mkdir(tempDir, { recursive: true });
190
  const outputPath = join(tempDir, 'output.mp4');
191
 
192
- // Get optimal concurrency (respects system limits)
193
- const concurrency = await getOptimalConcurrency();
194
 
195
- console.log('[Render] Starting video rendering...');
 
 
196
 
197
- await renderMedia({
198
- composition,
199
- serveUrl: bundleLocation,
200
- codec: 'h264',
201
- pixelFormat: 'yuv420p',
202
- outputLocation: outputPath,
203
- imageFormat: 'jpeg',
204
- jpegQuality: 85,
205
- inputProps: { scenes, settings },
206
- chromiumOptions: {
207
- executablePath: '/usr/bin/google-chrome-stable',
208
- args: [
209
- '--no-sandbox',
210
- '--disable-dev-shm-usage',
211
- '--use-gl=angle',
212
- '--use-angle=gl-egl',
213
- ]
214
- },
215
- concurrency: concurrency,
216
- disallowParallelEncoding: false,
217
- onProgress: ({ progress, renderedFrames }) => {
218
- const percent = Math.round(progress * 100);
219
- const elapsed = (Date.now() - startTime) / 1000;
220
- const fps = elapsed > 0 ? Math.round(renderedFrames / elapsed) : 0;
221
- console.log(`[Progress] ${percent}% | FPS: ${fps} | Frames: ${renderedFrames}`);
222
- },
223
- ffmpegOverride: ({ args }) => {
224
- if (nvencAvailable) {
225
- console.log('[L4 GPU] Using NVENC hardware encoding');
226
- // OPTIMIZED NVENC SETTINGS FOR L4
227
- return [
228
- ...args,
229
- '-c:v', 'h264_nvenc',
230
- '-preset', 'p1', // Fastest quality preset
231
- '-tune', 'll', // Low latency
232
- '-cq', '20', // Quality level (20 = good quality)
233
- '-movflags', '+faststart',
234
- '-profile:v', 'high',
235
- '-level', '5.1',
236
- '-bf', '2', // B-frames
237
- '-gpu', '0', // Use GPU 0
238
- '-surfaces', '24', // Surfaces for L4
239
- '-c:a', 'aac',
240
- '-b:a', '192k',
241
- '-ac', '2',
242
- ];
243
- } else {
244
- console.log('[CPU] Using software encoding');
245
- return [
246
- ...args,
247
- '-c:v', 'libx264',
248
- '-preset', 'fast',
249
- '-crf', '23',
250
- '-movflags', '+faststart',
251
- '-c:a', 'aac',
252
- '-b:a', '192k',
253
- ];
254
- }
255
- },
256
- audioBitrate: '192k',
257
- videoBitrate: '10M',
258
- muted: false,
259
- });
260
 
261
- const renderTime = Date.now() - startTime;
262
- console.log(`[Render] Completed in ${Math.round(renderTime / 1000)}s`);
263
-
264
- const fps = Math.round(composition.durationInFrames / (renderTime / 1000));
265
- console.log(`[Performance] Average FPS: ${fps}`);
266
 
267
  console.log(`[Upload] Reading video file...`);
268
  const videoBuffer = await readFile(outputPath);
@@ -297,10 +334,9 @@ app.post('/render', async (req, res) => {
297
  .update({
298
  status: 'done',
299
  video_url: publicUrl,
300
- render_time: renderTime,
301
  rendered_at: new Date().toISOString(),
302
- render_fps: fps,
303
- gpu_used: nvencAvailable ? 'L4 NVENC' : 'CPU'
304
  })
305
  .eq('id', projectId);
306
 
@@ -314,10 +350,6 @@ app.post('/render', async (req, res) => {
314
  } catch (error) {
315
  console.error(`[Render] Error for ${projectId}:`, error.message);
316
 
317
- // Try fallback with reduced concurrency
318
- console.log('[Fallback] Trying with reduced concurrency...');
319
- // (You could implement a retry logic here if needed)
320
-
321
  // Update project status to 'error'
322
  try {
323
  await supabase
@@ -337,72 +369,77 @@ app.post('/render', async (req, res) => {
337
  // Status endpoint
338
  app.get('/status', async (req, res) => {
339
  const os = await import('os');
340
- const { execSync } = await import('child_process');
341
-
342
- let gpuInfo = 'Not detected';
343
- let nvencInfo = 'Not detected';
344
 
 
 
345
  try {
346
- // Check GPU
347
- try {
348
- const gpu = execSync('lspci 2>/dev/null | grep -i "vga\\|3d\\|display" || echo "No GPU"', { encoding: 'utf8' });
349
- gpuInfo = gpu.trim();
350
- } catch {
351
- gpuInfo = 'GPU check failed';
352
- }
353
-
354
- // Check NVENC
355
- try {
356
- execSync('ffmpeg -encoders 2>/dev/null | grep -i nvenc', { stdio: 'pipe' });
357
- nvencInfo = 'Available';
358
- } catch {
359
- nvencInfo = 'Not available';
360
- }
361
- } catch (error) {
362
- gpuInfo = 'Check error';
363
  }
364
 
365
  res.json({
366
  status: 'running',
367
- hardware: 'L4 GPU',
368
  cpu_cores: os.cpus().length,
369
  total_memory: Math.round(os.totalmem() / (1024 * 1024 * 1024)) + 'GB',
370
  free_memory: Math.round(os.freemem() / (1024 * 1024 * 1024)) + 'GB',
371
- gpu: gpuInfo,
372
- nvenc: nvencInfo,
373
  bundle_cached: cachedBundle !== null,
374
  uptime: Math.round(process.uptime()) + 's',
375
- concurrency_limit: 'Max 8 (6 recommended)'
376
  });
377
  });
378
 
379
- // Quick NVENC test
380
- app.get('/test-encode', async (req, res) => {
381
  try {
382
  const { execSync } = await import('child_process');
 
383
 
384
- // Create a test video with NVENC
385
- const testCommand = 'ffmpeg -f lavfi -i testsrc=duration=2:size=640x360:rate=30 -c:v h264_nvenc -preset p1 -tune ll -f mp4 -y /tmp/test_nvenc.mp4 2>&1';
386
 
387
- console.log('[Test] Running:', testCommand);
388
- const output = execSync(testCommand, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 10 });
 
 
 
 
 
389
 
390
- // Check if file was created
391
- const fs = await import('fs');
392
- const stats = fs.statSync('/tmp/test_nvenc.mp4');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
 
394
  res.json({
395
- success: true,
396
- file_size: stats.size + ' bytes',
397
- test: 'NVENC encoding works',
398
- output_preview: output.substring(0, 500) + '...'
399
  });
 
400
  } catch (error) {
401
- res.json({
402
- success: false,
403
- error: error.message,
404
- test: 'NVENC encoding failed'
405
- });
406
  }
407
  });
408
 
@@ -414,19 +451,10 @@ app.listen(PORT, async () => {
414
  console.log(`💾 Memory: ${Math.round(os.totalmem() / (1024 * 1024 * 1024))}GB`);
415
  console.log(`⚡ CPU Cores: ${os.cpus().length}`);
416
 
417
- // Check NVENC
418
- try {
419
- const { execSync } = await import('child_process');
420
- const nvenc = execSync('ffmpeg -encoders 2>/dev/null | grep -i nvenc | head -1', { encoding: 'utf8' });
421
- console.log(`⚡ NVENC: ${nvenc.trim()}`);
422
- } catch {
423
- console.log('⚡ NVENC: Not detected');
424
- }
425
-
426
  console.log('--- Configuration ---');
427
- console.log('CONCURRENCY: Dynamic (max 6)');
428
- console.log('ENCODING: NVENC hardware when available');
429
- console.log('CHROME: GPU accelerated');
430
  console.log('---------------------');
431
 
432
  // Auto-warmup
 
26
  app.get('/', (req, res) => {
27
  res.json({
28
  status: 'ok',
29
+ service: 'FacelessFlowAI Video Renderer',
30
+ note: 'Auto-detect best encoding method'
31
  });
32
  });
33
 
 
74
  }
75
  }
76
 
77
+ // Test NVENC with simple command
78
+ async function testNvencCompatibility() {
79
  try {
80
  const { execSync } = await import('child_process');
81
+ // Simple test command
82
+ const testCommand = 'ffmpeg -f lavfi -i testsrc=duration=1:size=128x72:rate=1 -c:v h264_nvenc -f null - 2>&1';
83
+ execSync(testCommand, { stdio: 'pipe', timeout: 5000 });
84
+ console.log('[NVENC Test] Basic encoding works');
85
  return true;
86
  } catch (error) {
87
+ console.log('[NVENC Test] Basic encoding failed:', error.message);
88
  return false;
89
  }
90
  }
91
 
92
+ // Render with fallback mechanism
93
+ async function renderWithFallback(composition, bundleLocation, scenes, settings, outputPath) {
94
+ const startTime = Date.now();
95
+
96
+ // Try NVENC first
97
+ console.log('[Render] Attempt 1: Trying NVENC hardware encoding...');
98
  try {
99
+ await renderMedia({
100
+ composition,
101
+ serveUrl: bundleLocation,
102
+ codec: 'h264',
103
+ pixelFormat: 'yuv420p',
104
+ outputLocation: outputPath,
105
+ imageFormat: 'jpeg',
106
+ jpegQuality: 80,
107
+ inputProps: { scenes, settings },
108
+ chromiumOptions: {
109
+ executablePath: '/usr/bin/google-chrome-stable',
110
+ args: ['--no-sandbox', '--disable-dev-shm-usage']
111
+ },
112
+ concurrency: 6,
113
+ disallowParallelEncoding: false,
114
+ onProgress: ({ progress, renderedFrames }) => {
115
+ const percent = Math.round(progress * 100);
116
+ const elapsed = (Date.now() - startTime) / 1000;
117
+ const fps = elapsed > 0 ? Math.round(renderedFrames / elapsed) : 0;
118
+ console.log(`[NVENC Progress] ${percent}% | FPS: ${fps}`);
119
+ },
120
+ ffmpegOverride: ({ args }) => {
121
+ console.log('[NVENC] Using simplified NVENC settings');
122
+ // SIMPLIFIED NVENC SETTINGS - most compatible
123
+ return [
124
+ ...args,
125
+ '-c:v', 'h264_nvenc',
126
+ '-preset', 'default', // Most compatible preset
127
+ '-cq', '23', // Standard quality
128
+ '-movflags', '+faststart',
129
+ '-c:a', 'aac',
130
+ '-b:a', '192k',
131
+ ];
132
+ },
133
+ audioBitrate: '192k',
134
+ videoBitrate: '8M',
135
+ });
136
 
137
+ console.log(`[NVENC Success] Completed in ${Math.round((Date.now() - startTime) / 1000)}s`);
138
+ return 'nvenc';
139
+
140
+ } catch (nvencError) {
141
+ console.log(`[NVENC Failed] ${nvencError.message}`);
142
+
143
+ // Try even simpler NVENC
144
+ console.log('[Render] Attempt 2: Trying minimal NVENC settings...');
145
+ try {
146
+ await renderMedia({
147
+ composition,
148
+ serveUrl: bundleLocation,
149
+ codec: 'h264',
150
+ pixelFormat: 'yuv420p',
151
+ outputLocation: outputPath,
152
+ imageFormat: 'jpeg',
153
+ jpegQuality: 80,
154
+ inputProps: { scenes, settings },
155
+ chromiumOptions: {
156
+ executablePath: '/usr/bin/google-chrome-stable',
157
+ args: ['--no-sandbox', '--disable-dev-shm-usage']
158
+ },
159
+ concurrency: 4,
160
+ disallowParallelEncoding: true, // More stable
161
+ onProgress: ({ progress }) => {
162
+ console.log(`[NVENC2 Progress] ${Math.round(progress * 100)}%`);
163
+ },
164
+ ffmpegOverride: ({ args }) => {
165
+ console.log('[NVENC2] Using minimal NVENC settings');
166
+ // MINIMAL NVENC SETTINGS
167
+ return [
168
+ ...args,
169
+ '-c:v', 'h264_nvenc',
170
+ '-preset', 'p1',
171
+ '-movflags', '+faststart',
172
+ '-c:a', 'aac',
173
+ '-b:a', '192k',
174
+ ];
175
+ },
176
+ audioBitrate: '192k',
177
+ videoBitrate: '4M',
178
+ });
179
+
180
+ console.log(`[NVENC2 Success] Completed in ${Math.round((Date.now() - startTime) / 1000)}s`);
181
+ return 'nvenc_minimal';
182
+
183
+ } catch (nvenc2Error) {
184
+ console.log(`[NVENC2 Failed] ${nvenc2Error.message}`);
185
+
186
+ // Fallback to software encoding
187
+ console.log('[Render] Attempt 3: Falling back to software encoding...');
188
+ try {
189
+ await renderMedia({
190
+ composition,
191
+ serveUrl: bundleLocation,
192
+ codec: 'h264',
193
+ pixelFormat: 'yuv420p',
194
+ outputLocation: outputPath,
195
+ imageFormat: 'jpeg',
196
+ jpegQuality: 80,
197
+ inputProps: { scenes, settings },
198
+ chromiumOptions: {
199
+ executablePath: '/usr/bin/google-chrome-stable',
200
+ args: ['--no-sandbox', '--disable-dev-shm-usage']
201
+ },
202
+ concurrency: 4,
203
+ disallowParallelEncoding: true,
204
+ onProgress: ({ progress }) => {
205
+ console.log(`[CPU Progress] ${Math.round(progress * 100)}%`);
206
+ },
207
+ ffmpegOverride: ({ args }) => {
208
+ console.log('[CPU] Using software encoding');
209
+ return [
210
+ ...args,
211
+ '-c:v', 'libx264',
212
+ '-preset', 'fast',
213
+ '-crf', '23',
214
+ '-movflags', '+faststart',
215
+ '-c:a', 'aac',
216
+ '-b:a', '192k',
217
+ ];
218
+ },
219
+ audioBitrate: '192k',
220
+ videoBitrate: '4M',
221
+ });
222
+
223
+ console.log(`[CPU Success] Completed in ${Math.round((Date.now() - startTime) / 1000)}s`);
224
+ return 'cpu';
225
+
226
+ } catch (cpuError) {
227
+ console.log(`[CPU Failed] ${cpuError.message}`);
228
+ throw new Error(`All encoding methods failed. Last error: ${cpuError.message}`);
229
+ }
230
+ }
231
  }
232
  }
233
 
234
+ // Render endpoint with intelligent fallback
235
  app.post('/render', async (req, res) => {
236
  const { projectId, scenes, settings } = req.body;
237
 
 
255
  res.json({
256
  success: true,
257
  message: 'Rendering started in background',
258
+ note: 'Using intelligent encoding detection'
259
  });
260
 
261
  // 2. Start Background Process
 
265
  try {
266
  console.log(`[Render] Starting render for project ${projectId}`);
267
 
 
 
 
 
268
  const bundleLocation = await getCachedBundle();
269
  console.log('[Bundle] Bundle ready');
270
 
 
274
  inputProps: { scenes, settings },
275
  chromiumOptions: {
276
  executablePath: '/usr/bin/google-chrome-stable',
277
+ args: ['--no-sandbox', '--disable-dev-shm-usage']
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  },
279
  });
280
 
281
  console.log(`[Composition] Loaded: ${composition.durationInFrames} frames at ${composition.fps}fps`);
 
282
 
283
  const tempDir = join(tmpdir(), `remotion-${randomUUID()}`);
284
  await mkdir(tempDir, { recursive: true });
285
  const outputPath = join(tempDir, 'output.mp4');
286
 
287
+ console.log('[Render] Starting intelligent rendering...');
 
288
 
289
+ // Test NVENC compatibility first
290
+ const nvencCompatible = await testNvencCompatibility();
291
+ console.log(`[Compatibility] NVENC compatible: ${nvencCompatible}`);
292
 
293
+ const encodingMethod = await renderWithFallback(
294
+ composition,
295
+ bundleLocation,
296
+ scenes,
297
+ settings,
298
+ outputPath
299
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
+ const totalTime = Date.now() - startTime;
302
+ console.log(`[Render] Completed in ${Math.round(totalTime / 1000)}s using ${encodingMethod}`);
 
 
 
303
 
304
  console.log(`[Upload] Reading video file...`);
305
  const videoBuffer = await readFile(outputPath);
 
334
  .update({
335
  status: 'done',
336
  video_url: publicUrl,
337
+ render_time: totalTime,
338
  rendered_at: new Date().toISOString(),
339
+ encoding_method: encodingMethod
 
340
  })
341
  .eq('id', projectId);
342
 
 
350
  } catch (error) {
351
  console.error(`[Render] Error for ${projectId}:`, error.message);
352
 
 
 
 
 
353
  // Update project status to 'error'
354
  try {
355
  await supabase
 
369
  // Status endpoint
370
  app.get('/status', async (req, res) => {
371
  const os = await import('os');
 
 
 
 
372
 
373
+ // Test NVENC compatibility
374
+ let nvencStatus = 'Unknown';
375
  try {
376
+ const { execSync } = await import('child_process');
377
+ execSync('ffmpeg -encoders 2>/dev/null | grep -i nvenc', { stdio: 'pipe' });
378
+ nvencStatus = 'Detected (needs test)';
379
+ } catch {
380
+ nvencStatus = 'Not detected';
 
 
 
 
 
 
 
 
 
 
 
 
381
  }
382
 
383
  res.json({
384
  status: 'running',
 
385
  cpu_cores: os.cpus().length,
386
  total_memory: Math.round(os.totalmem() / (1024 * 1024 * 1024)) + 'GB',
387
  free_memory: Math.round(os.freemem() / (1024 * 1024 * 1024)) + 'GB',
388
+ nvenc: nvencStatus,
 
389
  bundle_cached: cachedBundle !== null,
390
  uptime: Math.round(process.uptime()) + 's',
391
+ strategy: 'Intelligent fallback (NVENC → CPU)'
392
  });
393
  });
394
 
395
+ // Enhanced NVENC test
396
+ app.get('/test-nvenc-full', async (req, res) => {
397
  try {
398
  const { execSync } = await import('child_process');
399
+ const fs = await import('fs');
400
 
401
+ const tests = [];
 
402
 
403
+ // Test 1: Check if NVENC encoder exists
404
+ try {
405
+ const encoders = execSync('ffmpeg -encoders 2>/dev/null | grep -i nvenc', { encoding: 'utf8' });
406
+ tests.push({ test: 'NVENC encoders exist', result: 'PASS', details: encoders.trim() });
407
+ } catch {
408
+ tests.push({ test: 'NVENC encoders exist', result: 'FAIL', details: 'Not found' });
409
+ }
410
 
411
+ // Test 2: Try simple encoding
412
+ try {
413
+ execSync('ffmpeg -f lavfi -i testsrc=duration=0.1:size=64x36:rate=1 -c:v h264_nvenc -f null - 2>&1', { stdio: 'pipe' });
414
+ tests.push({ test: 'Simple NVENC encode', result: 'PASS', details: 'Works' });
415
+ } catch (error) {
416
+ tests.push({ test: 'Simple NVENC encode', result: 'FAIL', details: error.message.substring(0, 100) });
417
+ }
418
+
419
+ // Test 3: Try with CQ parameter
420
+ try {
421
+ execSync('ffmpeg -f lavfi -i testsrc=duration=0.1:size=64x36:rate=1 -c:v h264_nvenc -cq 23 -f null - 2>&1', { stdio: 'pipe' });
422
+ tests.push({ test: 'NVENC with CQ', result: 'PASS', details: 'Works' });
423
+ } catch (error) {
424
+ tests.push({ test: 'NVENC with CQ', result: 'FAIL', details: error.message.substring(0, 100) });
425
+ }
426
+
427
+ // Test 4: Try with preset
428
+ try {
429
+ execSync('ffmpeg -f lavfi -i testsrc=duration=0.1:size=64x36:rate=1 -c:v h264_nvenc -preset p1 -f null - 2>&1', { stdio: 'pipe' });
430
+ tests.push({ test: 'NVENC with preset', result: 'PASS', details: 'Works' });
431
+ } catch (error) {
432
+ tests.push({ test: 'NVENC with preset', result: 'FAIL', details: error.message.substring(0, 100) });
433
+ }
434
 
435
  res.json({
436
+ hardware: 'L4 GPU Tests',
437
+ tests: tests,
438
+ summary: `${tests.filter(t => t.result === 'PASS').length}/${tests.length} tests passed`
 
439
  });
440
+
441
  } catch (error) {
442
+ res.status(500).json({ error: error.message });
 
 
 
 
443
  }
444
  });
445
 
 
451
  console.log(`💾 Memory: ${Math.round(os.totalmem() / (1024 * 1024 * 1024))}GB`);
452
  console.log(`⚡ CPU Cores: ${os.cpus().length}`);
453
 
 
 
 
 
 
 
 
 
 
454
  console.log('--- Configuration ---');
455
+ console.log('STRATEGY: Intelligent fallback (NVENC → CPU)');
456
+ console.log('CONCURRENCY: Adaptive');
457
+ console.log('QUALITY: Adaptive');
458
  console.log('---------------------');
459
 
460
  // Auto-warmup