Files
BaraBingo/lib/convert.ts
SlavaVlad 3f41d7699c
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m44s
feat: accept any audio/video upload, server converts to 6s compressed MP3
2026-06-15 03:25:44 +03:00

19 lines
525 B
TypeScript

import { execSync } from "child_process";
/**
* 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}" -t 6 -vn -codec:a libmp3lame -b:a 64k -y "${mp3Path}" 2>/dev/null`,
{ timeout: 30000 }
);
return true;
} catch {
return false;
}
}