1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 02:12:30 +01:00

fix progress bug

closes #2161
This commit is contained in:
Mikael Finstad 2024-09-26 09:18:08 +03:00
parent 4c00987db9
commit f6c1266588
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

View File

@ -1178,19 +1178,20 @@ function App() {
setCutProgress(0); setCutProgress(0);
let lastOutPath: string | undefined; let lastOutPath: string | undefined;
let totalProgress = 0;
const onProgress = (progress: number) => { const segmentProgresses: Record<number, number> = {};
totalProgress += progress; const handleSegmentProgress = (segIndex: number, progress: number) => {
segmentProgresses[segIndex] = progress;
const totalProgress = segments.reduce((acc, _ignored, index) => acc + (segmentProgresses[index] ?? 0), 0);
setCutProgress(totalProgress / segments.length); setCutProgress(totalProgress / segments.length);
}; };
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
for (const segment of segments) { for (const [index, segment] of segments.entries()) {
const { start, end } = segment; const { start, end } = segment;
if (filePath == null) throw new Error(); if (filePath == null) throw new Error();
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
lastOutPath = await captureFramesRange({ customOutDir, filePath, fps: detectedFps, fromTime: start, toTime: end, estimatedMaxNumFiles: captureFramesResponse.estimatedMaxNumFiles, captureFormat, quality: captureFrameQuality, filter: captureFramesResponse.filter, outputTimestamps: captureFrameFileNameFormat === 'timestamp', onProgress }); lastOutPath = await captureFramesRange({ customOutDir, filePath, fps: detectedFps, fromTime: start, toTime: end, estimatedMaxNumFiles: captureFramesResponse.estimatedMaxNumFiles, captureFormat, quality: captureFrameQuality, filter: captureFramesResponse.filter, outputTimestamps: captureFrameFileNameFormat === 'timestamp', onProgress: (progress) => handleSegmentProgress(index, progress) });
} }
if (!hideAllNotifications && lastOutPath != null) { if (!hideAllNotifications && lastOutPath != null) {
showOsNotification(i18n.t('Frames have been extracted')); showOsNotification(i18n.t('Frames have been extracted'));