added max audio bitrate limit
This commit is contained in:
parent
8daf8d07d7
commit
c8c32d8126
1 changed files with 12 additions and 3 deletions
|
@ -51,10 +51,17 @@ class Encoder {
|
|||
async #constructVideoCommand(path, out) {
|
||||
let [duration, resolutionHeight] = await this.#getDurationAndResolution(path)
|
||||
|
||||
//Calculates video bitrate to fit right under 8mb 2:6 audio:video. 8Mb * 8 = 64000 - 1000 for overhead, *0.97 to leave space for container.
|
||||
const audioBitRate = Math.round((63000 / 8 * 2 / duration) * 0.97)
|
||||
const videoBitRate = Math.round((63000 / 8 * 6 / duration) * 0.97)
|
||||
//Calculates video bitrate to fit right under 8mb 1:7 audio:video. 8Mb * 8 = 64000(8mb) - 1000 for overhead, *0.97 to leave space for container.
|
||||
const maxOpusBitrate = 256 //kbits
|
||||
|
||||
let audioBitRate = Math.round((62000 / 8 * 1 / duration) * 0.97)
|
||||
let videoBitRate = Math.round((62000 / 8 * 7 / duration) * 0.97)
|
||||
|
||||
//if maxOpusBitrate reached, cap the audio bit rate and give the rest of the bits to video
|
||||
if (audioBitRate > maxOpusBitrate) {
|
||||
videoBitRate += audioBitRate - maxOpusBitrate
|
||||
audioBitRate = maxOpusBitrate
|
||||
}
|
||||
//if command had argument of anotehr quality setting change to use that setting
|
||||
if (this.encodePresetIndexArg) {
|
||||
this.currentSetting = this.settings.presets[this.encodePresetIndexArg]
|
||||
|
@ -89,6 +96,7 @@ class Encoder {
|
|||
command += `-qmax 60 `
|
||||
command += `-g 240 `
|
||||
command += `-row-mt 1 "${out}.webm" `
|
||||
console.log(command)
|
||||
return [command, duration, false]
|
||||
}
|
||||
|
||||
|
@ -124,6 +132,7 @@ class Encoder {
|
|||
command += `-g 240 `
|
||||
|
||||
command += `-row-mt 1 -pass 2 "${out}.webm" `
|
||||
console.log(command)
|
||||
return [command, duration, isTwoPass]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue