From 5a20c1c6a4470f9d2685ccc2a32f027886190c52 Mon Sep 17 00:00:00 2001 From: xRangerDE Date: Thu, 19 Mar 2026 17:48:02 +0100 Subject: [PATCH] fix(merge): fix progress formula for long videos, add optional totalDurationSec param, normalize Windows paths Co-Authored-By: Claude Opus 4.6 (1M context) --- src/main.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index a10f301..336d135 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2428,6 +2428,29 @@ async function mergeVideos( return false; } + // Determine total duration for accurate progress + let mergeTotalDurationUs = 0; + if (totalDurationSec && totalDurationSec > 0) { + mergeTotalDurationUs = totalDurationSec * 1_000_000; + } else { + // Fallback: use ffprobe to get total duration of all input files + const ffprobe = getFFprobePath(); + for (const filePath of inputFiles) { + try { + const result = execSync( + `"${ffprobe}" -v quiet -show_entries format=duration -of csv=p=0 "${filePath}"`, + { timeout: 10000, windowsHide: true } + ).toString().trim(); + const dur = parseFloat(result); + if (!isNaN(dur)) { + mergeTotalDurationUs += dur * 1_000_000; + } + } catch { + // If ffprobe fails, fall back to old behavior + } + } + } + const runMergeAttempt = async (copyMode: boolean): Promise => { const args = [ '-f', 'concat', @@ -2460,7 +2483,11 @@ async function mergeVideos( const match = line.match(/out_time_us=(\d+)/); if (match) { const currentUs = parseInt(match[1], 10); - onProgress(Math.min(99, currentUs / 10000000)); + if (mergeTotalDurationUs > 0) { + onProgress(Math.min(99, (currentUs / mergeTotalDurationUs) * 100)); + } else { + onProgress(Math.min(99, currentUs / 10000000)); + } } });