FFMPEG SIGKILL with Node.js

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);

Services receive a SIGKILL when they overrun their memory allocation. You likely have multiple Gigabytes of memory on your local system, and not on Render.

When I looked it up I also thought it could become the issue, which is why I keep only 2 segments of 2 seconds but it doesn’t even save a single file before crashing.
The following 2 parts should prevent me from running out of memory.

  • ‘-hls_flags delete_segments’ deletes the already existing segments
  • “fs.readdir(directory, (err, files) => {” the code inside here deletes the whole folder of recorded files on startup (so the files that get left behind when closing the app)
    My project is only ± 50MB itself.

Or do you mean that executing the FFMPEG command itself (so not the files that would get saved) is using up too much memory?
If so, is it even possible using FFMPEG on the free instance of render?

Thank you for the feedback

I looks like ffmpeg-fluent can’t be run on a free instance of render since only running the FFMPEG part of the code still causes the sigkill error to appear. I also got for the first time an out of memory error which I think confirms that it’s the ram memory problem. (before I only got the sigkill, now I got both)
image

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.