Skip to content

Commit

Permalink
Merge pull request #81 from sjdaws/worker-hw-transcode
Browse files Browse the repository at this point in the history
Worker hw transcode
  • Loading branch information
pabloromeo authored Sep 30, 2021
2 parents 8abcda6 + f5a1f26 commit 2177f31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ The image extends the [LinuxServer Plex](https://hub.docker.com/r/linuxserver/pl

| Parameter | Function |
| :----: | --- |
| `FFMPEG_HWACCEL` | Allows a [hwaccel decoder](https://trac.ffmpeg.org/wiki/HWAccelIntro) to be passed to ffmpeg such as `nvdec` or `dvxa2` |
| `LISTENING_PORT` | Port where workers expose the internal healthcheck |
| `STAT_CPU_INTERVAL` | Frequency at which the worker sends stats to the orchestrator (in ms). Default 2000 |
| `ORCHESTRATOR_URL` | The url where the orchestrator service can be reached (ex: http://plex-orchestrator:3500) |
Expand Down
12 changes: 12 additions & 0 deletions worker/app/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const STAT_CPU_OPS_DURATION = process.env.STAT_CPU_OPS_DURATION || 1000
const ORCHESTRATOR_URL = process.env.ORCHESTRATOR_URL || 'http://localhost:3500'
const TRANSCODER_PATH = process.env.TRANSCODER_PATH || '/usr/lib/plexmediaserver/'
const TRANSCODER_NAME = process.env.TRANSCODER_NAME || 'Plex Transcoder'
// hwaccel decoder: https://trac.ffmpeg.org/wiki/HWAccelIntro
const FFMPEG_HWACCEL = process.env.FFMPEG_HWACCEL || false

var app = require('express')();
var server = require('http').createServer(app);
Expand Down Expand Up @@ -83,6 +85,16 @@ socket.on('worker.task.request', taskRequest => {
console.log('Starting test of waiting for 5 seconds')
child = exec('sleep 5');
} else {
if (FFMPEG_HWACCEL != false) {
console.log(`Setting hwaccel to ${FFMPEG_HWACCEL}`)
let i = taskRequest.payload.args.indexOf('-hwaccel')
if (i > 0) {
taskRequest.payload.args[i+1] = FFMPEG_HWACCEL
} else {
taskRequest.payload.args.unshift('-hwaccel', FFMPEG_HWACCEL)
}
}

child = spawn(TRANSCODER_PATH + TRANSCODER_NAME, taskRequest.payload.args, {
cwd: taskRequest.payload.cwd,
env: processedEnvironmentVariables
Expand Down

0 comments on commit 2177f31

Please sign in to comment.