only apply vaapi init parameter when needed

This commit is contained in:
Théo Le Calvar 2021-04-05 11:27:23 +02:00
parent 777803c6c9
commit 70b62037d6
3 changed files with 29 additions and 13 deletions

8
README.md Normal file
View File

@ -0,0 +1,8 @@
# Hardware h264 encoding using vaapi
TODO
See these to setup vaapi:
- https://jellyfin.org/docs/general/administration/hardware-acceleration.html#enabling-hardware-acceleration
- https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Comparison_tables

32
main.js
View File

@ -4,23 +4,30 @@ async function register ({
}) {
const { logger } = peertubeHelpers
const initVaapiOptions = [
// enable hardware acceleration
'-hwaccel vaapi',
'-hwaccel_output_format vaapi',
'-vaapi_device /dev/dri/renderD128'
]
let latestStreamNum = 9999
// Add hardware encode through vaapi
{
const VODBuilder = (options) => {
const { input, resolution, fps, streamNum } = options
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`
const targetBitrate = getTargetBitrate(resolution, fps)
let shouldInitVaapi = (streamNum == undefined || streamNum <= latestStreamNum)
if (shouldInitVaapi && streamNum != undefined) {
latestStreamNum = streamNum
}
// You can also return a promise
return {
videoFilters: [
],
inputOptions: [
// enable hardware acceleration
'-hwaccel vaapi',
'-hwaccel_output_format vaapi',
'-vaapi_device /dev/dri/renderD128'
],
inputOptions: shouldInitVaapi ? initVaapiOptions : [],
outputOptions: [
'-bf 8', // override hardcoded bf value which cause memory error
'-pix_fmt vaapi_vld',
@ -36,17 +43,17 @@ async function register ({
const { input, resolution, fps, streamNum } = options
const streamSuffix = streamNum == undefined ? '' : `:${streamNum}`
const targetBitrate = getTargetBitrate(resolution, fps)
let shouldInitVaapi = (streamNum == undefined || streamNum <= latestStreamNum)
if (shouldInitVaapi && streamNum != undefined) {
latestStreamNum = streamNum
}
// You can also return a promise
return {
videoFilters: [
],
inputOptions: [
// enable hardware acceleration
'-hwaccel vaapi',
'-hwaccel_output_format vaapi',
'-vaapi_device /dev/dri/renderD128'
],
inputOptions: shouldInitVaapi ? initVaapiOptions : [],
outputOptions: [
'-bf 8', // override hardcoded bf value which cause memory error
'-pix_fmt vaapi_vld',
@ -76,6 +83,7 @@ async function register ({
}
async function unregister() {
transcodingManager.removeAllProfilesAndEncoderPriorities()
return true;
}

View File

@ -1,6 +1,6 @@
{
"name": "peertube-plugin-hardware-transcode-vaapi",
"version": "0.0.1",
"version": "0.0.3",
"description": "Plugin add transcode profils which use vaapi for hardware acceleration",
"engine": {
"peertube": ">=3.1.0"