From 70b62037d6997365daed876e30a34dff721df1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Calvar?= Date: Mon, 5 Apr 2021 11:27:23 +0200 Subject: [PATCH] only apply vaapi init parameter when needed --- README.md | 8 ++++++++ main.js | 32 ++++++++++++++++++++------------ package.json | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d23dff9 --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/main.js b/main.js index f72b6b2..1de633c 100644 --- a/main.js +++ b/main.js @@ -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; } diff --git a/package.json b/package.json index cbb601b..9e6f510 100644 --- a/package.json +++ b/package.json @@ -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"