-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (49 loc) · 1.43 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
import http from 'http'
import path from 'path'
import { spawn } from 'child_process'
import express from 'express'
import { Server as SocketIO } from 'socket.io'
const app = express();
const server = http.createServer(app);
const io = new SocketIO(server)
const options = [
'-i',
'-',
'-c:v', 'libx264',
'-preset', 'ultrafast',
'-tune', 'zerolatency',
'-r', `${25}`,
'-g', `${25 * 2}`,
'-keyint_min', 25,
'-crf', '25',
'-pix_fmt', 'yuv420p',
'-sc_threshold', '0',
'-profile:v', 'main',
'-level', '3.1',
'-c:a', 'aac',
'-b:a', '128k',
'-ar', 128000 / 4,
'-f', 'flv',
`rtmp://a.rtmp.youtube.com/live2/mjvg-hkxu-40a4-zskz-9fz0`,
];
const ffmpegProcess = spawn('ffmpeg', options);
ffmpegProcess.stdout.on('data', (data) => {
console.log(`ffmpeg stdout: ${data}`);
});
ffmpegProcess.stderr.on('data', (data) => {
console.error(`ffmpeg stderr: ${data}`);
});
ffmpegProcess.on('close', (code) => {
console.log(`ffmpeg process exited with code ${code}`);
});
app.use(express.static(path.resolve('./public')))
io.on('connection', socket => {
console.log('Socket Connected', socket.id);
socket.on('binarystream', stream => {
console.log('Binary Stream Incommming...')
ffmpegProcess.stdin.write(stream, (err) => {
console.log('Erhhhr', err)
})
})
})
server.listen(3000, () => console.log(`HTTP Server is runnning on PORT 3000`))