From 044975b37611131445e0532fed74271aad52987a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Calvar?= Date: Sat, 13 May 2023 14:12:15 +0200 Subject: [PATCH] set bitrate to input if lower than target bitrate --- src/main.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9af8bc0..e1246b2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -165,11 +165,15 @@ function buildInitOptions() { } async function vodBuilder(params: EncoderOptionsBuilderParams) : Promise { - const { resolution, fps, streamNum } = params + const { resolution, fps, streamNum, inputBitrate } = params const streamSuffix = streamNum == undefined ? '' : `:${streamNum}` - const targetBitrate = getTargetBitrate(resolution, fps) + let targetBitrate = getTargetBitrate(resolution, fps) let shouldInitVaapi = (streamNum == undefined || streamNum <= latestStreamNum) + if (targetBitrate > inputBitrate) { + targetBitrate = inputBitrate + } + logger.info(`Building encoder options, received ${JSON.stringify(params)}`) if (shouldInitVaapi && streamNum != undefined) { @@ -194,11 +198,15 @@ async function vodBuilder(params: EncoderOptionsBuilderParams) : Promise { - const { resolution, fps, streamNum } = params + const { resolution, fps, streamNum, inputBitrate } = params const streamSuffix = streamNum == undefined ? '' : `:${streamNum}` - const targetBitrate = getTargetBitrate(resolution, fps) + let targetBitrate = getTargetBitrate(resolution, fps) let shouldInitVaapi = (streamNum == undefined || streamNum <= latestStreamNum) + if (targetBitrate > inputBitrate) { + targetBitrate = inputBitrate + } + logger.info(`Building encoder options, received ${JSON.stringify(params)}`) if (shouldInitVaapi && streamNum != undefined) {