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
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)

View file

@ -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 {

View file

@ -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,
"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",
"minrate": 75,
"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",
"minrate":75,
"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,
"minrate": 90,
"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",
"minrate": 50,
"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) => {