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"