add hevc vod and live builders

This commit is contained in:
matty 2024-04-14 15:31:21 -04:00
parent 2168bc72d0
commit 5e809bc053

136
dist/main.js vendored
View File

@ -32,11 +32,16 @@ async function register({ settingsManager, peertubeHelpers, transcodingManager:
transcodingManager = transcode;
logger.info("Registering peertube-plugin-nctv-hardware-encode");
const encoder = 'h264_nvenc';
const hevc = 'hevc_nvenc';
const profileName = 'nctv-nvenc';
transcodingManager.addVODProfile(encoder, profileName, vodBuilder);
transcodingManager.addVODEncoderPriority('video', encoder, 1000);
transcodingManager.addLiveProfile(encoder, profileName, liveBuilder);
transcodingManager.addLiveEncoderPriority('video', encoder, 1000);
transcodingManager.addVODProfile(hevc, profileName, hevcVODBuilder);
transcodingManager.addVODEncoderPriority('video', encoder, 1000);
transcodingManager.addLiveProfile(hevc, profileName, hevcLiveBuilder);
transcodingManager.addLiveEncoderPriority('video', encoder, 1000);
await loadSettings(settingsManager);
registerSetting({
name: 'hardware-decode',
@ -172,6 +177,9 @@ function buildInitOptions() {
];
}
}
//H264_NVENC VOD BUILDER
async function vodBuilder(params) {
const { resolution, fps, streamNum, inputBitrate } = params;
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
@ -185,10 +193,7 @@ async function vodBuilder(params) {
if (shouldInitVaapi && streamNum != undefined) {
latestStreamNum = streamNum;
}
let options = {};
if (pluginSettings.hevcEnabled) {
options = {
let options = {
scaleFilter: {
name: 'scale'
},
@ -196,39 +201,86 @@ async function vodBuilder(params) {
outputOptions: [
`-preset ${pluginSettings.vodQuality}`,
`-b:v${streamSuffix} ${targetBitrate}`,
//`-b:v${streamSuffix} 0`,
`-bufsize ${targetBitrate * 2}`,
`-profile:v${streamSuffix} ${pluginSettings.hevcProfile}`,
//`-cq 25`,
//`-rc vbr`,
`-c:v${streamSuffix} hevc_nvenc`,
//`-bf 4`
]
};
} else {
options = {
scaleFilter: {
name: 'scale'
},
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
outputOptions: [
`-preset ${pluginSettings.vodQuality}`,
`-b:v${streamSuffix} ${targetBitrate}`,
//`-b:v${streamSuffix} 0`,
`-bufsize ${targetBitrate * 2}`,
`-profile:v${streamSuffix} high`,
`-cq 25`,
//`-rc vbr`,
//`-c:v${streamSuffix} h264_nvenc`,
`-bf 4`
]
};
}
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
return options;
}
//HEVC VOD builder
async function hevcVODBuilder(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)}, HEVC: ${pluginSettings.hevcEnabled}`);
if (shouldInitVaapi && streamNum != undefined) {
latestStreamNum = streamNum;
}
let options = {
scaleFilter: {
name: 'scale'
},
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
outputOptions: [
`-preset ${pluginSettings.vodQuality}`,
`-b:v${streamSuffix} ${targetBitrate}`,
`-bufsize ${targetBitrate * 2}`,
`-profile:v${streamSuffix} ${pluginSettings.hevcProfile}`,
]
};
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
return options;
}
//HEVC Live builder
async function hevcLiveBuilder(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)}, HEVC: ${pluginSettings.hevcEnabled}`);
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.hevcProfile}`,
`-g:v${streamSuffix} ${fps * 2}`,
`-b:v${streamSuffix} ${targetBitrate}`,
`-bufsize ${targetBitrate * 2}`
]
};
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
return options;
}
//H264 Live builder
async function liveBuilder(params) {
const { resolution, fps, streamNum, inputBitrate } = params;
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
@ -243,31 +295,7 @@ async function liveBuilder(params) {
latestStreamNum = streamNum;
}
let options = {};
if (pluginSettings.hevcEnabled) {
options = {
scaleFilter: {
name: 'scale'
},
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
outputOptions: [
`-tune ${pluginSettings.liveQuality}`,
`-r:v${streamSuffix} ${fps}`,
`-profile:v${streamSuffix} ${pluginSettings.hevcProfile}`,
`-c:v${streamSuffix} hevc_nvenc`,
//`-cq 25`,
`-g:v${streamSuffix} ${fps * 2}`,
`-b:v${streamSuffix} ${targetBitrate}`,
//`-b:v${streamSuffix} 0`,
`-bufsize ${targetBitrate * 2}`,
//`-rc vbr`,
// `-bf 4`
]
};
} else {
options = {
let options = {
scaleFilter: {
name: 'scale'
},
@ -280,12 +308,10 @@ async function liveBuilder(params) {
`-g:v${streamSuffix} ${fps * 2}`,
`-b:v${streamSuffix} ${targetBitrate}`,
`-bufsize ${targetBitrate * 2}`,
//`-rc vbr`,
`-bf 4`
]
};
}
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
return options;
}