This commit is contained in:
@@ -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