reorganize builder functions (i am autistic about it)

This commit is contained in:
matty 2024-04-15 20:00:05 -04:00
parent 96ececa3f1
commit a263efb618

73
dist/main.js vendored
View File

@ -244,6 +244,43 @@ async function vodBuilder(params) {
return options;
}
//H264 Live builder
async function liveBuilder(params) {
const { resolution, fps, streamNum, inputBitrate } = params;
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
let targetBitrate = getTargetBitrate(resolution, fps);
// let targetBitrate = inputBitrate;
let shouldInitVaapi = (streamNum == undefined || streamNum <= latestStreamNum);
if (targetBitrate > inputBitrate) {
targetBitrate = inputBitrate;
}
logger.info(`Building encoder options, received ${JSON.stringify(params)}`);
if (shouldInitVaapi && streamNum != undefined) {
latestStreamNum = streamNum;
}
let options = {
scaleFilter: {
name: 'scale'
},
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
outputOptions: [
`-tune ${pluginSettings.liveQuality}`,
`-r:v${streamSuffix} ${fps}`,
`-profile:v${streamSuffix} ${pluginSettings.h264Profile}`,
`-cq ${pluginSettings.cqH264}`,
`-g:v${streamSuffix} ${fps * 2}`,
`-b:v${streamSuffix} ${targetBitrate}`,
`-bufsize ${targetBitrate * 2}`,
`-bf 4`
]
};
logger.info(`EncoderOptions: ${JSON.stringify(options)}, HEVC: false`);
return options;
}
//HEVC VOD builder
async function hevcVODBuilder(params) {
const { resolution, fps, streamNum, inputBitrate } = params;
@ -313,42 +350,6 @@ async function hevcLiveBuilder(params) {
return options;
}
//H264 Live builder
async function liveBuilder(params) {
const { resolution, fps, streamNum, inputBitrate } = params;
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
let targetBitrate = getTargetBitrate(resolution, fps);
// let targetBitrate = inputBitrate;
let shouldInitVaapi = (streamNum == undefined || streamNum <= latestStreamNum);
if (targetBitrate > inputBitrate) {
targetBitrate = inputBitrate;
}
logger.info(`Building encoder options, received ${JSON.stringify(params)}`);
if (shouldInitVaapi && streamNum != undefined) {
latestStreamNum = streamNum;
}
let options = {
scaleFilter: {
name: 'scale'
},
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
outputOptions: [
`-tune ${pluginSettings.liveQuality}`,
`-r:v${streamSuffix} ${fps}`,
`-profile:v${streamSuffix} ${pluginSettings.h264Profile}`,
`-cq ${pluginSettings.cqH264}`,
`-g:v${streamSuffix} ${fps * 2}`,
`-b:v${streamSuffix} ${targetBitrate}`,
`-bufsize ${targetBitrate * 2}`,
`-bf 4`
]
};
logger.info(`EncoderOptions: ${JSON.stringify(options)}, HEVC: false`);
return options;
}
function getTargetBitrate(resolution, fps) {
const baseBitrate = pluginSettings.baseBitrate.get(resolution) || 0;
const maxBitrate = baseBitrate * 1.4;