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