From c8c32d812613035d14693a7f43c7dc265fd8a9ce Mon Sep 17 00:00:00 2001 From: Djkato Date: Thu, 9 Jun 2022 14:30:08 +0200 Subject: [PATCH] added max audio bitrate limit --- lib/encoder.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/encoder.js b/lib/encoder.js index 95447c6..ef64663 100644 --- a/lib/encoder.js +++ b/lib/encoder.js @@ -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] }