Hi,
I have my node app which works locally perfect, but gives me a SIGKILL error the moment it gets deployed (or the moment I try to access the hls file).
It should take the RTMP stream convert it to hls and keep only 2 files at the same time.
I noticed that even though I ask FFMPG to remove older files, it allways keep the last ones till they get overwritten in on the next launch.
I use a function to remove all files just bc ffmpeg doesn’t seem to have a way to remove all segments on start so this was the best way to make sure that the total file size wouldn’t be an issue. (± 9MB in total now).
The last function was added so I could get open the stream through an hls player.
Feel free to add some examples cuz I’m pretty new to backend development, deploying a site and FFMPEG.
import http from "http";
import fs from "fs";
import path from "path";
import ffmpegStatic from "ffmpeg-static";
import ffmpeg from "fluent-ffmpeg";
const camport = 8900;
ffmpeg.setFfmpegPath(ffmpegStatic);
ffmpeg()
.input('rtmp://working link replaced with this for the post')
.saveToFile('videos/index.m3u8')
.outputOptions(['-g 2', '-hls_delete_threshold 1', '-hls_time 2', '-hls_list_size 1', '-hls_flags delete_segments'])
.on('error', (error) => {
console.log(error);
});
const directory = "videos";
fs.readdir(directory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(directory, file), (err) => {
if (err) throw err;
});
}
});
http.createServer(function (req, res) {
var filePath = '.' + req.url;
fs.readFile(filePath, function (err, content) {
if (err) {
if (err.code == 'ENOENT') {
fs.readFile('./404.hmtl', function (err, content) {
res.end(content, 'utf-8');
})
}
else {
res.end('Sorry, check with the site admin for error: ' + err.code + ' ..\n');
res.end();
}
}
else {
res.end(content, 'utf-8');
}
})
}).listen(camport);