Fix: frame-accurate bg-removal progress text

This commit is contained in:
2026-03-21 01:14:54 -07:00
parent 353a9fff97
commit cb5d666eca

View File

@@ -77,18 +77,19 @@ export async function removeBackgroundFrames(frameDataUrls, { onProgress } = {})
const total = frameDataUrls.length; const total = frameDataUrls.length;
for (let i = 0; i < total; i++) { for (let i = 0; i < total; i++) {
const frameNo = i + 1; const frameIndex = i;
const src = frameDataUrls[i]; const frameNo = frameIndex + 1;
const src = frameDataUrls[frameIndex];
onProgress?.({ onProgress?.({
pct: Math.round((i / total) * 100), pct: Math.round((frameIndex / total) * 100),
text: `preparing frame ${frameNo} of ${total} for background removal...` text: `preparing frame ${frameNo} of ${total} for background removal...`
}); });
const pngFile = await toPngFile(src, `frame-${frameNo}.png`); const pngFile = await toPngFile(src, `frame-${frameNo}.png`);
onProgress?.({ onProgress?.({
pct: Math.round((i / total) * 100), pct: Math.round((frameIndex / total) * 100),
text: `removing background from frame ${frameNo} of ${total}...` text: `removing background from frame ${frameNo} of ${total}...`
}); });
@@ -98,7 +99,7 @@ export async function removeBackgroundFrames(frameDataUrls, { onProgress } = {})
progress: (_key, current, stepTotal) => { progress: (_key, current, stepTotal) => {
if (!stepTotal) return; if (!stepTotal) return;
const inner = current / stepTotal; const inner = current / stepTotal;
const pct = Math.round(((i + inner) / total) * 100); const pct = Math.round(((frameIndex + inner) / total) * 100);
onProgress?.({ onProgress?.({
pct, pct,
text: `removing background from frame ${frameNo} of ${total}...` text: `removing background from frame ${frameNo} of ${total}...`