feat: accept any audio/video upload, server converts to 6s compressed MP3
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m44s
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m44s
This commit is contained in:
@@ -1,23 +1,18 @@
|
||||
import { execSync } from "child_process";
|
||||
import fs from "fs";
|
||||
|
||||
export function convertOggToMp3(inputPath: string, outputPath: string): boolean {
|
||||
/**
|
||||
* Convert any audio/video file to a 6-second compressed MP3 via ffmpeg.
|
||||
* Returns true on success, false on failure.
|
||||
* The output file is always mp3Path (overwritten if exists).
|
||||
*/
|
||||
export function convertToCompressedMp3(inputPath: string, mp3Path: string): boolean {
|
||||
try {
|
||||
execSync(
|
||||
`ffmpeg -i "${inputPath}" -codec:a libmp3lame -b:a 128k -y "${outputPath}" 2>/dev/null`,
|
||||
{ timeout: 15000 }
|
||||
`ffmpeg -i "${inputPath}" -t 6 -vn -codec:a libmp3lame -b:a 64k -y "${mp3Path}" 2>/dev/null`,
|
||||
{ timeout: 30000 }
|
||||
);
|
||||
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