From 2fb5659f09c1ebab4acd5377ebe3eb6e1f7e885a Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Thu, 2 Apr 2026 22:20:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E5=B0=91=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index d1a11f7..7794805 100644 --- a/server.js +++ b/server.js @@ -120,6 +120,29 @@ const probeFile = (filePath) => { }); }; +const parseTimemarkToSeconds = (timemark) => { + if (typeof timemark !== 'string' || !timemark.trim()) { + return 0; + } + + const parts = timemark.trim().split(':'); + if (parts.length !== 3) { + const numericValue = parseFloat(timemark); + return Number.isFinite(numericValue) ? numericValue : 0; + } + + const [hoursPart, minutesPart, secondsPart] = parts; + const hours = parseInt(hoursPart, 10); + const minutes = parseInt(minutesPart, 10); + const seconds = parseFloat(secondsPart); + + if (![hours, minutes, seconds].every(Number.isFinite)) { + return 0; + } + + return (hours * 3600) + (minutes * 60) + seconds; +}; + const stopActiveTranscode = (progressKey) => { const activeCommand = transcodeProcesses.get(progressKey); if (!activeCommand) { @@ -448,7 +471,7 @@ app.get('/api/stream', async (req, res) => { ffmpegCommand .on('progress', (progress) => { const effectiveDuration = Math.max(0, (progressMap[progressKey]?.duration || 0) - startSeconds); - const timemarkSeconds = ffmpeg.timemarkToSeconds(progress.timemark || '0'); + const timemarkSeconds = parseTimemarkToSeconds(progress.timemark || '0'); const absoluteSeconds = startSeconds + (isFinite(timemarkSeconds) ? timemarkSeconds : 0); const percent = effectiveDuration > 0 ? Math.min(Math.max(Math.round((absoluteSeconds / (progressMap[progressKey]?.duration || effectiveDuration)) * 100), 0), 100)