feat: convert uploaded OGG to MP3 via ffmpeg
All checks were successful
Deploy / build-and-deploy (push) Successful in 2m4s
All checks were successful
Deploy / build-and-deploy (push) Successful in 2m4s
This commit is contained in:
23
lib/convert.ts
Normal file
23
lib/convert.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { execSync } from "child_process";
|
||||
import fs from "fs";
|
||||
|
||||
export function convertOggToMp3(inputPath: string, outputPath: string): boolean {
|
||||
try {
|
||||
execSync(
|
||||
`ffmpeg -i "${inputPath}" -codec:a libmp3lame -b:a 128k -y "${outputPath}" 2>/dev/null`,
|
||||
{ timeout: 15000 }
|
||||
);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function convertOggToMp3OrCopy(inputPath: string, mp3Path: string): string {
|
||||
if (convertOggToMp3(inputPath, mp3Path)) {
|
||||
return mp3Path;
|
||||
}
|
||||
// fallback: keep original OGG
|
||||
fs.copyFileSync(inputPath, mp3Path.replace(/\.mp3$/, ".ogg"));
|
||||
return mp3Path.replace(/\.mp3$/, ".ogg");
|
||||
}
|
||||
Reference in New Issue
Block a user