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

View File

@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-hardware-transcode-vaapi", "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", "description": "Plugin add transcode profils which use vaapi for hardware acceleration",
"engine": { "engine": {
"peertube": ">=3.1.0" "peertube": ">=3.1.0"