-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
ffmpeg.js
55 lines (48 loc) · 1.55 KB
/
ffmpeg.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
const ffbinaries = require("ffbinaries");
const fe = require("path");
const ffmpeg = require("fluent-ffmpeg");
exports.setup = function (mstream, program) {
var dest = fe.join(__dirname, "ffmpeg");
var platform = ffbinaries.detectPlatform();
ffbinaries.downloadFiles(
["ffmpeg", "ffprobe"],
{ platform: platform, quiet: true, destination: dest },
function (err, data) {
console.log("Downloading ffmpeg binary for win-64 to " + dest + ".");
console.log("err", err);
console.log("data", data);
var ffmpegPath = fe.join(
dest,
ffbinaries.getBinaryFilename("ffmpeg", platform)
);
var ffprobePath = fe.join(
dest,
ffbinaries.getBinaryFilename("ffprobe", platform)
);
console.log(ffmpegPath);
console.log(ffprobePath);
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);
mstream.get("/transcode/*", function (req, res) {
let pathInfo = program.getVPathInfo(req.params[0]);
if (pathInfo === false) {
res.json({ "success": false });
return;
}
ffmpeg(pathInfo.fullPath)
.noVideo()
.format('mp3')
.audioBitrate('128k')
.on('end', function () {
console.log('file has been converted succesfully');
})
.on('error', function (err) {
console.log(err)
console.log('an error happened: ' + err.message);
})
// save to stream
.pipe(res, { end: true });
});
}
);
};