-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (51 loc) · 1.43 KB
/
Copy pathindex.js
File metadata and controls
64 lines (51 loc) · 1.43 KB
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
import http from 'http'
import express from 'express'
import { spawn } from 'child_process';
import {Server as socky } from 'socket.io'
import path from 'path';
const app = express();
app.use(express.json())
app.use(express.urlencoded({extended:true}))
const PORT = 3000
const server = http.createServer(app);
const io = new socky(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/*********`,
];
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('stream',(data)=>{
ffmpegProcess.stdin.write(data, (err) => {
console.log('Err', err)
})
})
})
server.listen(3000 ,()=>{console.log(`server up and running at PORT ${PORT}`)})