diff --git a/lib/audioconv.js b/lib/audioconv.js index 3bd7776..c57bbdf 100644 --- a/lib/audioconv.js +++ b/lib/audioconv.js @@ -34,7 +34,7 @@ const childProcess = require('node:child_process'); const ffmpeg = require('fluent-ffmpeg'); // Promisify the `exec` function -const exec = promisify(childProcess.exec); +const spawn = promisify(childProcess.exec); const { logger: log } = require('./utils'); @@ -150,6 +150,13 @@ function resolveOptions(options, useDefault=true) { async function checkFfmpeg(verbose=false) { verbose && log.debug('Checking `ffmpeg` binary...'); if (process.env.FFMPEG_PATH) { + if ((await fs.promises.stat(process.env.FFMPEG_PATH)).isDirectory()) { + const msg = '[EISDIR] Please set the FFMPEG_PATH environment variable ' + + 'to the path of the `ffmpeg` binary'; + verbose && log.warn(msg); + throw new Error(msg); + } + verbose && log.debug('`ffmpeg` installed on system'); return true; } @@ -157,8 +164,8 @@ async function checkFfmpeg(verbose=false) { // This try-catch block to handle error, // in case the `ffmpeg` binary is not installed on system try { - const { stdout, stderr } = await exec('ffmpeg -version'); - if (!stderr && stdout) { + const { status } = await spawn('ffmpeg -version', { shell: true }); + if (status !== 0) { verbose && log.debug('`ffmpeg` installed on system'); return true; }