Finally fixed multi file progres bars
This commit is contained in:
parent
88cb759829
commit
87a41cb39c
4 changed files with 17 additions and 13 deletions
|
@ -60,7 +60,7 @@ async function main(menu = false) {
|
||||||
//get settings
|
//get settings
|
||||||
let settings = new SettingsManager()
|
let settings = new SettingsManager()
|
||||||
await settings.start(__dirname)
|
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()
|
if (menu) savesettings = await ui.startMenu()
|
||||||
|
|
||||||
|
@ -94,15 +94,14 @@ async function main(menu = false) {
|
||||||
}
|
}
|
||||||
//start encoding all
|
//start encoding all
|
||||||
if (isListEncodable) {
|
if (isListEncodable) {
|
||||||
|
|
||||||
let encoder = []
|
let encoder = []
|
||||||
|
console.log(`Encoding with "${settings.currentSetting.name}" preset...`)
|
||||||
for (let i = 0; i < filePaths.length; i++) {
|
for (let i = 0; i < filePaths.length; i++) {
|
||||||
encoder.push(new Encoder(settings.settings, settings.currentSetting, presetIndexArg))
|
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") {
|
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.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) })
|
encoder[i].on("close", () => { ui.encodeFinished(i) })
|
||||||
}
|
}
|
||||||
else if (fileTypes[i] == "webm" || fileTypes[i] == "mp4" || fileTypes[i] == "mov" || fileTypes[i] == "mkv" || fileTypes[i] == "avi") {
|
else if (fileTypes[i] == "webm" || fileTypes[i] == "mp4" || fileTypes[i] == "mov" || fileTypes[i] == "mkv" || fileTypes[i] == "avi") {
|
||||||
|
|
|
@ -32,8 +32,8 @@ class Encoder {
|
||||||
*/
|
*/
|
||||||
async encodeAudio(path, out) {
|
async encodeAudio(path, out) {
|
||||||
let [duration, resolution] = await this.#getDurationAndResolution(path)
|
let [duration, resolution] = await this.#getDurationAndResolution(path)
|
||||||
const videoBitRate = Math.round(62000 / duration)
|
const audioBitRate = Math.round(62000 / duration)
|
||||||
this.encoder = exec(`ffmpeg -y -i "${path}" -c:a libvorbis -b:a ${videoBitRate}k ${out}.ogg`)
|
this.encoder = exec(`ffmpeg -y -i "${path}" -c:a libvorbis -b:a ${audioBitRate}k "${out}.ogg"`)
|
||||||
return [duration, out, undefined]
|
return [duration, out, undefined]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class Encoder {
|
||||||
* @param {String} out output filename
|
* @param {String} out output filename
|
||||||
*/
|
*/
|
||||||
async encodePicture(path, out) {
|
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]
|
return [1, out, undefined]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,9 +146,9 @@ class SettingsManager {
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
"name": "I want it, NOW!",
|
"name": "I want it, NOW!",
|
||||||
"cpuUsed": 4,
|
"cpuUsed": 3,
|
||||||
"deadline": "realtime",
|
"deadline": "realtime",
|
||||||
"bitrateError": 60,
|
"bitrateError": 50,
|
||||||
"crfMap": [{
|
"crfMap": [{
|
||||||
"resolution": 240,
|
"resolution": 240,
|
||||||
"crf": 40
|
"crf": 40
|
||||||
|
|
13
lib/ui.js
13
lib/ui.js
|
@ -40,7 +40,8 @@ class UI {
|
||||||
"isPastHalf": false,
|
"isPastHalf": false,
|
||||||
"filename": filename,
|
"filename": filename,
|
||||||
"duration": duration,
|
"duration": duration,
|
||||||
"finished": false
|
"finished": false,
|
||||||
|
"isVideo": false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
const barIndex = this.bars.length - 1
|
const barIndex = this.bars.length - 1
|
||||||
|
@ -53,6 +54,7 @@ class UI {
|
||||||
this.bars[barIndex]?.bar.update(1, { filename: `${this.bars[barIndex].filename}.webp` })
|
this.bars[barIndex]?.bar.update(1, { filename: `${this.bars[barIndex].filename}.webp` })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.bars[barIndex].isVideo = isVideo
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
const currentTime = chunk.split("time=")[1]?.split(" ")[0]
|
const currentTime = chunk.split("time=")[1]?.split(" ")[0]
|
||||||
if (!currentTime) return
|
if (!currentTime) return
|
||||||
|
@ -79,11 +81,14 @@ class UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encodeFinished(barIndex) {
|
async encodeFinished(barIndex) {
|
||||||
this.bars[barIndex].fininshed = true
|
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
|
// if all are finished stop multibars and exit
|
||||||
for (let i = 0; i < this.bars.length; i++) {
|
for (let i = 0; i < this.bars.length; i++) {
|
||||||
if (this.bars[i].finished) return
|
if (!this.bars[i].finished) return
|
||||||
}
|
}
|
||||||
this.multibar.stop()
|
this.multibar.stop()
|
||||||
fs.rm("ffmpeg2pass-0.log", (error) => { error })
|
fs.rm("ffmpeg2pass-0.log", (error) => { error })
|
||||||
|
|
Loading…
Reference in a new issue