fixed [settings always new in cwd]

This commit is contained in:
Djkato 2022-05-04 20:40:14 +02:00
parent 55c12e920a
commit 894228d189
3 changed files with 149 additions and 190 deletions

View file

@ -7,16 +7,16 @@ import path from "path"
//get settings //get settings
let settings = new SettingsManager() let settings = new SettingsManager()
await settings.start() await settings.start()
let resolve = path.resolve
let term = termkit.terminal let term = termkit.terminal
const ui = new UI(settings.settings, settings.currentSetting) const ui = new UI(settings.settings, settings.currentSetting)
/** /**
* TODO : Adapt audio quality as well to accomodate long videos(Currently 5m is too much) * TODO : FIND A WAY TO COMPILE THIS:..
* FIND A WAY TO COMPILE THIS:.. *
*/ */
const inputList = process.argv//.slice() const inputList = process.argv.slice(2)
//if launched without params //if launched without params
if (!inputList[0]) { if (!inputList[0]) {
ui.startMenu() //stops program here ui.startMenu() //stops program here
@ -32,7 +32,7 @@ if (inputList[0] == "-preset") {
for (let i = 2; i < inputList.length; i++) { for (let i = 2; i < inputList.length; i++) {
let file let file
file = resolve(inputList[i]) file = path.resolve(inputList[i])
filePaths.push(file) filePaths.push(file)
@ -47,7 +47,7 @@ if (inputList[0] == "-preset") {
else { else {
for (let i = 0; i < inputList.length; i++) { for (let i = 0; i < inputList.length; i++) {
let file let file
file = resolve(inputList[i]) file = path.resolve(inputList[i])
filePaths.push(file) filePaths.push(file)

View file

@ -76,9 +76,9 @@ export class Encoder {
command += `ffmpeg -y -i "${path}" -vcodec libvpx-vp9 -acodec libvorbis ` command += `ffmpeg -y -i "${path}" -vcodec libvpx-vp9 -acodec libvorbis `
command += `-deadline ${this.currentSetting.deadline} ` command += `-deadline ${this.currentSetting.deadline} `
command += `-cpu-used ${this.currentSetting.cpuUsed} ` command += `-cpu-used ${this.currentSetting.cpuUsed} `
if (this.currentSetting?.minrate) { if (this.currentSetting?.bitrateError) {
command += `-b:v ${Math.round(videoBitRate * 0.95)}k ` command += `-b:v ${Math.round(videoBitRate / 100 * this.currentSetting.bitrateError)}k `
command += `-minrate ${Math.round(videoBitRate / 100 * this.currentSetting.minrate)}k ` command += `-minrate ${Math.round(videoBitRate)}k `
command += `-maxrate ${videoBitRate}k ` command += `-maxrate ${videoBitRate}k `
} }
else { else {

View file

@ -1,5 +1,5 @@
import fs from "fs" import fs from "fs"
import path from "path"
export class SettingsManager { export class SettingsManager {
settings settings
@ -14,8 +14,8 @@ export class SettingsManager {
async #init() { async #init() {
let settings
let settings = await this.#getSettings().catch(async (err) => { settings = await this.#getSettings().catch(async (err) => {
settings = undefined settings = undefined
}) })
//console.log(settings) //console.log(settings)
@ -25,7 +25,7 @@ export class SettingsManager {
} }
async #getSettings() { async #getSettings() {
return new Promise((resolve, reject) => { 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) if (err) reject(err)
resolve(data) resolve(data)
}) })
@ -34,184 +34,143 @@ export class SettingsManager {
async #makeNewSettingsFile() { async #makeNewSettingsFile() {
const settings = ` const settings = `
{ {
"currentSetting": 2, "currentSetting": 3,
"presets": [{ "presets": [{
"name": "Most efficient 8 megabytes of your life", "name": "Most efficient 8 megabytes of your life",
"cpuUsed": 0, "cpuUsed": 0,
"deadline": "best", "deadline": "best",
"minrate": 90, "bitrateError": 90,
"crfMap": [{ "crfMap": [{
"resolution": 240, "resolution": 240,
"crf": 1 "crf": 1
}, }, {
{ "resolution": 360,
"resolution": 360, "crf": 1
"crf": 1 }, {
}, "resolution": 480,
{ "crf": 1
"resolution": 480, }, {
"crf": 1 "resolution": 720,
}, "crf": 1
{ }, {
"resolution": 720, "resolution": 1080,
"crf": 1 "crf": 1
}, }, {
{ "resolution": 1440,
"resolution": 1080, "crf": 1
"crf": 1 }, {
}, "resolution": 2160,
{ "crf": 1
"resolution": 1440, }]
"crf": 1 }, {
}, "name": "I have some time to kill",
{ "cpuUsed": 1,
"resolution": 2160, "deadline": "good",
"crf": 1 "bitrateError": 90,
} "crfMap": [{
] "resolution": 240,
}, "crf": 20
{ }, {
"name": "I have some time to kill", "resolution": 360,
"cpuUsed": 1, "crf": 20
"deadline": "good", }, {
"minrate": 75, "resolution": 480,
"crfMap": [{ "crf": 20
"resolution": 240, }, {
"crf": 20 "resolution": 720,
}, "crf": 20
{ }, {
"resolution": 360, "resolution": 1080,
"crf": 20 "crf": 17
}, }, {
{ "resolution": 1440,
"resolution": 480, "crf": 15
"crf": 20 }, {
}, "resolution": 2160,
{ "crf": 10
"resolution": 720, }]
"crf": 20 }, {
}, "name": "Mid",
{ "cpuUsed": 3,
"resolution": 1080, "deadline": "good",
"crf": 17 "bitrateError": 80,
}, "crfMap": [{
{ "resolution": 240,
"resolution": 1440, "crf": 30
"crf": 15 }, {
}, "resolution": 360,
{ "crf": 30
"resolution": 2160, }, {
"crf": 10 "resolution": 480,
} "crf": 30
] }, {
}, "resolution": 720,
{ "crf": 25
"name": "Mid", }, {
"cpuUsed": 3, "resolution": 1080,
"deadline": "good", "crf": 20
"minrate":75, }, {
"crfMap": [{ "resolution": 1440,
"resolution": 240, "crf": 15
"crf": 30 }, {
}, "resolution": 2160,
{ "crf": 10
"resolution": 360, }]
"crf": 30 }, {
}, "name": "I don't like waiting",
{ "cpuUsed": 4,
"resolution": 480, "deadline": 100,
"crf": 30 "bitrateError": 70,
}, "crfMap": [{
{ "resolution": 240,
"resolution": 720, "crf": 45
"crf": 25 }, {
}, "resolution": 360,
{ "crf": 42
"resolution": 1080, }, {
"crf": 20 "resolution": 480,
}, "crf": 40
{ }, {
"resolution": 1440, "resolution": 720,
"crf": 15 "crf": 35
}, }, {
{ "resolution": 1080,
"resolution": 2160, "crf": 30
"crf": 10 }, {
} "resolution": 1440,
] "crf": 25
}, }, {
{ "resolution": 2160,
"name": "I don't like waiting", "crf": 20
"cpuUsed": 4, }]
"deadline": 100, }, {
"minrate": 90, "name": "I want it, NOW!",
"crfMap": [{ "cpuUsed": 4,
"resolution": 240, "deadline": "realtime",
"crf": 45 "bitrateError": 60,
}, "crfMap": [{
{ "resolution": 240,
"resolution": 360, "crf": 40
"crf": 42 }, {
}, "resolution": 360,
{ "crf": 35
"resolution": 480, }, {
"crf": 40 "resolution": 480,
}, "crf": 30
{ }, {
"resolution": 720, "resolution": 720,
"crf": 35 "crf": 25
}, }, {
{ "resolution": 1080,
"resolution": 1080, "crf": 20
"crf": 30 }, {
}, "resolution": 1440,
{ "crf": 15
"resolution": 1440, }, {
"crf": 25 "resolution": 2160,
}, "crf": 10
{ }]
"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
}
]
}
]
} }
` `
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {