Search code examples
node.jsfluent-ffmpeg

Correct way to catch an error with fluent ffmpeg


I'm using Fluent FFMpeg in my NodeJS application and I'm trying to add some error handling in the event an input doesn't exist. At the moment it's just crashing out with this message:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ffmpeg exited with code 1: http://localhost:9001: Connection refused

When an input source doesn't exist I want to wait some time (say 1 second) and try again. This is currently my code:

var command = FFmpeg("http://localhost:9001")
  // set options here
;

var stream = command.pipe();
stream.on('data', function(chunk) {
  // do something with the data
});

How do correctly cater to an error when the input doesn't (yet) exist?


Solution

  • you can get the error infomation in the "error" handler like:

    stream.on('error', function(err, stdout, stderr) {
      console.log("ffmpeg stdout:\n" + stdout);
      console.log("ffmpeg stderr:\n" + stderr);
    })