Wai Yan Hein
Wai Yan Hein

Reputation: 14831

'ffmpeg' is not recognized as an internal or external command in nodejs node-ffmpeg

I am developing a Node.js application. First of all, I am just a beginner when it comes to Node.

What I am doing in my application now is that I am trying to create the thumbnail JPEG file for my mp4 file. I have already tried many possible solutions. Now I am using this one - https://github.com/damianociarla/node-ffmpeg. I think this is the potential solution among all. I am getting the error when I generate the JPEG thumbnail of the video file.

Here is what I have done so far. I installed the package running this command

npm install ffmpeg --save

Then I try to generate the thumbnail files like this

var ffmpeg = require('ffmpeg');
module.exports.createVideoThumbnail = function(req, res)
{
    try {
        var process = new ffmpeg('public/lalaland.mp4');
        process.then(function (video) {
            
            video.fnExtractFrameToJPG('public', {
                frame_rate : 1,
                number : 5,
                file_name : 'my_frame_%t_%s'
            }, function (error, files) {
                if (!error)
                    console.log('Frames: ' + files);
                else
                    //This error message is displayed
                    console.log(error)
            });

        }, function (err) {
            console.log('Error: ' + err);
        });
    } catch (e) {
        console.log(e.code);
        console.log(e.msg);
    }
    res.json({ status : true , message: "Video thumbnail created. Hopefully" });
}

When I run the code, it is throwing an error. I commented in the code where the error is thrown from. This is the error message

{ Error: Command failed: ffmpeg -i public/lalaland.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" public/my_frame_1518211962631_0x0_%d.jpg
'ffmpeg' is not recognized as an internal or external command,
operable program or batch file.

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
  killed: false,
  code: 1,
  signal: null,
  cmd: 'ffmpeg -i public/lalaland.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" public/my_frame_1518211962631_0x0_%d.jpg' }

I installed the ffmg as well. You can see below it is an installed command on my laptop

enter image description here

What is missing in my code?

Upvotes: 7

Views: 27937

Answers (4)

Mohit Bhargava
Mohit Bhargava

Reputation: 1

  1. Install ffmpeg via pip:
pip install ffmpeg
  1. Put the ffmpeg downloaded files in the below.
C:\ffmpeg\
  1. Change the system environment variable so that ffmpeg can be recognized.

Alternate option when you don't have option to change system environment variables/when working on other systems.

  1. Place the ffmpeg files in the project folder where you are trying use ffmpeg.
  2. Ensure all ffmpeg files are there.

Upvotes: 0

Jackssn
Jackssn

Reputation: 1624

I have had same problem in Python (Jupyter Notebook)! Trouble was in PATH. My solving for Python3:

  1. Install ffmpeg via pip: pip install ffmpeg
  2. Check path in Jupyter Notebook: echo %path%
  3. In path I looked for dir with name: C:\ffmpeg\bin but this dir didn't exist
  4. Download version in my Windows 10 from official website and unzip archive in directory: C:\ffmpeg\
  5. Then my echo %path% found ffmpeg.exe file and code !ffmpeg ... works well

Upvotes: 1

Adil
Adil

Reputation: 4623

Maybe this can help others, as the only answer is not so clear.

It tells you that the command ffmpeg is not recognized, which means you need to install ffmpeg binaries. You have installed the nodejs library, but beside that you should install the ffmpeg binaries, which what actually will execute the command 'ffmpeg' called by the JS library. Find here the url the download ffmpeg, extract it and add the path of /bin folder to your environment variables (PATH).

Upvotes: 2

Wesgur
Wesgur

Reputation: 3237

Did you try adding ffmpeg executable's path to the environment variable?

Upvotes: 3

Related Questions