Encode jukebox audio with native ffmpeg, normalise loudness, read metadata
- Play every track through an ffmpeg process that normalises loudness (EBU R128) and outputs Ogg Opus, handed to Discord as is: no more Opus encoding in JavaScript with opusscript. Measured at over 40x real time, about 2% of a core while playing. Closing the stream kills ffmpeg. - Encoding at upload instead was ruled out: over two minutes for an 85-minute mix, during which the upload would hang. - Read duration, title and artist with ffprobe at upload; default the title to "Artist - Title" or the file name without extension. - Fill the duration of existing library entries at startup. - Expose the position of the current track in queue snapshots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d200040691
commit
98f4d29ac7
9 changed files with 309 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { Router } from "express";
|
||||
import multer from "multer";
|
||||
import { validateAudioFile } from "../../media/validateAudioFile.js";
|
||||
import { probeAudioFile } from "../../media/validateAudioFile.js";
|
||||
import { serializeTrack } from "../serializers.js";
|
||||
import {
|
||||
TEMP_DIR,
|
||||
|
|
@ -29,6 +29,15 @@ const upload = multer({
|
|||
},
|
||||
});
|
||||
|
||||
// Titre par défaut : « Artiste - Titre » d'après les tags, sinon le nom du fichier sans
|
||||
// son extension.
|
||||
function defaultTitle({ title, artist }, originalName) {
|
||||
if (title) {
|
||||
return (artist ? `${artist} - ${title}` : title).slice(0, 200);
|
||||
}
|
||||
return originalName.replace(/\.[a-z0-9]{1,10}$/i, "").slice(0, 200) || originalName;
|
||||
}
|
||||
|
||||
function uploadsRouter({ queue }) {
|
||||
const router = Router();
|
||||
|
||||
|
|
@ -43,7 +52,7 @@ function uploadsRouter({ queue }) {
|
|||
.replace(/[\u0000-\u001f]/g, "")
|
||||
.trim()
|
||||
.slice(0, 80);
|
||||
const title = String(req.body?.notes || req.file.originalname)
|
||||
const customTitle = String(req.body?.notes || "")
|
||||
.replace(/[\u0000-\u001f]/g, "")
|
||||
.trim()
|
||||
.slice(0, 200);
|
||||
|
|
@ -57,12 +66,17 @@ function uploadsRouter({ queue }) {
|
|||
throw error;
|
||||
}
|
||||
|
||||
await validateAudioFile(req.file.path);
|
||||
const metadata = await probeAudioFile(req.file.path);
|
||||
const track = registerUploadedFile(req.file, {
|
||||
permanent,
|
||||
uploader,
|
||||
title: title || req.file.originalname,
|
||||
title: customTitle || defaultTitle(metadata, req.file.originalname),
|
||||
duration: metadata.duration,
|
||||
artist: metadata.artist,
|
||||
});
|
||||
if (permanent) {
|
||||
queue.emit("libraryUpdate");
|
||||
}
|
||||
|
||||
if (enqueue) {
|
||||
queue.enqueue(track);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue