-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (32 loc) · 1.12 KB
/
Copy pathindex.js
File metadata and controls
38 lines (32 loc) · 1.12 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
const express = require('express');
const multer = require('multer');
const ffmpeg = require('fluent-ffmpeg');
const path = require('path');
require('dotenv').config();
const app = express();
const upload = multer({ dest: 'uploads/' });
app.use(express.static('public'));
app.use(express.json());
app.post('/start-stream', upload.single('video'), (req, res) => {
const videoPath = req.file.path;
const rtmpUrl = process.env.YOUTUBE_RTMP;
if (!rtmpUrl) {
return res.status(500).json({ error: 'RTMP URL not configured' });
}
ffmpeg(videoPath)
.outputOptions('-f flv')
.output(rtmpUrl)
.on('start', () => {
console.log('Streaming started');
res.status(200).json({ message: 'Streaming started' });
})
.on('error', (err) => {
console.error('Error during streaming:', err.message);
res.status(500).json({ error: 'Streaming failed' });
})
.run();
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});