Add fluent-ffmpeg dependency and refactor AAC to FLAC conversion logic
This commit is contained in:
parent
df0627dea2
commit
34e6265cae
3 changed files with 26 additions and 11 deletions
|
@ -1,6 +1,9 @@
|
|||
import { FlacStreamTagger } from "flac-stream-tagger";
|
||||
import Ffmpeg from "fluent-ffmpeg";
|
||||
import ffmpegPath from "ffmpeg-static";
|
||||
import { PassThrough } from "stream";
|
||||
|
||||
Ffmpeg.setFfmpegPath(ffmpegPath as string);
|
||||
|
||||
export default class {
|
||||
authHeaders: { [key: string]: string }
|
||||
|
@ -10,18 +13,20 @@ export default class {
|
|||
}
|
||||
|
||||
async convertAacToFlac(buffer: ArrayBuffer) {
|
||||
const fileId = Bun.nanoseconds().toString(36);
|
||||
const inputStream = new PassThrough();
|
||||
inputStream.end(Buffer.from(buffer));
|
||||
|
||||
Bun.write(`tmp/${fileId}.aac`, Buffer.from(buffer))
|
||||
const outputChunks: Buffer[] = [];
|
||||
|
||||
await Bun.$`${ffmpegPath} -i tmp/${fileId}.aac -c:a flac tmp/${fileId}.flac`.quiet()
|
||||
|
||||
await Bun.file(`tmp/${fileId}.aac`).delete();
|
||||
const flac = Bun.file(`tmp/${fileId}.flac`)
|
||||
const audioBuffer = await flac.arrayBuffer();
|
||||
await flac.delete()
|
||||
|
||||
return audioBuffer;
|
||||
await new Promise((resolve, reject) => {
|
||||
Ffmpeg(inputStream)
|
||||
.audioCodec("flac")
|
||||
.format("flac")
|
||||
.on("error", reject)
|
||||
.on("end", resolve)
|
||||
.pipe()
|
||||
.on("data", chunk => outputChunks.push(chunk));
|
||||
});
|
||||
}
|
||||
|
||||
async fetchTrack(id: number) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue