-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
31 lines (28 loc) · 858 Bytes
/
server.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
const ffmpeg = require('fluent-ffmpeg');
const fs = require('fs');
const express = require('express');
var app = express();
app.get("/mkv", (req, res) => {
var videoPath = req.query.path;
try {
if (fs.existsSync(videoPath)) {
var stream = fs.createReadStream(videoPath);
ffmpeg()
.input(stream)
.outputOptions('-movflags frag_keyframe+empty_moov')
.outputFormat('mp4')
.on('error', ignored => {})
.audioCodec('aac')
.videoCodec('libx264')
.pipe(res)
res.on('close', () => {
stream.destroy()
})
} else {
res.status(404).send();
}
} catch (err) {
console.log("Error, unknown file -> " + videoPath);
}
})
app.listen(8080);