fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.85k stars 874 forks source link

Crash when setting ffmpeg path after successfully converting #1285

Open gsproston opened 3 months ago

gsproston commented 3 months ago

I'm seeing a program crash when converting with an invalid ffmpeg path after successfully converting a video with a valid path.

Version information

Code to reproduce

var ffmpeg = require("fluent-ffmpeg");

const INPUT_PATH = "./input/SampleVideo_1280x720_1mb.mkv";
const OUTPUT_PATH = "./output/test.mp4";

// start by converting with a valid FFMPEG path
ffmpeg(INPUT_PATH)
  .output(OUTPUT_PATH)
  .on("start", function (cmdline) {
    console.log("Command line: " + cmdline);
  })
  .on("error", function (err, stdout, stderr) {
    console.log("An error happened: " + err.message);
    console.log("ffmpeg standard output:\n" + stdout);
    console.log("ffmpeg standard error:\n" + stderr);
  })
  .on("end", function () {
    console.log("Finished processing");

    // once the conversion has finished with the valid path
    // start converting with an invalid path
    ffmpeg(INPUT_PATH)
      .setFfmpegPath("bad-path")
      .output(OUTPUT_PATH)
      .on("start", function (cmdline) {
        console.log("Command line: " + cmdline);
      })
      .on("error", function (err, stdout, stderr) {
        console.log("An error happened: " + err.message);
        console.log("ffmpeg standard output:\n" + stdout);
        console.log("ffmpeg standard error:\n" + stderr);
      })
      .on("end", function () {
        console.log("Finished processing");
      })
      .run();
  })
  .run();

Expected results

I expect the conversion to fail, but to fail gracefully by calling the error callback and for the above code to then log the error.

Observed results

Instead the entire program crashes when the error occurs. I don't see the logged out error as expected. I instead see the following:

Exception has occurred: TypeError: Cannot read properties of undefined (reading 'get')
  at endCB (A:\Germingi\Documents\programming\test\fluent-ffmpeg-bug\node_modules\fluent-ffmpeg\lib\processor.js:543:37)
    at ChildProcess.<anonymous> (A:\Germingi\Documents\programming\test\fluent-ffmpeg-bug\node_modules\fluent-ffmpeg\lib\processor.js:157:9)
    at ChildProcess.emit (node:events:520:28)
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

and the error message in the endCB function is "spawn bad-path ENOENT", which is expected.

From looking at the code, it might be necessary to clear the cache in capabilities.js when the ffmpeg path is changed.

Checklist