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,8 +1,8 @@
|
|||
import fs from "fs";
|
||||
import { EventEmitter } from "events";
|
||||
import {
|
||||
AudioPlayerStatus,
|
||||
NoSubscriberBehavior,
|
||||
StreamType,
|
||||
VoiceConnectionStatus,
|
||||
createAudioPlayer,
|
||||
createAudioResource,
|
||||
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from "@discordjs/voice";
|
||||
import { Events } from "discord.js";
|
||||
import { config } from "../config.js";
|
||||
import { createOpusStream } from "../media/validateAudioFile.js";
|
||||
import { serializeTrack, serializeTracks } from "../web/serializers.js";
|
||||
import {
|
||||
deleteTrackFile,
|
||||
|
|
@ -80,6 +81,8 @@ class MusicQueue extends EventEmitter {
|
|||
current: serializeTrack(this.currentTrack),
|
||||
upcoming: serializeTracks(this.queue),
|
||||
status: this.playbackStatus,
|
||||
// Millisecondes déjà jouées du morceau en cours (pauses exclues).
|
||||
position: this.audioPlayer?.state?.resource?.playbackDuration ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +248,9 @@ class MusicQueue extends EventEmitter {
|
|||
}
|
||||
|
||||
createResource(track) {
|
||||
return createAudioResource(fs.createReadStream(track.path));
|
||||
return createAudioResource(createOpusStream(track.path), {
|
||||
inputType: StreamType.OggOpus,
|
||||
});
|
||||
}
|
||||
|
||||
scheduleConnectRetry() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue