Skip to content

Commit

Permalink
NaN check for archive conversion progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Oct 5, 2024
1 parent 358ef6a commit fc44161
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3631,21 +3631,23 @@ async function convertAndOrganiseFiles() {
DEBUG && console.log('FFmpeg command: ' + commandLine);
})
.on('progress', (progress) => {
// Calculate the cumulative progress
fileProgressMap[inputFilePath] = progress.percent * scaleFactor;
console.log(`${inputFilePath} progress: ${fileProgressMap[inputFilePath].toFixed(1)}%`)
const values = Object.values(fileProgressMap);
// Calculate the sum of the values
const sum = values.reduce((accumulator, currentValue) => accumulator + currentValue, 0);

// Calculate the average
const average = sum / values.length;

UI.postMessage({
event: `conversion-progress`,
progress: { percent: average }, // Use cumulative progress for smooth transition
text: `Archive file conversion progress: ${average.toFixed(1)}% `
});
if (!isNaN(progress.percent)){
// Calculate the cumulative progress
fileProgressMap[inputFilePath] = progress.percent * scaleFactor;
console.log(`${inputFilePath} progress: ${fileProgressMap[inputFilePath].toFixed(1)}%`)
const values = Object.values(fileProgressMap);
// Calculate the sum of the values
const sum = values.reduce((accumulator, currentValue) => accumulator + currentValue, 0);

// Calculate the average
const average = sum / values.length;

UI.postMessage({
event: `conversion-progress`,
progress: { percent: average }, // Use cumulative progress for smooth transition
text: `Archive file conversion progress: ${average.toFixed(1)}% `
});
}
})
.run();
}
Expand Down

0 comments on commit fc44161

Please sign in to comment.