我正在开发一个 Node.js 应用程序。首先,我只是 Node 的初学者。
我现在在应用程序中所做的是尝试为我的 mp4 文件创建缩略图 JPEG 文件。我已经尝试过很多可能的解决方案。现在我正在使用这个 - https://github.com/damianociarla/node-ffmpeg 。我认为这是所有潜在的解决方案。当我生成视频文件的 JPEG 缩略图时出现错误。
这是我到目前为止所做的事情。我安装了运行此命令的包
npm install ffmpeg --save
然后我尝试生成这样的缩略图文件
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" });
}
当我运行代码时,它抛出一个错误。我在抛出错误的代码中注释了。 这是错误信息
{ 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' }
我也安装了 ffmg。您可以在下面看到它是我的笔记本电脑上安装的命令
我的代码中缺少什么?
最佳答案
您是否尝试将 ffmpeg 可执行文件的路径添加到环境变量中?
关于node.js - 在nodejs中,“ffmpeg”不被识别为内部或外部命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48714542/