This repository has been archived by the owner on Jun 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstream.js
59 lines (52 loc) · 1.6 KB
/
stream.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
// Requirements
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpeg = require("fluent-ffmpeg");
const fs = require("fs");
const axios = require("axios");
ffmpeg.setFfmpegPath(ffmpegPath);
let command;
var started = false;
const GetIngest = async () => {
const res = await axios.get("https://ingest.twitch.tv/ingests");
return res.data.ingests[0].url_template.replace("{stream_key}", process.env.STREAM_KEY);
}
module.exports.Start = async () => {
started = true;
console.log("Started streaming!");
let ingest;
if (!process.env.INGEST)
ingest = await GetIngest();
else
ingest = process.env.INGEST;
command = ffmpeg()
.addInput("./assets/bkg.gif")
.addInputOption("-ignore_loop 0")
.videoFilters({
filter: 'drawtext',
options: {
fontfile: './assets/font.ttf',
textfile: "./assets/livetext.txt",
fontsize: 40,
fontcolor: 'white',
x: '(w-tw)/2',
y: '(main_h-60)',
reload: 1,
shadowcolor: 'black',
shadowx: 2,
shadowy: 2,
}
})
.addInput("http://hyades.shoutca.st:8043/stream")
.size(process.env.VIDEO_SIZE)
.videoBitrate(process.env.BITRATE)
.withAspect('16:9')
.videoCodec('libx264')
.audioCodec('aac')
.toFormat('flv')
.save(ingest);
}
module.exports.Stop = async () => {
command.ffmpegProc.stdin.write('q');
started = false;
}
module.exports.Started = started;