fluent-ffmpeg/node-fluent-ffmpeg

Crash when setting ffmpeg path after successfully converting

gsproston opened this issue · 0 comments

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

Version information

  • fluent-ffmpeg version: 2.1.3
  • ffmpeg version: 7.0.1-essentials_build-www.gyan.dev
  • OS: Windows 10 Home 22H2

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

  • I have read the FAQ
  • I tried the same with command line ffmpeg and it works correctly (hint: if the problem also happens this way, this is an ffmpeg problem and you're not reporting it to the right place)
  • I have included full stderr/stdout output from ffmpeg