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)); + } } });