fix(merge): fix progress formula for long videos, add optional totalDurationSec param, normalize Windows paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xRangerDE 2026-03-19 17:48:02 +01:00
parent 645d2f147b
commit 5a20c1c6a4

View File

@ -2428,6 +2428,29 @@ async function mergeVideos(
return false; 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<boolean> => { const runMergeAttempt = async (copyMode: boolean): Promise<boolean> => {
const args = [ const args = [
'-f', 'concat', '-f', 'concat',
@ -2460,7 +2483,11 @@ async function mergeVideos(
const match = line.match(/out_time_us=(\d+)/); const match = line.match(/out_time_us=(\d+)/);
if (match) { if (match) {
const currentUs = parseInt(match[1], 10); 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));
}
} }
}); });