From 7c5424437e52c9453fb29578a035989cc98fdf61 Mon Sep 17 00:00:00 2001 From: Daniel <790119+DanTheMan827@users.noreply.github.com> Date: Thu, 19 Mar 2026 14:13:58 -0500 Subject: [PATCH] feat(ffmpeg): add WAV format support and detection for use in dev mode - Added WAV format to customFormats with appropriate metadata. - Implemented detection for RIFF/WAVE format in detectAudioFormat function. --- js/ffmpegFormats.ts | 12 ++++++++++++ js/utils.js | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/js/ffmpegFormats.ts b/js/ffmpegFormats.ts index ef69277..562cbd0 100644 --- a/js/ffmpegFormats.ts +++ b/js/ffmpegFormats.ts @@ -130,6 +130,18 @@ export const customFormats: Record = { }, }; +// Add wav to custom formats when vite is in dev mode +if (import.meta.env.DEV) { + customFormats.FFMPEG_WAV = { + displayName: 'WAV (16-bit PCM)', + ffmpegArgs: ['-map_metadata', '-1'], + outputFilename: 'output.wav', + outputMime: 'audio/wav', + extension: 'wav', + category: 'WAV', + }; +} + /** * Container format definitions for lossless re-muxing. Each entry describes * the ffmpeg arguments needed to produce that container and provides a diff --git a/js/utils.js b/js/utils.js index 75588d7..022e1b5 100644 --- a/js/utils.js +++ b/js/utils.js @@ -140,6 +140,22 @@ export const detectAudioFormat = (view, mimeType = '') => { return 'mp3'; } + // Detect RIFF/WAVE by "RIFF" at offset 0 and "WAVE" at offset 8 (only in dev mode) + if ( + import.meta.env.DEV && + view.byteLength >= 12 && + view.getUint8(0) === 0x52 && // R + view.getUint8(1) === 0x49 && // I + view.getUint8(2) === 0x46 && // F + view.getUint8(3) === 0x46 && // F + view.getUint8(8) === 0x57 && // W + view.getUint8(9) === 0x41 && // A + view.getUint8(10) === 0x56 && // V + view.getUint8(11) === 0x45 // E + ) { + return 'wav'; + } + // Check for MPEG frame sync (0xFF 0xFB or 0xFF 0xFA) if (view.byteLength >= 2 && view.getUint8(0) === 0xff && (view.getUint8(1) & 0xe0) === 0xe0) { return 'mp3';