Skip to content

Commit c03f626

Browse files
authored
UnicornFFMPEG 2.0.0
2 parents e6edeee + a053109 commit c03f626

File tree

5 files changed

+39
-104
lines changed

5 files changed

+39
-104
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
node_modules/
33
npm-debug.log
4+
package-lock.json
45
bin/

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## UnicornFFMPEG
22

3-
This software is a part of __UnicornTranscoder__ project, it's a binary to replace the official __Plex Transcoder__, the binary will save parameters in your Redis database, the data will be used by __UnicornTranscoder__.
3+
This software is a part of __UnicornTranscoder__ project, it's a binary to replace the official __Plex Transcoder__, the binary will send parameters to __UnicornLoadBalancer__.
44

55
## UnicornTranscoder Project
66

@@ -9,13 +9,11 @@ This software is a part of __UnicornTranscoder__ project, it's a binary to repla
99
* [UnicornFFMPEG](https://github.com/UnicornTranscoder/UnicornFFMPEG)
1010

1111
## Dependencies
12-
* Redis Server with [Keyspace Notifications](https://redis.io/topics/notifications) enabled
1312
* Plex Media Server
1413

1514
## Installation
1615
* Clone this repository
1716
* Run `npm i`
18-
* Set your Redis configuration in `config.js`, and change Plex paths if it's necessary
19-
* __Note:__ The redis configuration should be the same as the one of UnicornTranscoder
17+
* Set your load-balancer url in `config.js`
2018
* Build the binary with `npm start`
21-
* Replace the Plex binary called `Plex Transcoder` by the generated binary store in `bin`, choose the correct version (depend of your OS)
19+
* Replace the Plex binary called `Plex Transcoder` by the generated binary store in `bin`, choose the correct version (depending on your OS)

app.js

+25-78
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,32 @@
1-
// Get dependencies
2-
const redis = require('redis');
1+
// Import fetch
2+
const fetch = require('node-fetch');
33

4-
// Get configuration
4+
// Import our config
55
const config = require('./config');
66

7-
// Env
7+
// Get env
88
const env = process.env;
99

10-
// Args
11-
const args = process.argv.slice(2);
12-
13-
// Get and check session
14-
let sessionid = false;
15-
const regex = /^http\:\/\/127.0.0.1:32400\/video\/:\/transcode\/session\/(.*)\/progress$/;
16-
for (idx in args) {
17-
if (regex.test(args[idx])) {
18-
sessionid = args[idx].match(regex)[1];
19-
break;
20-
}
21-
}
22-
if (sessionid === false) {
23-
console.error('Failed to find session id');
24-
process.exit(1);
25-
}
26-
const propersessionid = sessionid.split('/')[0];
27-
console.log('Session found: ' + sessionid + ' (' + propersessionid + ')');
28-
29-
// Parse arguments
30-
const parsedargs = args.map((o) => {
31-
if (o.indexOf('/progress') !== -1)
32-
o = o.replace(config.plex.plex_url, '{PROGRESSURL}/');
33-
return o.replace(config.plex.plex_url, '{URL}/')
34-
.replace(config.plex.plex_sessions, '{SRTSRV}/')
35-
.replace(config.plex.plex_usr, '{USRPLEX}/')
36-
.replace(config.plex.plex_mount, '{PATH}/')
37-
});
38-
39-
// Replace seglist
40-
const segList = '{SEGURL}/video/:/transcode/session/' + sessionid + '/seglist';
41-
var forceSegList = false;
42-
var finalargs = [];
43-
for (var i = 0; i < parsedargs.length; i++) {
44-
if (parsedargs[i] == '-segment_list') {
45-
forceSegList = true;
46-
finalargs.push(parsedargs[i]);
47-
}
48-
else if (forceSegList) {
49-
finalargs.push(segList);
50-
if (parsedargs[i + 1] !== '-segment_list_type') {
51-
finalargs.push('-segment_list_type');
52-
finalargs.push('csv');
53-
finalargs.push('-segment_list_size');
54-
finalargs.push('2147483647');
55-
}
56-
forceSegList = false;
57-
}
58-
else
59-
finalargs.push(parsedargs[i]);
60-
}
61-
62-
// Create Redis instance
63-
let redisClient = redis.createClient({
64-
host: config.redis.redis_host,
65-
port: config.redis.redis_port,
66-
password: config.redis.redis_pass,
67-
db: config.redis.redis_db
68-
});
69-
70-
// On Redis error
71-
redisClient.on('error', (err) => {
72-
if (err.errno === 'ECONNREFUSED') {
73-
console.error('Failed to connect to REDIS, please check your configuration');
74-
}
75-
else {
76-
console.error(err.errno);
77-
}
78-
process.exit(1);
10+
// Get args
11+
const arg = process.argv.slice(2);
12+
13+
// Call the load-balancer
14+
fetch(`${config.URL}api/ffmpeg`, {
15+
method: 'POST',
16+
headers: {
17+
'Accept': 'application/json',
18+
'Content-Type': 'application/json'
19+
},
20+
body: JSON.stringify({
21+
arg,
22+
env
23+
})
24+
}).catch((err) => {
25+
console.error(err);
7926
});
8027

81-
// Send to redis
82-
redisClient.set(propersessionid, JSON.stringify({
83-
args: finalargs,
84-
env
85-
}));
28+
/**
29+
* We need to keep alive the process otherwise
30+
* plex send a bad mpd file
31+
**/
32+
setInterval(() => {}, 3600000);

config.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1+
// URL of the load-balancer with last '/'
12
module.exports = {
2-
redis: {
3-
redis_host: '127.0.0.1',
4-
redis_port: 6379,
5-
redis_pass: '',
6-
redis_db: 0
7-
},
8-
plex: {
9-
plex_url: 'http://127.0.0.1:32400/',
10-
plex_sessions: '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode/Sessions/',
11-
plex_usr: '/usr/lib/plexmediaserver/',
12-
plex_mount: '/mnt/acd/'
13-
}
14-
};
3+
URL: 'http://127.0.0.1:3001/'
4+
};

package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
{
22
"name": "unicorn-ffmpeg",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Fake FFMPEG binary to extract arguments",
55
"bin": "app.js",
66
"scripts": {
77
"start": "pkg . -o \"bin/Plex Transcoder\""
88
},
99
"author": "Maxime BACONNAIS",
10-
"license": "ISC",
10+
"license": "MIT",
1111
"dependencies": {
12-
"redis": "^2.7.1"
12+
"node-fetch": "^2.3.0"
1313
},
1414
"devDependencies": {
15-
"pkg": "4.2.2"
15+
"pkg": "^4.3.7"
1616
},
1717
"pkg": {
1818
"targets": [
19-
"freebsd",
20-
"linux",
21-
"macos",
22-
"win"
19+
"linux-node10",
20+
"macos-node10",
21+
"win-node10"
2322
]
2423
}
2524
}

0 commit comments

Comments
 (0)