-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
66 lines (51 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const fs = require('fs');
const express = require('express');
const app = express();
const port = 8080;
let devHack = false; // enable hacks for running faster on dev station
let threads = 0; // auto
// Uncomment this during testing only
//devHack = true; threads = 6;
const Encoder = require('./encoder.js');
const config = require('./config.json');
let encoding = false;
let encodingIndex = 0;
let encoder = null;
let currentUrl = null;
let lastEncoder = null;
//app.get('/', (req, res) => res.send('Hello world'));
app.get('/current', (req, res) => {
res.json(currentUrl);
});
app.get('/config', (req, res) => {
res.json(config);
});
app.post('/encode', (req, res) => {
if (encoding) {
res.json(null);
} else {
if (lastEncoder) {
lastEncoder.cleanup();
}
const base = `dash-stream-${encodingIndex}.mpd`;
const main = `output/${base}`;
const url = main;
encoding = true;
currentUrl = url;
encodingIndex++;
let options = {
dest: main,
base: base,
};
encoder = new Encoder(options);
encoder.start().then(() => {
encoding = false;
currentUrl = null;
lastEncoder = encoder;
});
res.json(url);
}
});
app.use(express.static('dist'));
app.use('/output', express.static('output'));
app.listen(port, () => console.log(`AV1 demo running on port ${port}`));