1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 14:11:59 +01:00

playaround with settings

This commit is contained in:
2026-02-23 18:00:50 +01:00
parent 5a321562bd
commit 0a7c56ff1d

View File

@@ -21,12 +21,9 @@ checkFFmpeg().then((ffmpegPath) => {
logInfo(`${consoleLogTitle} Using ${ffmpegPath === 'ffmpeg' ? 'system-installed FFmpeg' : 'ffmpeg-static'}`);
logInfo(`${consoleLogTitle} Starting audio stream on device: \x1b[35m${serverConfig.audio.audioDevice}\x1b[0m`);
const sampleRate =
Number(this?.Server?.SampleRate || serverConfig.audio.sampleRate || 44100) +
Number(serverConfig.audio.samplerateOffset || 0);
const sampleRate = Number(this?.Server?.SampleRate || serverConfig.audio.sampleRate || 44100) + Number(serverConfig.audio.samplerateOffset || 0);
const channels =
Number(this?.Server?.Channels || serverConfig.audio.audioChannels || 2);
const channels = Number(this?.Server?.Channels || serverConfig.audio.audioChannels || 2);
let ffmpeg = null;
let restartTimer = null;
@@ -39,16 +36,12 @@ checkFFmpeg().then((ffmpegPath) => {
let inputArgs;
if (process.platform === 'win32') {
inputArgs = ["-f", "dshow", "-i", `audio=${device}`];
} else if (process.platform === 'darwin') {
inputArgs = ["-f", "avfoundation", "-i", device || ":0"];
} else {
inputArgs = ["-f", "alsa", "-i", device];
}
if (process.platform === 'win32') inputArgs = ["-f", "dshow", "-i", `audio=${device}`];
else if (process.platform === 'darwin') inputArgs = ["-f", "avfoundation", "-i", device || ":0"];
else inputArgs = ["-f", "alsa", "-i", device];
return [
"-fflags", "+nobuffer",
"-fflags", "+flush_packets",
"-flags", "low_delay",
"-rtbufsize", "4096",
"-probesize", "128",
@@ -79,15 +72,11 @@ checkFFmpeg().then((ffmpegPath) => {
logDebug(`${consoleLogTitle} Launching FFmpeg with args: ${args.join(' ')}`);
ffmpeg = spawn(ffmpegPath, args, {
stdio: ['ignore', 'pipe', 'pipe']
});
ffmpeg = spawn(ffmpegPath, args, {stdio: ['ignore', 'pipe', 'pipe']});
ffmpeg.stdout.pipe(audio_pipe, { end: false });
connectMessage(
`${consoleLogTitle} Connected FFmpeg → MP3 → Server.StdIn`
);
connectMessage(`${consoleLogTitle} Connected FFmpeg → MP3 → audioWss`);
ffmpeg.stderr.on('data', (data) => {
const msg = data.toString();
@@ -97,10 +86,7 @@ checkFFmpeg().then((ffmpegPath) => {
const match = msg.match(/time=(\d\d):(\d\d):(\d\d\.\d+)/);
if (match) {
const [_, hh, mm, ss] = match;
const totalSec =
parseInt(hh) * 3600 +
parseInt(mm) * 60 +
parseFloat(ss);
const totalSec = parseInt(hh) * 3600 + parseInt(mm) * 60 + parseFloat(ss);
if (lastTimestamp !== null && totalSec === lastTimestamp) {
staleCount++;
@@ -129,11 +115,8 @@ checkFFmpeg().then((ffmpegPath) => {
});
ffmpeg.on('exit', (code, signal) => {
if (signal) {
logWarn(`${consoleLogTitle} FFmpeg killed with signal ${signal}`);
} else if (code !== 0) {
logWarn(`${consoleLogTitle} FFmpeg exited with code ${code}`);
}
if (signal) logWarn(`${consoleLogTitle} FFmpeg killed with signal ${signal}`);
else if (code !== 0) logWarn(`${consoleLogTitle} FFmpeg exited with code ${code}`);
logWarn(`${consoleLogTitle} Restarting FFmpeg in 5 seconds...`);
setTimeout(launchFFmpeg, 5000);