add hevc vod and live builders
This commit is contained in:
parent
2168bc72d0
commit
5e809bc053
166
dist/main.js
vendored
166
dist/main.js
vendored
@ -32,11 +32,16 @@ async function register({ settingsManager, peertubeHelpers, transcodingManager:
|
|||||||
transcodingManager = transcode;
|
transcodingManager = transcode;
|
||||||
logger.info("Registering peertube-plugin-nctv-hardware-encode");
|
logger.info("Registering peertube-plugin-nctv-hardware-encode");
|
||||||
const encoder = 'h264_nvenc';
|
const encoder = 'h264_nvenc';
|
||||||
|
const hevc = 'hevc_nvenc';
|
||||||
const profileName = 'nctv-nvenc';
|
const profileName = 'nctv-nvenc';
|
||||||
transcodingManager.addVODProfile(encoder, profileName, vodBuilder);
|
transcodingManager.addVODProfile(encoder, profileName, vodBuilder);
|
||||||
transcodingManager.addVODEncoderPriority('video', encoder, 1000);
|
transcodingManager.addVODEncoderPriority('video', encoder, 1000);
|
||||||
transcodingManager.addLiveProfile(encoder, profileName, liveBuilder);
|
transcodingManager.addLiveProfile(encoder, profileName, liveBuilder);
|
||||||
transcodingManager.addLiveEncoderPriority('video', encoder, 1000);
|
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);
|
await loadSettings(settingsManager);
|
||||||
registerSetting({
|
registerSetting({
|
||||||
name: 'hardware-decode',
|
name: 'hardware-decode',
|
||||||
@ -172,6 +177,9 @@ function buildInitOptions() {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//H264_NVENC VOD BUILDER
|
||||||
|
|
||||||
async function vodBuilder(params) {
|
async function vodBuilder(params) {
|
||||||
const { resolution, fps, streamNum, inputBitrate } = params;
|
const { resolution, fps, streamNum, inputBitrate } = params;
|
||||||
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
|
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
|
||||||
@ -185,10 +193,7 @@ async function vodBuilder(params) {
|
|||||||
if (shouldInitVaapi && streamNum != undefined) {
|
if (shouldInitVaapi && streamNum != undefined) {
|
||||||
latestStreamNum = streamNum;
|
latestStreamNum = streamNum;
|
||||||
}
|
}
|
||||||
let options = {};
|
let options = {
|
||||||
if (pluginSettings.hevcEnabled) {
|
|
||||||
|
|
||||||
options = {
|
|
||||||
scaleFilter: {
|
scaleFilter: {
|
||||||
name: 'scale'
|
name: 'scale'
|
||||||
},
|
},
|
||||||
@ -196,39 +201,86 @@ async function vodBuilder(params) {
|
|||||||
outputOptions: [
|
outputOptions: [
|
||||||
`-preset ${pluginSettings.vodQuality}`,
|
`-preset ${pluginSettings.vodQuality}`,
|
||||||
`-b:v${streamSuffix} ${targetBitrate}`,
|
`-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}`,
|
`-bufsize ${targetBitrate * 2}`,
|
||||||
`-profile:v${streamSuffix} high`,
|
`-profile:v${streamSuffix} high`,
|
||||||
`-cq 25`,
|
`-cq 25`,
|
||||||
//`-rc vbr`,
|
|
||||||
//`-c:v${streamSuffix} h264_nvenc`,
|
|
||||||
`-bf 4`
|
`-bf 4`
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
|
||||||
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
|
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
|
||||||
return 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) {
|
async function liveBuilder(params) {
|
||||||
const { resolution, fps, streamNum, inputBitrate } = params;
|
const { resolution, fps, streamNum, inputBitrate } = params;
|
||||||
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
|
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`;
|
||||||
@ -243,49 +295,23 @@ async function liveBuilder(params) {
|
|||||||
latestStreamNum = streamNum;
|
latestStreamNum = streamNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = {};
|
let options = {
|
||||||
|
scaleFilter: {
|
||||||
|
name: 'scale'
|
||||||
|
},
|
||||||
|
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
|
||||||
|
outputOptions: [
|
||||||
|
`-tune ${pluginSettings.liveQuality}`,
|
||||||
|
`-r:v${streamSuffix} ${fps}`,
|
||||||
|
`-profile:v${streamSuffix} high`,
|
||||||
|
`-cq 25`,
|
||||||
|
`-g:v${streamSuffix} ${fps * 2}`,
|
||||||
|
`-b:v${streamSuffix} ${targetBitrate}`,
|
||||||
|
`-bufsize ${targetBitrate * 2}`,
|
||||||
|
`-bf 4`
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
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 = {
|
|
||||||
scaleFilter: {
|
|
||||||
name: 'scale'
|
|
||||||
},
|
|
||||||
inputOptions: shouldInitVaapi ? buildInitOptions() : [],
|
|
||||||
outputOptions: [
|
|
||||||
`-tune ${pluginSettings.liveQuality}`,
|
|
||||||
`-r:v${streamSuffix} ${fps}`,
|
|
||||||
`-profile:v${streamSuffix} high`,
|
|
||||||
`-cq 25`,
|
|
||||||
`-g:v${streamSuffix} ${fps * 2}`,
|
|
||||||
`-b:v${streamSuffix} ${targetBitrate}`,
|
|
||||||
`-bufsize ${targetBitrate * 2}`,
|
|
||||||
//`-rc vbr`,
|
|
||||||
`-bf 4`
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
|
logger.info(`EncoderOptions: ${JSON.stringify(options)}`);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user