diff --git a/bin/index.js b/bin/index.js index d05a2ba..c77f0aa 100644 --- a/bin/index.js +++ b/bin/index.js @@ -7,16 +7,16 @@ import path from "path" //get settings let settings = new SettingsManager() await settings.start() -let resolve = path.resolve + let term = termkit.terminal const ui = new UI(settings.settings, settings.currentSetting) /** - * TODO : Adapt audio quality as well to accomodate long videos(Currently 5m is too much) - * FIND A WAY TO COMPILE THIS:.. + * TODO : FIND A WAY TO COMPILE THIS:.. + * */ -const inputList = process.argv//.slice() +const inputList = process.argv.slice(2) //if launched without params if (!inputList[0]) { ui.startMenu() //stops program here @@ -32,7 +32,7 @@ if (inputList[0] == "-preset") { for (let i = 2; i < inputList.length; i++) { let file - file = resolve(inputList[i]) + file = path.resolve(inputList[i]) filePaths.push(file) @@ -47,7 +47,7 @@ if (inputList[0] == "-preset") { else { for (let i = 0; i < inputList.length; i++) { let file - file = resolve(inputList[i]) + file = path.resolve(inputList[i]) filePaths.push(file) diff --git a/lib/encoder.js b/lib/encoder.js index 5ac0407..a41fbe8 100644 --- a/lib/encoder.js +++ b/lib/encoder.js @@ -76,9 +76,9 @@ export class Encoder { command += `ffmpeg -y -i "${path}" -vcodec libvpx-vp9 -acodec libvorbis ` command += `-deadline ${this.currentSetting.deadline} ` command += `-cpu-used ${this.currentSetting.cpuUsed} ` - if (this.currentSetting?.minrate) { - command += `-b:v ${Math.round(videoBitRate * 0.95)}k ` - command += `-minrate ${Math.round(videoBitRate / 100 * this.currentSetting.minrate)}k ` + if (this.currentSetting?.bitrateError) { + command += `-b:v ${Math.round(videoBitRate / 100 * this.currentSetting.bitrateError)}k ` + command += `-minrate ${Math.round(videoBitRate)}k ` command += `-maxrate ${videoBitRate}k ` } else { diff --git a/lib/settingsManager.js b/lib/settingsManager.js index a8c45d6..9ff1e6e 100644 --- a/lib/settingsManager.js +++ b/lib/settingsManager.js @@ -1,5 +1,5 @@ import fs from "fs" - +import path from "path" export class SettingsManager { settings @@ -14,8 +14,8 @@ export class SettingsManager { async #init() { - - let settings = await this.#getSettings().catch(async (err) => { + let settings + settings = await this.#getSettings().catch(async (err) => { settings = undefined }) //console.log(settings) @@ -25,7 +25,7 @@ export class SettingsManager { } async #getSettings() { return new Promise((resolve, reject) => { - const getSettings = fs.readFile("settings.json", (err, data) => { + const getSettings = fs.readFile(path.resolve(__dirname, "settings.json"), (err, data) => { if (err) reject(err) resolve(data) }) @@ -34,184 +34,143 @@ export class SettingsManager { async #makeNewSettingsFile() { const settings = ` { - "currentSetting": 2, + "currentSetting": 3, "presets": [{ - "name": "Most efficient 8 megabytes of your life", - "cpuUsed": 0, - "deadline": "best", - "minrate": 90, - "crfMap": [{ - "resolution": 240, - "crf": 1 - }, - { - "resolution": 360, - "crf": 1 - }, - { - "resolution": 480, - "crf": 1 - }, - { - "resolution": 720, - "crf": 1 - }, - { - "resolution": 1080, - "crf": 1 - }, - { - "resolution": 1440, - "crf": 1 - }, - { - "resolution": 2160, - "crf": 1 - } - ] - }, - { - "name": "I have some time to kill", - "cpuUsed": 1, - "deadline": "good", - "minrate": 75, - "crfMap": [{ - "resolution": 240, - "crf": 20 - }, - { - "resolution": 360, - "crf": 20 - }, - { - "resolution": 480, - "crf": 20 - }, - { - "resolution": 720, - "crf": 20 - }, - { - "resolution": 1080, - "crf": 17 - }, - { - "resolution": 1440, - "crf": 15 - }, - { - "resolution": 2160, - "crf": 10 - } - ] - }, - { - "name": "Mid", - "cpuUsed": 3, - "deadline": "good", - "minrate":75, - "crfMap": [{ - "resolution": 240, - "crf": 30 - }, - { - "resolution": 360, - "crf": 30 - }, - { - "resolution": 480, - "crf": 30 - }, - { - "resolution": 720, - "crf": 25 - }, - { - "resolution": 1080, - "crf": 20 - }, - { - "resolution": 1440, - "crf": 15 - }, - { - "resolution": 2160, - "crf": 10 - } - ] - }, - { - "name": "I don't like waiting", - "cpuUsed": 4, - "deadline": 100, - "minrate": 90, - "crfMap": [{ - "resolution": 240, - "crf": 45 - }, - { - "resolution": 360, - "crf": 42 - }, - { - "resolution": 480, - "crf": 40 - }, - { - "resolution": 720, - "crf": 35 - }, - { - "resolution": 1080, - "crf": 30 - }, - { - "resolution": 1440, - "crf": 25 - }, - { - "resolution": 2160, - "crf": 20 - } - ] - }, - { - "name": "I want it, NOW!", - "cpuUsed": 4, - "deadline": "realtime", - "minrate": 50, - "crfMap": [{ - "resolution": 240, - "crf": 40 - }, - { - "resolution": 360, - "crf": 35 - }, - { - "resolution": 480, - "crf": 30 - }, - { - "resolution": 720, - "crf": 25 - }, - { - "resolution": 1080, - "crf": 20 - }, - { - "resolution": 1440, - "crf": 15 - }, - { - "resolution": 2160, - "crf": 10 - } - ] - } - - ] + "name": "Most efficient 8 megabytes of your life", + "cpuUsed": 0, + "deadline": "best", + "bitrateError": 90, + "crfMap": [{ + "resolution": 240, + "crf": 1 + }, { + "resolution": 360, + "crf": 1 + }, { + "resolution": 480, + "crf": 1 + }, { + "resolution": 720, + "crf": 1 + }, { + "resolution": 1080, + "crf": 1 + }, { + "resolution": 1440, + "crf": 1 + }, { + "resolution": 2160, + "crf": 1 + }] + }, { + "name": "I have some time to kill", + "cpuUsed": 1, + "deadline": "good", + "bitrateError": 90, + "crfMap": [{ + "resolution": 240, + "crf": 20 + }, { + "resolution": 360, + "crf": 20 + }, { + "resolution": 480, + "crf": 20 + }, { + "resolution": 720, + "crf": 20 + }, { + "resolution": 1080, + "crf": 17 + }, { + "resolution": 1440, + "crf": 15 + }, { + "resolution": 2160, + "crf": 10 + }] + }, { + "name": "Mid", + "cpuUsed": 3, + "deadline": "good", + "bitrateError": 80, + "crfMap": [{ + "resolution": 240, + "crf": 30 + }, { + "resolution": 360, + "crf": 30 + }, { + "resolution": 480, + "crf": 30 + }, { + "resolution": 720, + "crf": 25 + }, { + "resolution": 1080, + "crf": 20 + }, { + "resolution": 1440, + "crf": 15 + }, { + "resolution": 2160, + "crf": 10 + }] + }, { + "name": "I don't like waiting", + "cpuUsed": 4, + "deadline": 100, + "bitrateError": 70, + "crfMap": [{ + "resolution": 240, + "crf": 45 + }, { + "resolution": 360, + "crf": 42 + }, { + "resolution": 480, + "crf": 40 + }, { + "resolution": 720, + "crf": 35 + }, { + "resolution": 1080, + "crf": 30 + }, { + "resolution": 1440, + "crf": 25 + }, { + "resolution": 2160, + "crf": 20 + }] + }, { + "name": "I want it, NOW!", + "cpuUsed": 4, + "deadline": "realtime", + "bitrateError": 60, + "crfMap": [{ + "resolution": 240, + "crf": 40 + }, { + "resolution": 360, + "crf": 35 + }, { + "resolution": 480, + "crf": 30 + }, { + "resolution": 720, + "crf": 25 + }, { + "resolution": 1080, + "crf": 20 + }, { + "resolution": 1440, + "crf": 15 + }, { + "resolution": 2160, + "crf": 10 + }] + }] } ` return new Promise((resolve, reject) => {