fix: optimize FFmpeg encoding to reduce memory usage
- Switch from VP9 to VP8 codec for WebM (less memory-intensive) - Add realtime encoding deadline and fast CPU preset - Add ultrafast preset for x264 encoding - Set explicit bitrates to control memory usage - Use libvorbis instead of libopus for better compatibility This fixes "memory access out of bounds" errors during video conversion in browser environments with limited WASM memory. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -120,12 +120,24 @@ function buildFFmpegArgs(
|
||||
// Format-specific settings
|
||||
switch (outputFormat) {
|
||||
case 'webm':
|
||||
if (!options.videoCodec) args.push('-c:v', 'libvpx-vp9');
|
||||
if (!options.audioCodec) args.push('-c:a', 'libopus');
|
||||
// Use VP8 by default (less memory-intensive than VP9)
|
||||
if (!options.videoCodec) args.push('-c:v', 'libvpx');
|
||||
if (!options.audioCodec) args.push('-c:a', 'libvorbis');
|
||||
// Optimize for faster encoding and lower memory usage
|
||||
args.push('-deadline', 'realtime');
|
||||
args.push('-cpu-used', '8');
|
||||
// Set quality/bitrate if not specified
|
||||
if (!options.videoBitrate) args.push('-b:v', '1M');
|
||||
if (!options.audioBitrate) args.push('-b:a', '128k');
|
||||
break;
|
||||
case 'mp4':
|
||||
if (!options.videoCodec) args.push('-c:v', 'libx264');
|
||||
if (!options.audioCodec) args.push('-c:a', 'aac');
|
||||
// Use faster preset for browser encoding
|
||||
args.push('-preset', 'ultrafast');
|
||||
args.push('-tune', 'zerolatency');
|
||||
if (!options.videoBitrate) args.push('-b:v', '1M');
|
||||
if (!options.audioBitrate) args.push('-b:a', '128k');
|
||||
break;
|
||||
case 'mp3':
|
||||
if (!options.audioCodec) args.push('-c:a', 'libmp3lame');
|
||||
|
||||
@@ -218,14 +218,14 @@ export const FORMAT_PRESETS: FormatPreset[] = [
|
||||
{
|
||||
id: 'web-video',
|
||||
name: 'Web Video',
|
||||
description: 'Optimize video for web playback',
|
||||
description: 'Optimize video for web playback (VP8 for better compatibility)',
|
||||
category: 'video',
|
||||
sourceFormats: ['mp4', 'avi', 'mov', 'mkv'],
|
||||
targetFormat: 'webm',
|
||||
options: {
|
||||
videoCodec: 'libvpx-vp9',
|
||||
videoCodec: 'libvpx',
|
||||
videoBitrate: '1M',
|
||||
audioCodec: 'libopus',
|
||||
audioCodec: 'libvorbis',
|
||||
audioBitrate: '128k',
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user