From 87a41cb39c35cf4a5789601c3b26ec75efa6b6d9 Mon Sep 17 00:00:00 2001 From: Djkato Date: Thu, 5 May 2022 02:57:42 +0200 Subject: [PATCH] Finally fixed multi file progres bars --- bin/index.js | 7 +++---- lib/encoder.js | 6 +++--- lib/settingsManager.js | 4 ++-- lib/ui.js | 13 +++++++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bin/index.js b/bin/index.js index 4709a9c..96113d3 100644 --- a/bin/index.js +++ b/bin/index.js @@ -60,7 +60,7 @@ async function main(menu = false) { //get settings let settings = new SettingsManager() await settings.start(__dirname) - const ui = new UI(settings.settings, settings.currentSetting, settings.settingsFile) + const ui = new UI(settings.settings, settings.currentSetting, settings.settingsFile, filePaths?.length) if (menu) savesettings = await ui.startMenu() @@ -94,15 +94,14 @@ async function main(menu = false) { } //start encoding all if (isListEncodable) { - let encoder = [] + console.log(`Encoding with "${settings.currentSetting.name}" preset...`) for (let i = 0; i < filePaths.length; i++) { encoder.push(new Encoder(settings.settings, settings.currentSetting, presetIndexArg)) - console.log(`Encoding with "${settings.currentSetting.name}" preset...`) if (fileTypes[i] == "jpg" || fileTypes[i] == "JPG" || fileTypes[i] == "png" || fileTypes[i] == "PNG" || fileTypes[i] == "webp") { ui.newBar(await encoder[i].encodePicture(filePaths[i], fileNames[i])) - ui.updateBar("time=00:00:01", i, false, true) + encoder[i].on("update", (chunk) => { ui.updateBar(chunk, i, false, true) }) encoder[i].on("close", () => { ui.encodeFinished(i) }) } else if (fileTypes[i] == "webm" || fileTypes[i] == "mp4" || fileTypes[i] == "mov" || fileTypes[i] == "mkv" || fileTypes[i] == "avi") { diff --git a/lib/encoder.js b/lib/encoder.js index 593701b..039a391 100644 --- a/lib/encoder.js +++ b/lib/encoder.js @@ -32,8 +32,8 @@ class Encoder { */ async encodeAudio(path, out) { let [duration, resolution] = await this.#getDurationAndResolution(path) - const videoBitRate = Math.round(62000 / duration) - this.encoder = exec(`ffmpeg -y -i "${path}" -c:a libvorbis -b:a ${videoBitRate}k ${out}.ogg`) + const audioBitRate = Math.round(62000 / duration) + this.encoder = exec(`ffmpeg -y -i "${path}" -c:a libvorbis -b:a ${audioBitRate}k "${out}.ogg"`) return [duration, out, undefined] } @@ -43,7 +43,7 @@ class Encoder { * @param {String} out output filename */ async encodePicture(path, out) { - this.encoder = exec(`ffmpeg -y -i "${path}" -qscale 80 -compression_level 6 ${out}.webp`) + this.encoder = exec(`ffmpeg -y -i "${path}" -qscale 80 -compression_level 6 "${out}.webp"`) return [1, out, undefined] } diff --git a/lib/settingsManager.js b/lib/settingsManager.js index 8443227..757ef95 100644 --- a/lib/settingsManager.js +++ b/lib/settingsManager.js @@ -146,9 +146,9 @@ class SettingsManager { }] }, { "name": "I want it, NOW!", - "cpuUsed": 4, + "cpuUsed": 3, "deadline": "realtime", - "bitrateError": 60, + "bitrateError": 50, "crfMap": [{ "resolution": 240, "crf": 40 diff --git a/lib/ui.js b/lib/ui.js index 3beb05f..a41d7ea 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -40,7 +40,8 @@ class UI { "isPastHalf": false, "filename": filename, "duration": duration, - "finished": false + "finished": false, + "isVideo": false } ) const barIndex = this.bars.length - 1 @@ -53,6 +54,7 @@ class UI { this.bars[barIndex]?.bar.update(1, { filename: `${this.bars[barIndex].filename}.webp` }) return } + this.bars[barIndex].isVideo = isVideo if (isVideo) { const currentTime = chunk.split("time=")[1]?.split(" ")[0] if (!currentTime) return @@ -79,11 +81,14 @@ class UI { } } - encodeFinished(barIndex) { - this.bars[barIndex].fininshed = true + async encodeFinished(barIndex) { + this.bars[barIndex].finished = true + //sets bar to 100% + //const chunk = new Date(this.bars[barIndex].duration * 1000).toISOString().substr(11, 8) + //this.updateBar(chunk, barIndex, this.bars[barIndex].isVideo) // if all are finished stop multibars and exit for (let i = 0; i < this.bars.length; i++) { - if (this.bars[i].finished) return + if (!this.bars[i].finished) return } this.multibar.stop() fs.rm("ffmpeg2pass-0.log", (error) => { error })