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
What is missing in my code?
Did you try adding ffmpeg executable's path to the environment variable?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With