Extract audio from video files before loading
Video files (MP4, MKV, etc.) are now processed with ffmpeg to extract audio to a temp WAV file before loading into wavesurfer. This prevents the WebView crash caused by trying to fetch multi-GB files into memory. - New extract_audio Tauri command uses ffmpeg (sidecar-bundled or system) - Frontend detects video extensions and extracts audio automatically - User-friendly error if ffmpeg is not installed with install instructions - Reverted wavesurfer MediaElement approach in favor of clean extraction - Added FFmpeg install guide to USER_GUIDE.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,12 @@
|
||||
isReady = false;
|
||||
});
|
||||
|
||||
wavesurfer.on('error', (err: Error) => {
|
||||
console.error('[voice-to-notes] WaveSurfer error:', err);
|
||||
isLoading = false;
|
||||
loadError = 'Failed to load audio';
|
||||
});
|
||||
|
||||
if (audioUrl) {
|
||||
loadAudio(audioUrl);
|
||||
}
|
||||
|
||||
@@ -254,6 +254,8 @@
|
||||
// Changes persist when user saves the project file.
|
||||
}
|
||||
|
||||
const VIDEO_EXTENSIONS = ['mp4', 'mkv', 'avi', 'mov', 'webm'];
|
||||
|
||||
async function handleFileImport() {
|
||||
const filePath = await open({
|
||||
multiple: false,
|
||||
@@ -265,9 +267,34 @@
|
||||
});
|
||||
if (!filePath) return;
|
||||
|
||||
// Track the original file path and convert to asset URL for wavesurfer
|
||||
// For video files, extract audio first using ffmpeg
|
||||
const ext = filePath.split('.').pop()?.toLowerCase() ?? '';
|
||||
let audioPath = filePath;
|
||||
if (VIDEO_EXTENSIONS.includes(ext)) {
|
||||
try {
|
||||
audioPath = await invoke<string>('extract_audio', { filePath });
|
||||
} catch (err) {
|
||||
console.error('[voice-to-notes] Failed to extract audio:', err);
|
||||
const msg = String(err);
|
||||
if (msg.includes('ffmpeg not found')) {
|
||||
alert(
|
||||
'FFmpeg is required to import video files.\n\n' +
|
||||
'Install FFmpeg:\n' +
|
||||
' Windows: winget install ffmpeg\n' +
|
||||
' macOS: brew install ffmpeg\n' +
|
||||
' Linux: sudo apt install ffmpeg\n\n' +
|
||||
'Then restart Voice to Notes and try again.'
|
||||
);
|
||||
} else {
|
||||
alert(`Failed to extract audio from video: ${msg}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Track the original file path (video or audio) for the sidecar
|
||||
audioFilePath = filePath;
|
||||
audioUrl = convertFileSrc(filePath);
|
||||
audioUrl = convertFileSrc(audioPath);
|
||||
waveformPlayer?.loadAudio(audioUrl);
|
||||
|
||||
// Clear previous results
|
||||
|
||||
Reference in New Issue
Block a user