-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.js
60 lines (51 loc) · 1.26 KB
/
main.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
import express from 'express'
import { spawn } from 'child_process'
import 'dotenv/config';
const server = express()
const streamkey = process.env.streamkey
const video = "hajilok.mov"
const audio = "https://stream.zeno.fm/ez4m4918n98uv";
const ffmpegCommand = [
'ffmpeg',
'-stream_loop', '-1',
'-re',
'-i', video,
'-stream_loop', '-1',
'-re',
'-i', audio,
'-vcodec', 'libx264',
'-pix_fmt', 'yuvj420p',
'-maxrate', '2048k',
'-preset', 'ultrafast',
'-r', '12',
'-framerate', '1',
'-g', '50',
'-crf', '51',
'-c:a', 'aac',
'-b:a', '128k',
'-ar', '44100',
'-strict', 'experimental',
'-video_track_timescale', '100',
'-b:v', '1500k',
'-f', 'flv',
`rtmp://a.rtmp.youtube.com/live2/${streamkey}`,
];
const child = spawn(ffmpegCommand[0], ffmpegCommand.slice(1));
child.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
child.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
child.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
child.on('error', (err) => {
console.error(`Child process error: ${err}`);
});
server.use('/', (req, res) => {
res.send('Your Live Streaming Is All Ready Live')
})
server.listen(3000, () => {
console.log('live stream is ready')
})